-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 增加工具栏图标和快捷键(option + shift + ,),快速打开设置界面 2. 全局拦截模式,按着 shift 会拦截所有请求,此模式非常适合百度云和迅雷离线,可以不用任何其他插件直接导入至aria2 3. cmd可以临时禁用或启用自动拦截模式 - 关闭自动拦截配置后可按住cmd点击链接来临时启用自动拦截模式 - 开启自动拦截模式可以按住cmd来临时禁用自动拦截 - 可以配合全局拦截快捷键一起使用 4. 增加配置项来控制是否传递cookie 5. 增加配置项控制是否拦截iframe模式的下载(主要在百度云使用) - 如需在百度云快捷下载,请关闭cookie选项并打开iframe拦截 6. 增加user-agent设置项
- Loading branch information
Showing
10 changed files
with
304 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,4 +75,10 @@ textarea { | |
} | ||
#rpcList .defaultRpc{ | ||
flex: none; | ||
} | ||
.option{ | ||
display: flex; | ||
} | ||
input.text{ | ||
flex:1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); |
Oops, something went wrong.