Easy offline

Be easy to find out all magnet links and torrents and video links in current page, and stream them from cloud storage automatically.

As of 2016-10-18. See the latest version.

// ==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.18
// @author       Hoothin
// @mail         rixixi@gmail.com
// @include      http*://pan.baidu.com/*
// @include      http://115.com/*
// @include      https://www.furk.net/*
// @include      https://www.seedr.cc/*
// @include      http*://*/*
// @grant        GM_setValue
// @grant        GM_getValue
// @require      http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js
// ==/UserScript==

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={};
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=[];
    for(x = 0; x < 4; x++){
        var 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",offUrl);});
        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);
        parentDiv.prepend(offNode);
    }
    $("body").append(parentDiv);
    parentDiv.mouseleave(function(e){
        parentDiv.css("display","none");
        for(var node of offNodes){
            node.css("margin-top","0px");
        }
    });

    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){
        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");
                    }
                });
                $(curNode).after(clone);
            }
        }
    }
}

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();
                            setTimeout(function(){
                                var btList=document.querySelector('#offlinebtlist-dialog');
                                if(btList && btList.style.display!="none"){
                                    btList.querySelectorAll('.dialog-footer>.g-button')[1].click();
                                }
                            }, 500);
                        }
                    }, 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).length > 0) || i > 20){
        window.clearInterval(t);
        getAllEnableUrl();
    }else{
        i++;
    }
}, 500);