// ==UserScript==
// @name Easy offline
// @name:zh-CN 一键离线下载
// @name:zh-TW 一鍵離綫下載
// @description Be easy to find out all magnet links and torrents and video links in current page, and stream them from cloud storage automatically.
// @description:zh-CN 一键自动将磁链、bt种子或其他下载资源离线下载至网盘
// @description:zh-TW 一鍵自動將磁鏈、bt種子或其他下載資源離綫下載至網槃
// @namespace http://tampermonkey.net/
// @version 1.0.24
// @author Hoothin
// @mail [email protected]
// @include http*://*/*
// @exclude http*://www.baidu.*
// @exclude http*://www.google.*
// @exclude http*://www.bing.*
// @include http*://pan.baidu.com/*
// @include http://115.com/*
// @include https://www.furk.net/*
// @include https://www.seedr.cc/*
// @grant GM_setValue
// @grant GM_getValue
// @require http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js
// @supportURL http://www.hoothin.com
// @license MIT License
// @compatible chrome
// @compatible firefox
// @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_donations&[email protected]&item_name=Greasy+Fork+donation
// @contributionAmount 1
// ==/UserScript==
var sites={
0:{
name:"baidu",
url:"http://pan.baidu.com/disk/home",
bgColor:"e1e1e1"
},
1:{
name:"yyw",
url:"http://115.com/?tab=offline&mode=wangpan",
bgColor:"5e5eff"
},
2:{
name:"furk",
url:"https://www.furk.net/users/files/add",
bgColor:"3BEBFF",
hide:false
},
3:{
name:"seedr",
url:"https://www.seedr.cc/files",
bgColor:"F44336",
hide:false
},
};
var enableUrl = 'a[href^="magnet"],[href^="ed2k://|file"],[href$=".torrent"],[href$=".mp4"],[href$=".rar"],[href$=".7z"],[href$=".zip"],[href$=".rmvb"],[href$=".mkv"],[href$=".avi"],[href$=".iso"]';
var disableUrl=[".torrentkitty.","bt.box.n0808.com"];
var lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
var i18n={};
if(unsafeWindow && unsafeWindow.jQuery)$ = unsafeWindow.jQuery;
switch (lang){
case "zh-CN":
i18n={
yyw:"115网盘",
baidu:"百度网盘",
furk:"Furk网盘",
seedr:"Seedr网盘"
};
break;
default:
i18n={
yyw:"115",
baidu:"BaiduPan",
furk:"Furk",
seedr:"Seedr"
};
break;
}
function include(things,obj) {
for (var i = things.length - 1; i >= 0; i--) {
if ($(things[i]).attr('href')===$(obj).attr('href')){
return true;
}
}
}
function setCss(){
$('head').append(`
<style>
a.whx-a{
display:inline-block;
margin-left:5px;
background-size:20px;
border-radius:50%;
vertical-align:middle;
transition:margin-top 0.5s ease;
outline:none!important;
padding:0px!important;
height:25px!important;
width:25px!important;
background-position:center!important;
background-repeat:no-repeat!important;
background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAAARVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADc6ur3AAAAFnRSTlMAYM5vMOA/ENGegK2olI6G1b97Z0sXENA+jAAAAKFJREFUKM+FklkSxCAIRHFfss3K/Y86iQSDVqzpH7FfgQpCVfAmGx+gl9JI0qrxrcNLzooEbKUG4EKWdkCiDRV0N0RTrZ5wvdgTTgp4SzCAHxAPZkAM5GOJWuuT7FE5OVPOBFLTYb3Oc2YB5uJ8+G6pgkTGt74ntcCJHiwFLHw10Tdc93jlGXGvSRtsHNpuPs+/o1ODfxAtSL0f7HPC+L/9AF60G3QxO1UaAAAAAElFTkSuQmCC")!important;
}
</style>
`);
}
function getAllEnableUrl() {
var rawnodes = $(enableUrl).get();
var nodes = [];
var i,x;
var curNode;
var parentDiv=$("<div style='display:none;position:fixed;z-index:99999;overflow:visible;'></div>");
var offUrl;
var offNodes=[];
function hideIcons(){
parentDiv.css("display","none");
for(var node of offNodes){
node.css("margin-top","0px");
}
}
for(x = 0; x < 4; x++){
let offNode=$("<a></a>");
offNode.addClass('whx-a').css("position","absolute").css("margin-top","0px").css("margin-left","0px");
offNode.attr("target","_blank").click(function (event) {GM_setValue("url",getRightMagnetUrl(offUrl));});
let siteConfig=sites[x];
offNode.css("background-color","#"+siteConfig.bgColor).attr("title",i18n[siteConfig.name] ).attr("href", siteConfig.url);
/*switch(x){
case 0:
offNode.css("background-color","#e1e1e1").attr("title",i18n.baidu ).attr("href", "http://pan.baidu.com/disk/home");
break;
case 1:
offNode.css("background-color","#F44336").attr("title",i18n.seedr ).attr("href", "https://www.seedr.cc/files");
break;
case 2:
offNode.css("background-color","#3BEBFF").attr("title",i18n.furk ).attr("href", "https://www.furk.net/users/files/add");
break;
case 3:
offNode.css("background-color","#5e5eff").attr("title",i18n.yyw ).attr("href", "http://115.com/?tab=offline&mode=wangpan");
break;
}*/
offNodes.push(offNode);
if(siteConfig.hide)continue;
parentDiv.prepend(offNode);
}
parentDiv.mouseover(function(e){
e.stopPropagation();
});
document.addEventListener("mouseover", function(e){
hideIcons();
});
if(rawnodes.length > 0){
for (i = 0; i < rawnodes.length; i++) {
var disable = false;
curNode = rawnodes[i];
for(var j = 0; j < disableUrl.length; j++){
var temp = disableUrl[j];
if($(curNode)[0].href.indexOf(temp)!=-1){
disable = true;
break;
}
}
if(disable)continue;
if(!include(nodes,curNode)){
nodes.push(curNode);
}
}
}
if(nodes.length > 0){
$("body").append(parentDiv);
var codeList = [];
var listLen = 0;
listLen = nodes.length;
setCss();
if (listLen !== 0) {
for (i = 0; i < listLen; i++) {
curNode = nodes[i];
let clone=$("<a></a>").attr("style",curNode.getAttribute("style")).attr("href",curNode.getAttribute("href")).addClass('whx-a').css("background-color","#e1e1e1");
clone.mouseover(function(e){
offUrl=clone.attr("href");
parentDiv.css("display","block");
var basePos=clone.offset();
parentDiv.offset({top:basePos.top,left:basePos.left});
for(var x=0;x<4;x++){
offNodes[x].css("margin-top",-x*25+"px");
}
e.stopPropagation();
});
$(curNode).after(clone);
}
}
}
}
function getRightMagnetUrl(url){
var newUrl = url;
if(/^magnet/.test(url)){
newUrl=newUrl.split("&")[0].substring(20);
if(newUrl.length==32){
newUrl="magnet:?xt=urn:btih:" + base32ToHex(newUrl);
}else{
newUrl=url;
}
}
return newUrl;
}
var b32 = {'a':'00000','b':'00001','c':'00010','d':'00011','e':'00100','f':'00101','g':'00110','h':'00111','i':'01000','j':'01001','k':'01010','l':'01011','m':'01100','n':'01101','o':'01110','p':'01111','q':'10000','r':'10001','s':'10010','t':'10011','u':'10100','v':'10101','w':'10110','x':'10111','y':'11000','z':'11001','2':'11010','3':'11011','4':'11100','5':'11101','6':'11110','7':'11111'};
var b16 = {'0000':'0','0001':'1','0010':'2','0011':'3','0100':'4','0101':'5','0110':'6','0111':'7','1000':'8','1001':'9','1010':'a','1011':'b','1100':'c','1101':'d','1110':'e','1111':'f'};
function base32ToHex(str){
if(str.length % 8 !== 0){
return null;
}
str = str.toLowerCase();
var bin = "", returnStr = "", i;
for(i = 0;i < str.length;i++){
bin += b32[str.substring(i,i+1)];
}
for(i = 0;i < bin.length;i+=4){
returnStr += b16[bin.substring(i,i+4)];
}
return returnStr;
}
var i=0;
var t=window.setInterval(function() {
var curlink;
if (location.href.indexOf("furk.net/users/files/add") != -1){
window.clearInterval(t);
curlink = GM_getValue('url');
if(curlink){
setTimeout(function() {
$('#url').val(curlink);
GM_setValue('url', '');
$(":submit[value='Add download']").click();
}, 500);
}
}else if(location.href.indexOf("seedr.cc/files") != -1){
if($('#upload-button').css("display") != "none"){
window.clearInterval(t);
curlink = GM_getValue('url');
if(curlink){
setTimeout(function() {
$(':text[name="torrent"]').val(curlink);
GM_setValue('url', '');
$('#upload-button').click();
}, 500);
}
}
}else if(location.href.indexOf("pan.baidu.com/disk/home") != -1){
window.clearInterval(t);
curlink = GM_getValue('url');
if(curlink){
document.querySelector('.g-button[data-button-id=b13]').click();
var bsi = setInterval(function() {
var newTaskBtn = document.querySelector('#_disk_id_2');
if(newTaskBtn){
clearInterval(bsi);
newTaskBtn.click();
var bsl = setInterval(function() {
var offLink=document.querySelector('#share-offline-link');
if(offLink){
clearInterval(bsl);
offLink.value = curlink;
document.querySelectorAll('#newoffline-dialog>.dialog-footer>.g-button')[1].click();
if(/^magnet|torrent$/.test(curlink))
var bsb = setInterval(function(){
var btList=document.querySelector('#offlinebtlist-dialog');
if(btList && btList.style.display!="none"){
clearInterval(bsb);
btList.querySelectorAll('.dialog-footer>.g-button')[1].click();
}
}, 200);
}
}, 500);
}
}, 500);
GM_setValue('url', '');
}
}else if(location.href.indexOf("115.com/?tab=offline&mode=wangpan") != -1){
window.clearInterval(t);
curlink = GM_getValue('url');
if(curlink){
var rsc = setInterval(function() {
if (document.readyState == 'complete') {
clearInterval(rsc);
setTimeout(function() {
Core['OFFL5Plug'].OpenLink();
setTimeout(function() {
$('#js_offline_new_add').val(curlink);
}, 300);
}, 1000);
}
}, 400);
GM_setValue('url', '');
}
}else if((i === 0 && $(enableUrl).size() > 0) || i > 20){
window.clearInterval(t);
getAllEnableUrl();
}else{
i++;
}
}, 500);