Skip to content

Commit 6500979

Browse files
committed
Update Easy offline.user.js
1 parent 536d4b3 commit 6500979

1 file changed

Lines changed: 70 additions & 8 deletions

File tree

Easy offline/Easy offline.user.js

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// @namespace https://github.com/hoothin/UserScripts/tree/master/Easy%20offline
99
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js
1010
// @require https://cdnjs.cloudflare.com/ajax/libs/Base64/0.2.0/base64.min.js
11-
// @version 1.8.9
11+
// @version 1.9.0
1212
// @author Hoothin
1313
// @mail rixixi@gmail.com
1414
// @include http*://*/*
@@ -20,10 +20,14 @@
2020
// @grant GM_getValue
2121
// @grant GM_registerMenuCommand
2222
// @grant GM_deleteValue
23+
// @grant GM_xmlhttpRequest
24+
// @grant GM_notification
2325
// @grant GM.setValue
2426
// @grant GM.getValue
2527
// @grant GM.registerMenuCommand
2628
// @grant GM.deleteValue
29+
// @grant GM.xmlhttpRequest
30+
// @grant GM.notification
2731
// @grant unsafeWindow
2832
// @run-at document-end
2933
// @supportURL http://www.hoothin.com
@@ -365,7 +369,9 @@
365369
siteRulePlaceholder:"站点 @@ 站名 @@ 下载链接正则 @@ 图标base64 @@ 图标背景颜色\n\n@@ 分隔,目标站点中用 $url 代替目标链接,$hash 代表目标磁链的 hash 值,${reg}用正则提取\n\n例如:http://192.168.2.1/d2r?u=$url@@路由器下载\nhttp://xxx.com/magnet/$hash@@磁链下载@@^magnet@@data:image/png;base64,AAA@@ffffff",
366370
inputLink:"输入需要离线下载的链接:",
367371
importCustomAlert:"点击确定追加规则,点击取消覆盖规则",
368-
importOver:"规则导入完毕!"
372+
importOver:"规则导入完毕!",
373+
postOver:"发送成功,返回消息:",
374+
postError:"发送失败,错误内容:"
369375
};
370376
break;
371377
case "zh-TW":
@@ -402,7 +408,9 @@
402408
siteRulePlaceholder:"站點 @@ 站名 @@ 下載鏈接正則 @@ 圖標base64 @@ 圖標背景顏色\n\n@@ 分隔,目標站點中用 $url 代替目標連結,$hash 代表目標磁鏈的 hash 值,${reg}用正则提取\n\n例如:http://192.168.2.1/d2r?u=$url@@路由器下載\nhttp://xxx.com/magnet/$hash@@磁鏈下載@@^magnet@@data:image/png;base64,AAA@@ffffff",
403409
inputLink:"輸入需要離線下載的連結:",
404410
importCustomAlert:"點擊確定追加規則,點擊取消覆蓋規則",
405-
importOver:"規則導入完畢!"
411+
importOver:"規則導入完畢!",
412+
postOver:"發送成功,返回消息:",
413+
postError:"發送失敗,錯誤内容:"
406414
};
407415
break;
408416
default:
@@ -438,22 +446,36 @@
438446
siteRulePlaceholder: "site @@ sitename @@ link regexp @@ icon base64 @@ icon background color\n\nUse @@ to separated, use $url for the target Link, $hash for the hash of the target magnet link, ${reg} for regexp result on link\n\nFor example: http://192.168.2.1/d2r?u=$url@@MyRouter\nhttp://xxx.com/magnet/$hash@@MyMagnetLinkDownload@@^magnet@@data:image/png;base64,AAA@@ffffff",
439447
inputLink: "Enter the link that needs to be downloaded with this:",
440448
importCustomAlert:"Ok to add rule,Cancel to cover rule",
441-
importOver:"Rules import over!"
449+
importOver:"Rules import over!",
450+
postOver:"Post over, return: ",
451+
postError:"Fail in post, error: "
442452
};
443453
break;
444454
}
445455
return config[name]?config[name]:name;
446456
};
447457

448-
var _GM_registerMenuCommand;
449-
var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;
458+
var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification;
459+
if(typeof GM_xmlhttpRequest!='undefined'){
460+
_GM_xmlhttpRequest=GM_xmlhttpRequest;
461+
}else if(typeof GM!='undefined' && typeof GM.xmlhttpRequest!='undefined'){
462+
_GM_xmlhttpRequest=GM.xmlhttpRequest;
463+
}
450464
if(typeof GM_registerMenuCommand!='undefined'){
451465
_GM_registerMenuCommand=GM_registerMenuCommand;
452466
}else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
453467
_GM_registerMenuCommand=GM.registerMenuCommand;
454468
}
469+
if(typeof GM_notification!='undefined'){
470+
_GM_notification=GM_notification;
471+
}else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
472+
_GM_notification=GM.notification;
473+
}
455474

475+
if(typeof _GM_xmlhttpRequest=='undefined')_GM_xmlhttpRequest=(f)=>{};
456476
if(typeof _GM_registerMenuCommand=='undefined')_GM_registerMenuCommand=(s,f)=>{};
477+
if(typeof _GM_notification=='undefined')_GM_notification=(s)=>{};
478+
var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;
457479
var storage={
458480
supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
459481
supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
@@ -666,7 +688,7 @@
666688
}
667689
var hash=offUrl.replace("magnet:?xt=urn:btih:","").replace(/&.*/,"");
668690
var base64Str=btoa(offUrl);
669-
return ruleArr[0].replace("$url", offUrl).replace("$hash", hash).replace("$base64", base64Str);
691+
return ruleArr[0].replace("$url", offUrl).replace("$hash", hash).replace("$base64", base64Str).replace("$random", Math.random());
670692
};
671693
if(ruleArr[2]) {
672694
siteConfig.linkRegExp=new RegExp(ruleArr[2],"i");
@@ -842,6 +864,26 @@
842864
return returnStr;
843865
}
844866

867+
function urlArgs(query){
868+
let args = {};
869+
let pairs = query.split('&');
870+
pairs.forEach((item) => {
871+
let pos = item.indexOf('=');
872+
if (pos != -1) {
873+
let name = item.substr(0,pos);
874+
let value = item.substr(pos+1);
875+
value = decodeURIComponent(value);
876+
if(/^[\[{]/.test(value)){
877+
try{
878+
value = JSON.parse(value);
879+
}catch(e){}
880+
}
881+
args[name] = value;
882+
}
883+
})
884+
return args;
885+
}
886+
845887
function pageRun(){
846888
for(var x = 0; x < sitesArr.length; x++){
847889
let offNode=$("<a></a>");
@@ -851,7 +893,27 @@
851893
offNode.click(function(e){
852894
offUrl=getRightUrl(offUrl);
853895
if(siteConfig.directUrl){
854-
offNode.attr('href', siteConfig.directUrl(offUrl));
896+
let url=siteConfig.directUrl(offUrl);
897+
if(/^p:/.test(url)){
898+
url=url.match(/p:(.*)\?(.*)/);
899+
if(!url)return;
900+
let postData=JSON.stringify(urlArgs(url[2]));
901+
url=url[1];
902+
_GM_xmlhttpRequest({
903+
method: "POST", url, data: postData,
904+
onload: (d) => {
905+
_GM_notification(i18n("postOver")+d.statusText);
906+
},
907+
onerror: (e) => {
908+
_GM_notification(i18n("postError")+e.toString());
909+
},
910+
ontimeout: (e) => {
911+
_GM_notification(i18n("postError")+e.toString());
912+
}
913+
});
914+
}else{
915+
offNode.attr('href', url);
916+
}
855917
}else{
856918
if(e.ctrlKey && e.shiftKey && siteConfig.canMul)
857919
storage.setItem(siteConfig.name+":eoUrl",allUrl);

0 commit comments

Comments
 (0)