Easy offline | 一键离线下载

在种子或视频链接旁添加按钮离线下载至网盘 | Easy stream torrents or videos from cloud storage

Tính đến 26-08-2016. Xem phiên bản mới nhất.

// ==UserScript==
// @name         Easy offline | 一键离线下载
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  在种子或视频链接旁添加按钮离线下载至网盘 | Easy stream torrents or videos from cloud storage
// @author       Hoothin
// @match        http://pan.baidu.com/*
// @match        http://115.com/*
// @match        https://www.furk.net/*
// @match        https://www.seedr.cc/*
// @match        http*://*/*
// @grant       GM_setValue
// @grant       GM_getValue
// @require      http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js
// ==/UserScript==

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.wxz-a{ background-repeat: no-repeat;background-position: center; display: inline-block;margin-left:5px;height: 20px;width: 20px;background-size: 20px;border-radius: 50%;background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAB/UlEQVRIS6WUDVEDQQyFWwVQBRQFFAetAkABRQGggFYBOKAoABRwDgAFFAWAA953s+nkMtn+wM5kus0leXn52X5vu7MvsyPJSML9W/ImeS/3tVH6GzCm+n5ZgtdMAbuTPNQMaiBk/CgZbke0tVpKzgrDjlsGQvb3OwSPphdSLLwygvwXwGJ3gDwIJXr9B4Poemyl8yDU9GAHkOcShMZTnr3gix6gnoH8pUyHpdnEmUlukgTbshkIqOwBh9kns6ZkyngyxvHMS3D07M5XYtOyASQaMO8wszPU5SMJwEIOnJ7EzhO7ASBjyYv7GJ355Jn6OH6KaslMALmS3IYM4qzDLNudVXOLf8bmGpCZJDatkW7igCnpUhInCJPVqOqesZnXmODsp4f/WZbo/QDwH9aIPaotk7HE98QIRGecYGhTiN2PhCWGZTwzKahQ25Pa+OEIG3+wJUsSsyXE7rQYPTlj7ieSdro4temhL02SZQRmxK1vgHKHITs32rTxcWciHgyYzGElkc7GY0MG8e1iZygZv5x1UxZxWhYot3mF487UnpkIkr7CGE0lceka6fzOUJrsmfEgncQ8EzPKgOLO2ORkrYjMO+XyDtSSQNYj2CwkS8lnYRxfCXpAgkxq52RMvAFOvG1+AWMMgtMnkkjPJhBzsrmHIXemjYwRm7waRu8XzEByGl4Ir08AAAAASUVORK5CYII=");vertical-align: middle;}</style>');
}

function getAllEnableUrl() {
    var rawnodes;
    if (location.href.indexOf(".torrentkitty.") != -1){
        rawnodes = $('a[href^="magnet"],[href$=".torrent"]').get();
    }else{
        rawnodes = $('a[href^="magnet"],[href^="ed2k://|file"],[href$=".torrent"],[href$=".mp4"],[href$=".rar"],[href$=".7z"],[href$=".zip"],[href$=".rmvb"],[href$=".mkv"]').get();
    }
    if(rawnodes.length>0){
        var nodes = [];
        var codeList = [];
        var listLen = 0;
        for (var i = 0; i <rawnodes.length; i++) {
            if(!include(nodes,rawnodes[i])){
                nodes.push(rawnodes[i]);
            }
        }
        listLen = nodes.length;
        setCss();
        if (listLen !== 0) {
            for (i = 0; i < listLen; i++) {
                var curNode = nodes[i];
                var url = $(curNode)[0]["href"];
                $(curNode).after($(curNode).clone().addClass('wxz-a').css("background-color","#5e5eff").css("outline","none").empty().attr("target","_blank").attr("url",url).attr("title","115" ).attr("href", "http://115.com/?tab=offline&mode=wangpan").click(function (event) {GM_setValue("url",$(event.target).attr("url"));}));
                $(curNode).after($(curNode).clone().addClass('wxz-a').css("background-color","#3BEBFF").css("outline","none").empty().attr("target","_blank").attr("url",url).attr("title","Furk" ).attr("href", "https://www.furk.net/users/files/add").click(function (event) {GM_setValue("url",$(event.target).attr("url"));}));
                $(curNode).after($(curNode).clone().addClass('wxz-a').css("background-color","#F44336").css("outline","none").empty().attr("target","_blank").attr("url",url).attr("title","Seedr" ).attr("href", "https://www.seedr.cc/files").click(function (event) {GM_setValue("url",$(event.target).attr("url"));}));
                $(curNode).after($(curNode).clone().addClass('wxz-a').css("background-color","#ffffff").css("outline","none").empty().attr("target","_blank").attr("url",url).attr("title","BaiduPan" ).attr("href", "http://pan.baidu.com/disk/home").click(function (event) {GM_setValue("url",$(event.target).attr("url"));}));
            }
        }
        $('.wxz-a').css('b','d');
    }
}

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();
            setTimeout(function() {
                document.querySelector('#_disk_id_2').click();
                setTimeout(function() {
                    document.querySelector('#share-offline-link').value = curlink;
                    document.querySelector('.g-button[data-button-id=b63]').click();
                }, 500);
            }, 1500);
            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 && $('a[href^="magnet"],[href^="ed2k://|file"],[href$=".torrent"],[href$=".mp4"],[href$=".rar"],[href$=".7z"],[href$=".zip"],[href$=".rmvb"],[href$=".mkv"]').length>0)||i>20){
        window.clearInterval(t);
        getAllEnableUrl();
    }else{
        i++;
    }
}, 500);