Skip to content

Commit ea15f6d

Browse files
committed
add func for select and offline
1 parent b0429c3 commit ea15f6d

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

Easy offline/Easy offline.user.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// @namespace http://tampermonkey.net/
99
// @require https://cdn.jsdelivr.net/jquery/1.7.2/jquery.min.js
1010
// @require https://cdn.jsdelivr.net/hi-base64/0.2.0/base64.min.js
11-
// @version 1.3.12
11+
// @version 1.3.13
1212
// @author Hoothin
1313
// @mail rixixi@gmail.com
1414
// @include http*://*/*
@@ -689,9 +689,59 @@
689689
location.href="https://github.com/hoothin/UserScripts/tree/master/Easy offline#一键离线下载";
690690
}
691691

692+
function checkSel(e){
693+
var sel=document.getSelection();
694+
var link=sel.toString();
695+
if(link===""){
696+
link=prompt("输入需要离线下载的链接:","magnet:?xt=urn:btih:");
697+
}else{
698+
var focusedElement = sel.focusNode.parentElement;
699+
if(focusedElement.tagName == "A"){
700+
link=focusedElement.href;
701+
}
702+
}
703+
if(/^(magnet|ed2k:\/\/\|file|https?:|ftp:)/.test(link)){
704+
if(!isCssSeted){
705+
$("body").append(parentDiv);
706+
setCss();
707+
}
708+
offUrl=link;
709+
parentDiv.css("display","block");
710+
parentDiv.offset({top:mouseEve.pageY,left:mouseEve.pageX});
711+
let j=0;
712+
for(var x=0;x<offNodes.length;x++){
713+
let node=offNodes[x];
714+
let siteConfig=sites[node.attr("name")];
715+
if(/^magnet/i.test(offUrl) && siteConfig.noMag){
716+
node.hide();
717+
}else if(/^ftp/i.test(offUrl) && siteConfig.noFtp){
718+
node.hide();
719+
}else if(/^ed2k:\/\//i.test(offUrl) && siteConfig.noEd2k){
720+
node.hide();
721+
}else{
722+
node.show();
723+
node.css("margin-top",-j*25+"px");
724+
j++;
725+
if(siteConfig.directUrl){
726+
node.attr('href', siteConfig.directUrl(offUrl));
727+
}
728+
}
729+
}
730+
}
731+
}
732+
733+
var mouseEve;
734+
document.addEventListener("mousemove", function(e) {
735+
mouseEve=e;
736+
});
737+
692738
document.addEventListener("keydown", function(e) {
693739
if(e.keyCode == 120) {
694-
toggleIcon();
740+
if(e.altKey){
741+
checkSel(e);
742+
}else{
743+
toggleIcon();
744+
}
695745
}
696746
});
697747
GM_registerMenuCommand(i18n.configure, goSetting);

0 commit comments

Comments
 (0)