Skip to content

Commit

Permalink
v1.3
Browse files Browse the repository at this point in the history
1. 增加工具栏图标和快捷键(option + shift + ,),快速打开设置界面
2. 全局拦截模式,按着 shift 会拦截所有请求,此模式非常适合百度云和迅雷离线,可以不用任何其他插件直接导入至aria2
3. cmd可以临时禁用或启用自动拦截模式
 - 关闭自动拦截配置后可按住cmd点击链接来临时启用自动拦截模式
 - 开启自动拦截模式可以按住cmd来临时禁用自动拦截
 - 可以配合全局拦截快捷键一起使用
4. 增加配置项来控制是否传递cookie
5. 增加配置项控制是否拦截iframe模式的下载(主要在百度云使用)
 - 如需在百度云快捷下载,请关闭cookie选项并打开iframe拦截
6. 增加user-agent设置项
  • Loading branch information
miniers committed Jun 14, 2017
1 parent 4cf3f77 commit 2fbd6a7
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 157 deletions.
35 changes: 33 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
### v1.2更新内容:
### v1.3:
1. 增加工具栏图标和快捷键(option + shift + ,),快速打开设置界面
2. 全局拦截模式,按着 shift 会拦截所有请求,此模式非常适合百度云和迅雷离线,可以不用任何其他插件直接导入至aria2
3. cmd可以临时禁用或启用自动拦截模式
- 关闭自动拦截配置后可按住cmd点击链接来临时启用自动拦截模式
- 开启自动拦截模式可以按住cmd来临时禁用自动拦截
- 可以配合全局拦截快捷键一起使用
4. 增加配置项来控制是否传递cookie
5. 增加配置项控制是否拦截iframe模式的下载(主要在百度云使用)
- 如需在百度云快捷下载,请关闭cookie选项并打开iframe拦截
6. 增加user-agent设置项

### 注意事项
请在aria2c的配置文件中加入如下配置,用以开启百度云和迅雷离线导出时自动更改下载文件名
```
content-disposition-default-utf8=true
```
#### 迅雷离线导出:
- 开启cookie传递选项
- 选择需要导出的文件
- 如当前为自动拦截模式,长按**shift**并点击**取回本地**按钮即可导出下载至默认rpc服务器
- 如当前关闭了自动拦截默认,需长按**shift+cmd**并点击**取回本地**按钮即可导出下载至默认rpc服务器

#### 百度云分享页导出:
- 关闭cookie传递选项
- 点击下载,打开文件下载窗口
- 如当前为自动拦截模式,长按**shift**并点击**普通下载**按钮即可导出下载至默认rpc服务器
- 如当前关闭了自动拦截默认,需长按**shift+cmd**并点击**普通下载**按钮即可导出下载至默认rpc服务器


### v1.2:
1. 优化代码结构,修复包含iframe页面下载重复问题
2. 图片下载

Expand All @@ -9,7 +40,7 @@
1. 增加快捷键来切换默认rpc服务 (option+shift+[123456789]
2. 增加快捷键展示当前默认rpc服务(option+shift+`)
3. 设置界面可以设置默认rpc服务
4. 增加快捷键临时禁制拦截 (按着cmd点击链接)
4. 增加快捷键临时禁止拦截 (按着cmd点击链接)

### v1.0:
1. 自动拦截指定后缀文件的下载事件并通过aria2c来下载该文件
Expand Down
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,46 @@
1. 拦截指定后缀文件下载
2. 多aria2c服务支持
3. 右键菜单指定aria2c服务
4. 支持百度云和迅雷离线导出
5. 全局拦截模式

### 快捷键:
1. 切换默认rpc服务 (option+shift+[123456789]
2. 展示当前默认rpc服务(option+shift+`)
3. 临时禁用或启用拦截(按着cmd点击链接)
功能 | 快捷键
---- | ---
切换默认rpc服务 | option+shift+[123456789]
展示当前默认rpc服务 | option+shift+`
临时禁用或启用拦截 | 长按cmd并点击链接
全局拦截 | 长按shift并点击链接
设置 | option+shift+,

### 注意事项
请在aria2c的配置文件中加入如下配置,用以开启百度云和迅雷离线导出时自动更改下载文件名
```
content-disposition-default-utf8=true
```

[下载链接](https://github.com/miniers/safari2aria/releases)

设置:

![image](https://user-images.githubusercontent.com/2039910/27039832-bee11dc0-4fc1-11e7-9ab3-46264992baa6.png)
![image](https://user-images.githubusercontent.com/2039910/27144514-c743a31c-5164-11e7-9f23-4f2a9dcae223.png)

下载:

![image](https://user-images.githubusercontent.com/2039910/27039821-b4518ce6-4fc1-11e7-8dc2-a9b9c1621ae0.png)

#### 迅雷离线导出:
- 开启cookie传递选项
- 选择需要导出的文件
- 如当前为自动拦截模式,长按**shift**并点击**取回本地**按钮即可导出下载至默认rpc服务器
- 如当前关闭了自动拦截默认,需长按**shift+cmd**并点击**取回本地**按钮即可导出下载至默认rpc服务器

#### 百度云分享页导出:
- 关闭cookie传递选项
- 点击下载,打开文件下载窗口
- 如当前为自动拦截模式,长按**shift**并点击**普通下载**按钮即可导出下载至默认rpc服务器
- 如当前关闭了自动拦截默认,需长按**shift+cmd**并点击**普通下载**按钮即可导出下载至默认rpc服务器


### 注意事项:
如果aria2c端没有配置ssl证书,则https网站的下载请求无法发送至aria2c
Expand Down
25 changes: 22 additions & 3 deletions safari2aria.safariextension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,34 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<string>1.3</string>
<key>CFBundleVersion</key>
<string>1.2</string>
<string>1.3</string>
<key>Chrome</key>
<dict>
<key>Database Quota</key>
<integer>10485760</integer>
<key>Global Page</key>
<string>global.html</string>
<key>Toolbar Items</key>
<array>
<dict>
<key>Command</key>
<string>showOptions</string>
<key>Identifier</key>
<string>showOptions</string>
<key>Image</key>
<string>button.png</string>
<key>Include By Default</key>
<true/>
<key>Label</key>
<string>safari2aria</string>
<key>Popover</key>
<string>options</string>
<key>Tool Tip</key>
<string>打开设置窗口</string>
</dict>
</array>
</dict>
<key>Content</key>
<dict>
Expand Down Expand Up @@ -56,7 +75,7 @@
<key>Update From Gallery</key>
<true/>
<key>Update Manifest URL</key>
<string>https://miniers.github.io/safari2aria/update.plist?t=1.2</string>
<string>https://miniers.github.io/safari2aria/update.plist?t=1.3</string>
<key>Website</key>
<string>https://github.com/miniers/safari2aria</string>
</dict>
Expand Down
Binary file added safari2aria.safariextension/button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions safari2aria.safariextension/css/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ textarea {
}
#rpcList .defaultRpc{
flex: none;
}
.option{
display: flex;
}
input.text{
flex:1
}
195 changes: 112 additions & 83 deletions safari2aria.safariextension/js/endscript.js
Original file line number Diff line number Diff line change
@@ -1,101 +1,130 @@
(function () {

function linkForTarget (e) {
var result = null;
if ("BODY" === e.tagName) {
result = null
} else if (e.tagName === "IMG" && e.src) {
result = e.src
} else if (e.href) {
result = e.href
} else if (e.parentNode) {
result = linkForTarget(e.parentNode)
var mObserver;
var config;
var keyPressed = {};

function linkForTarget (e) {
var result = null;
if ("BODY" === e.tagName) {
result = null
} else if (e.tagName === "IMG" && e.src) {
result = e.src
} else if (e.href) {
result = e.href
} else if (e.parentNode) {
result = linkForTarget(e.parentNode)
}
return result
}
return result
}

function linksFromContainer (e) {
var n = {};
if (e.href) {
var t = e.title || e.alt || e.innerText || e.textContent || "title";
n[t] = e.href
function handleMessage (e) {
if (e.name === "changeRpc") {
miniToastr.success('成功切换默认下载服务至' + e.message);
}
if (e.name === "currentRpc") {
miniToastr.success('当前下载服务为' + e.message);
}
if (e.name === "showMassage") {
miniToastr[e.message.action || "success"](e.message.text);
}
if (e.name === "receiveConfig") {
config = e.message || {};
catchIframe();
}
}
for (var o = e.childNodes, r = 0; r < o.length; r++) {
var a = this.linksFromContainer(o.item(r));
if (null != a)
for (t in a) n[t] = a[t]

function handleContextMenu (e) {
var n = [
linkForTarget(e.target),
document.location.href,
document.cookie
];
safari.self.tab.setContextMenuEventUserInfo(e, n)
}
return n
}

function selectedLinks () {
var e = window.getSelection();
if (e && e.rangeCount > 0) {
var n = e.getRangeAt(0);
if (n) {
var t = n.commonAncestorContainer;
if (t) {
var o = linksFromContainer(t),
r = e.toString(),
a = [];
for (var i in o)
if (-1 != r.search(i)) {
var s = o[i];
"" != s && a.push(s)
}
return a
function catchIframe () {
if (mObserver) {
if(!config.catchIframe){
mObserver.disconnect();
}
return
}
if (config.catchIframe) {
mObserver = new MutationObserver(function (mutations) {
mutations.some(function (mutation) {
if (mutation.target.tagName === "IFRAME" && mutation.type === 'attributes' && mutation.attributeName === 'src') {
if (mutation.target.src.match(/^https:\/\/127\.0\.0\.1\//)) {
return false
} else {
safari.self.tab.dispatchMessage("downloadFromIframe", {
url: mutation.target.src,
cookie: document.cookie
});
mutation.target.src = "https://127.0.0.1/";
}
return false;
}
return false;
});
});
mObserver.observe(document.body, {
attributes: true,
attributeFilter: ['src'],
attributeOldValue: true,
characterData: false,
characterDataOldValue: false,
childList: false,
subtree: true
});
}
}
return null
}

function handleMessage (e) {
if (e.name === "changeRpc") {
miniToastr.success('成功切换默认下载服务至' + e.message);
}
if (e.name === "currentRpc") {
miniToastr.success('当前下载服务为' + e.message);
}
if (e.name === "showMassage") {
miniToastr[e.message.action || "success"](e.message.text);
}
}
document.onkeydown = function (event) {
var unicode = event.charCode ? event.charCode : event.keyCode;
keyPressed[unicode] = true;
//console.log('onkeydown:',keyPressed);
sendKeyPressEvent()
};

function handleContextMenu (e) {
document.onkeyup = function (event) {
var unicode = event.charCode ? event.charCode : event.keyCode;
delete keyPressed[unicode];
sendKeyPressEvent()
};
window.onblur = function (event) {
keyPressed={};
sendKeyPressEvent()
};

var n = new Array;
n[0] = linkForTarget(e.target);
n[1] = document.location.href;
n[2] = selectedLinks();
safari.self.tab.setContextMenuEventUserInfo(e, n)
}
function sendKeyPressEvent () {
safari.self.tab.dispatchMessage("keyPress", {
keyPressed: keyPressed
});
saveCookie();
}

function saveCookie () {
safari.self.tab.dispatchMessage("setCookie", {
cookie: document.cookie
});
}

function init () {
miniToastr.init({
appendTarget: document.body,
timeout: 5000
});
saveCookie();
safari.self.tab.dispatchMessage("getConfig");

//handle command key
document.onkeydown = function (event) {
var unicode = event.charCode ? event.charCode : event.keyCode;
keyPressed[unicode] = true;
sendKeyPressEvent()
};
document.addEventListener("contextmenu", handleContextMenu, !1);

document.onkeyup = function (event) {
var unicode = event.charCode ? event.charCode : event.keyCode;
keyPressed[unicode] = false;
sendKeyPressEvent()
};
safari.self.addEventListener("message", handleMessage, !1);

function sendKeyPressEvent () {
safari.self.tab.dispatchMessage("keyPress", {
keyPressed: keyPressed
});
}
sendKeyPressEvent();
}

var keyPressed = {};
miniToastr.init({
appendTarget: document.body,
timeout: 5000
});
sendKeyPressEvent();
document.addEventListener("contextmenu", handleContextMenu, !1);
init()

safari.self.addEventListener("message", handleMessage, !1);
})();
Loading

0 comments on commit 2fbd6a7

Please sign in to comment.