|
8 | 8 | // @namespace https://github.com/hoothin/UserScripts/tree/master/Easy%20offline |
9 | 9 | // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js |
10 | 10 | // @require https://cdnjs.cloudflare.com/ajax/libs/Base64/0.2.0/base64.min.js |
11 | | -// @version 1.8.9 |
| 11 | +// @version 1.9.0 |
12 | 12 | // @author Hoothin |
13 | 13 | // @mail rixixi@gmail.com |
14 | 14 | // @include http*://*/* |
|
20 | 20 | // @grant GM_getValue |
21 | 21 | // @grant GM_registerMenuCommand |
22 | 22 | // @grant GM_deleteValue |
| 23 | +// @grant GM_xmlhttpRequest |
| 24 | +// @grant GM_notification |
23 | 25 | // @grant GM.setValue |
24 | 26 | // @grant GM.getValue |
25 | 27 | // @grant GM.registerMenuCommand |
26 | 28 | // @grant GM.deleteValue |
| 29 | +// @grant GM.xmlhttpRequest |
| 30 | +// @grant GM.notification |
27 | 31 | // @grant unsafeWindow |
28 | 32 | // @run-at document-end |
29 | 33 | // @supportURL http://www.hoothin.com |
|
365 | 369 | 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", |
366 | 370 | inputLink:"输入需要离线下载的链接:", |
367 | 371 | importCustomAlert:"点击确定追加规则,点击取消覆盖规则", |
368 | | - importOver:"规则导入完毕!" |
| 372 | + importOver:"规则导入完毕!", |
| 373 | + postOver:"发送成功,返回消息:", |
| 374 | + postError:"发送失败,错误内容:" |
369 | 375 | }; |
370 | 376 | break; |
371 | 377 | case "zh-TW": |
|
402 | 408 | 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", |
403 | 409 | inputLink:"輸入需要離線下載的連結:", |
404 | 410 | importCustomAlert:"點擊確定追加規則,點擊取消覆蓋規則", |
405 | | - importOver:"規則導入完畢!" |
| 411 | + importOver:"規則導入完畢!", |
| 412 | + postOver:"發送成功,返回消息:", |
| 413 | + postError:"發送失敗,錯誤内容:" |
406 | 414 | }; |
407 | 415 | break; |
408 | 416 | default: |
|
438 | 446 | 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", |
439 | 447 | inputLink: "Enter the link that needs to be downloaded with this:", |
440 | 448 | 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: " |
442 | 452 | }; |
443 | 453 | break; |
444 | 454 | } |
445 | 455 | return config[name]?config[name]:name; |
446 | 456 | }; |
447 | 457 |
|
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 | + } |
450 | 464 | if(typeof GM_registerMenuCommand!='undefined'){ |
451 | 465 | _GM_registerMenuCommand=GM_registerMenuCommand; |
452 | 466 | }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){ |
453 | 467 | _GM_registerMenuCommand=GM.registerMenuCommand; |
454 | 468 | } |
| 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 | + } |
455 | 474 |
|
| 475 | + if(typeof _GM_xmlhttpRequest=='undefined')_GM_xmlhttpRequest=(f)=>{}; |
456 | 476 | 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; |
457 | 479 | var storage={ |
458 | 480 | supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined', |
459 | 481 | supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined', |
|
666 | 688 | } |
667 | 689 | var hash=offUrl.replace("magnet:?xt=urn:btih:","").replace(/&.*/,""); |
668 | 690 | 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()); |
670 | 692 | }; |
671 | 693 | if(ruleArr[2]) { |
672 | 694 | siteConfig.linkRegExp=new RegExp(ruleArr[2],"i"); |
|
842 | 864 | return returnStr; |
843 | 865 | } |
844 | 866 |
|
| 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 | + |
845 | 887 | function pageRun(){ |
846 | 888 | for(var x = 0; x < sitesArr.length; x++){ |
847 | 889 | let offNode=$("<a></a>"); |
|
851 | 893 | offNode.click(function(e){ |
852 | 894 | offUrl=getRightUrl(offUrl); |
853 | 895 | 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 | + } |
855 | 917 | }else{ |
856 | 918 | if(e.ctrlKey && e.shiftKey && siteConfig.canMul) |
857 | 919 | storage.setItem(siteConfig.name+":eoUrl",allUrl); |
|
0 commit comments