diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c8cf8..010ec66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### v1.4: +1. 修复单页面多iframe引发的相同文件下载多次问题 +2. 优化拉取cookie的逻辑 +3. **aria2可以不用开启证书了** + ### v1.3: 1. 增加工具栏图标和快捷键(option + shift + ,),快速打开设置界面 2. 全局拦截模式,按着 shift 会拦截所有请求,此模式非常适合百度云和迅雷离线,可以不用任何其他插件直接导入至aria2 diff --git a/README.md b/README.md index cfe6f49..6f49f15 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ 4. 支持百度云和迅雷离线导出 5. 全局拦截模式 + ### 快捷键: 功能 | 快捷键 ---- | --- @@ -21,7 +22,8 @@ 设置 | option+shift+, ### 注意事项 -请在aria2c的配置文件中加入如下配置,用以开启百度云和迅雷离线导出时自动更改下载文件名 +1. aria2已经无需配置SSL证书了 +2. 请在aria2c的配置文件中加入如下配置,用以开启百度云和迅雷离线导出时自动更改下载文件名 ``` content-disposition-default-utf8=true ``` @@ -48,40 +50,3 @@ content-disposition-default-utf8=true - 如当前为自动拦截模式,长按**shift**并点击**普通下载**按钮即可导出下载至默认rpc服务器 - 如当前关闭了自动拦截默认,需长按**shift+cmd**并点击**普通下载**按钮即可导出下载至默认rpc服务器 - -### 注意事项: -如果aria2c端没有配置ssl证书,则https网站的下载请求无法发送至aria2c - -该问题为safari的安全策略,暂时没有思路修复 - -详细原因请浏览此篇博文 [https://imququ.com/post/sth-about-switch-to-https.html#toc-0-2](https://imququ.com/post/sth-about-switch-to-https.html#toc-0-2) - -请在 aria2c 的配置文件中添加如下配置引入证书 -``` -rpc-secure=true -rpc-certificate=path/to/you/cert -rpc-private-key=path/to/you/key -``` - -如果你的aria2c运行于macos下, - -则需要通过**钥匙串访问**程序将证书先行导入 - -并在证书简介页面的最低部找到SHA-1 指纹,填写入aria2c的配置文件 -``` -rpc-secure=true -rpc-certificate=01 01 01 01 01 01 01 -``` - -## 友情福利 - -鉴于有些用户没有申请域名或者证书,现提供一套自用ssl证书用以搭建本地aria2c https支持 - -域名: aria2.zc.ci - -解析: 127.0.0.1 - -证书下载地址:[aria2.zc.ci.zip](https://github.com/miniers/safari2aria/files/1070942/aria2.zc.ci.zip) - -请参照注意事项在aria2c的配置文件中添加证书 - diff --git a/safari2aria.safariextension/Info.plist b/safari2aria.safariextension/Info.plist index 91cdaa6..15acda2 100644 --- a/safari2aria.safariextension/Info.plist +++ b/safari2aria.safariextension/Info.plist @@ -13,9 +13,9 @@ CFBundleInfoDictionaryVersion 1.0 CFBundleShortVersionString - 1.3 + 1.4 CFBundleVersion - 1.3 + 1.4 Chrome Database Quota diff --git a/safari2aria.safariextension/js/endscript.js b/safari2aria.safariextension/js/endscript.js index ab2748d..235aff0 100644 --- a/safari2aria.safariextension/js/endscript.js +++ b/safari2aria.safariextension/js/endscript.js @@ -1,4 +1,4 @@ -(function () { +if (window.top === window){(function () { var mObserver; var config; @@ -32,6 +32,11 @@ config = e.message || {}; catchIframe(); } + if(e.message && e.message.hasCb){ + safari.self.tab.dispatchMessage([e.name,'cb'].join('_'), { + cookie: document.cookie + }); + } } function handleContextMenu (e) { @@ -101,25 +106,20 @@ 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"); document.addEventListener("contextmenu", handleContextMenu, !1); + safari.self.addEventListener("message", handleMessage, !1); sendKeyPressEvent(); @@ -127,4 +127,4 @@ init() -})(); \ No newline at end of file +})()} \ No newline at end of file diff --git a/safari2aria.safariextension/js/global.js b/safari2aria.safariextension/js/global.js index 0f23a82..61140d9 100644 --- a/safari2aria.safariextension/js/global.js +++ b/safari2aria.safariextension/js/global.js @@ -5,6 +5,44 @@ var cookie; var isCommandPressed, isShiftPressd, isOptionPressd; var fileTypes = []; var rpcList = []; +var timers={}; +var messageAction = { + updateSafari2Aria:function (msg) { + localStorage.setItem("safari2aria", JSON.stringify(msg)); + restoreOptions() + }, + keyPress:function (msg) { + keyPressAction(msg) + }, + getConfig:function () { + sendMsg('receiveConfig', config); + }, + downloadFromIframe:function (msg,e) { + if(!isCommandPressed){ + var t = [ + rpcList[config.defaultRpcIndex], + msg.url, + e.target.url, + msg.cookie + ]; + sendToAria2(t); + } + } +} + +function delay (name, func, wait, scope) { + return function delayed() { + var context = scope || this, + args = Array.prototype.slice.call(arguments); + if(timers[name]){ + clearTimeout(timers[name]) + } + timers[name] = setTimeout(function () { + delete timers[name]; + func.apply(context, args); + }, wait || 10); + }; +} var ARIA2 = (function () { var jsonrpc_version = '2.0'; @@ -47,7 +85,7 @@ var ARIA2 = (function () { return function (jsonrpc_path) { this.jsonrpc_path = jsonrpc_path; this.addUri = function (uri, options, cb) { - request(this.jsonrpc_path, 'aria2.addUri', [[uri,], options], cb); + delay(uri,request,100,this)(this.jsonrpc_path, 'aria2.addUri', [[uri], options], cb); }; return this; } @@ -61,14 +99,14 @@ function sendToAria2 (e) { "user-agent":config.userAgent }, function (err) { if (err) { - showToast("showMassage", { + sendMsg("showMassage", { action: 'error', - text: ['添加到', e[0].name, '失败'].join('') + text: ['添加到', e[0].name, '失败',config.enableCookie?"":'(关闭cookie)'].join('') }); } else { - showToast("showMassage", { + sendMsg("showMassage", { action: 'success', - text: ['添加到', e[0].name, '成功'].join('') + text: ['添加到', e[0].name, '成功',config.enableCookie?"":'(关闭cookie)'].join('') }); } }); @@ -76,7 +114,7 @@ function sendToAria2 (e) { } function openPreferences (e) { - "showOptions" === e.key && (openOptions(), optionsEvent = e) + "showOptions" === e.key && openOptions() } function openOptions () { safari.application.activeBrowserWindow.openTab().url = safari.extension.baseURI + "options.html" @@ -93,34 +131,26 @@ function restoreOptions () { fileTypes = config.filetypes ? config.filetypes.split(" ") : []; for (var a = 0; a < fileTypes.length; a++)fileTypes[a] = fileTypes[a].toLowerCase() rpcList = config.rpcList; - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage('receiveConfig', config); + sendMsg('receiveConfig', config); } function messageHandler (e) { - if (e.name === "updateSafari2Aria") { - localStorage.setItem("safari2aria", JSON.stringify(e.message)); - restoreOptions() + if(messageAction[e.name]){ + messageAction[e.name](e.message,e); } - if (e.name === "keyPress") { - keyPressAction(e.message) - } - if (e.name === "setCookie") { - cookie = e.message.cookie; - } - if (e.name === "getConfig") { - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage('receiveConfig', config); +} +function sendMsg (type, msg , cb) { + if(msg instanceof Function){ + cb = msg; + msg={}; } - if (e.name === "downloadFromIframe" && !isCommandPressed) { - var t = [ - rpcList[config.defaultRpcIndex], - e.message.url, - e.target.url, - e.message.cookie - ]; - sendToAria2(t); + if(cb){ + msg = Object.assign(msg || {},{ + hasCb:true + }); + messageAction[type+'_cb'] = cb; } -} -function showToast (type, msg) { safari.application.activeBrowserWindow.activeTab.page.dispatchMessage(type, msg); + } function keyPressAction (keys) { var keyPressed = keys.keyPressed || {}; @@ -135,12 +165,12 @@ function keyPressAction (keys) { name: 'updateSafari2Aria', message: config }); - showToast("changeRpc", rpcList[config.defaultRpcIndex].name); + sendMsg("changeRpc", rpcList[config.defaultRpcIndex].name); break; } } if (keyPressed[192]) { - showToast("currentRpc", rpcList[config.defaultRpcIndex].name); + sendMsg("currentRpc", rpcList[config.defaultRpcIndex].name); } if (keyPressed[188]) { openOptions(); @@ -172,13 +202,16 @@ function handleNavigation (e) { for (var n = 0; n < fileTypes.length; n++) { if (a === fileTypes[n] || isShiftPressd) { e.preventDefault(); - var t = [ - rpcList[config.defaultRpcIndex], - e.url, - e.target.url, - cookie - ]; - sendToAria2(t); + sendMsg('getCookie',function (msg) { + var t = [ + rpcList[config.defaultRpcIndex], + e.url, + e.target.url, + msg.cookie + ]; + sendToAria2(t); + }); + break } } diff --git a/safari2aria.safariextz b/safari2aria.safariextz index 9ea7f06..a1363bf 100644 Binary files a/safari2aria.safariextz and b/safari2aria.safariextz differ