自动获取磁链接并自动离线下载

Stan na 15-11-2015. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        挊
// @namespace   撸
// @description 自动获取磁链接并自动离线下载
// @include     http://www.javmoo.info/*
// @include     http://www.javlog.com/*
// @include     http://www.avmemo.com/*
// @include     http://www.javlib3.com/*
// @include     http://javlib3.com/*
// @include     http://www.libredmm.com/products/*
// @include     http://www.javbus.in/*
// @include     http://avdb.la/movie/*
// @include     http://www.141jav.com/view/*
// @include     http://www.av4you.net/work/*.htm
// @include     http://www.dmmy18.com/*
// @include     http://pan.baidu.com/disk/home
// @include     http://115.com/?tab=offline&mode=wangpan
// @include     http://cloud.letv.com/webdisk/home/index
// @include     http://disk.yun.uc.cn/
// @include     https://www.furk.net/users/files/add
// @include     *.yunpan.360.cn/my/

// @version     1.26
// @run-at      document-end
// @grant       GM_xmlhttpRequest
// @grant       GM_setClipboard
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       GM_addStyle
// ==/UserScript==

var debugging = false;


/*
// @include     http://www.btcherry.net/*
// @include     https://btdigg.org/search*
// @include     http://www.cilizhushou.com/search/*
// @include     http://www.btava.com/*
// @include     http://www.dmm.co.jp/digital/videoa/*
// @include     http://www.minnano-av.com/av*
// @include     http://www.oisinbosoft.com/dera/*

*/
var $ = function(selector) {
    return document.querySelectorAll(selector);
};
var offline_sites = {
    baidu: {
        url: 'http://pan.baidu.com/disk/home',
        name: '百度云',
        enable: true
    },
    115: {
        name: '115离线',
        url: 'http://115.com/?tab=offline&mode=wangpan',
        enable: true,
    },
    letv: {
        name: '乐视云',
        url: 'http://cloud.letv.com/webdisk/home/index',
        enable: false
    },
    360: {
        name: '360云',
        url: 'http://yunpan.360.cn/my/',
        enable: true
    },
    uc: {
        name: 'UC离线',
        url: 'http://disk.yun.uc.cn/',
        enable: true
    },
    furk: {
        name: 'Furk',
        url: 'https://www.furk.net/users/files/add',
        enable: false
    },
};
var common = {
    add_style: function(css) {
        if (css) {
            GM_addStyle(css);
        }
        else {
            GM_addStyle([
                '#nong-table{margin:10px auto;color:#666 !important;font-size:13px;text-align:center;background-color: #F2F2F2;}',
                '#nong-table th,td{text-align: center;height:30px;background-color: #FFF;padding:0 1em 0;border: 1px solid #EFEFEF;}',
                '.nong-row{text-align: center;height:30px;background-color: #FFF;padding:0 1em 0;border: 1px solid #EFEFEF;}',
                '.nong-copy{color:#08c !important;}',
                '.nong-offline{text-align: center;}',
                '.nong-offline-download{color: rgb(0, 180, 30) !important;margin-right: 4px;}',
                '.nong-offline-download:hover{color:red !important;}',
            ].join(''));
        }
    },
    handle_event: function(event) {
        if (event.target.className == 'nong-copy') {
            event.target.innerHTML = '成功';
            GM_setClipboard(event.target.href);
            setTimeout(function() {
                event.target.innerHTML = '复制';
            }, 1000);
            event.preventDefault(); //阻止跳转
        }
        else if (event.target.className == 'nong-offline-download') {
            GM_setValue('magnet', event.target.parentElement.parentElement.parentElement.getAttribute('maglink'));
        }
        else if (event.target.id == 'nong-search-select') {
            current_search_name = event.target.value;
            GM_setValue('search', current_search_name);
            search_engines[current_search_name](current_vid, function(src, data) {
                magnet_table.updata_table(src, data);
            });
        }
    },
    reg_event: function() { //TODO target 处理 更精准
        var list = ['.nong-copy', '.nong-offline-download'];
        for (var i = 0; i < list.length; i++) {
            var a = document.querySelectorAll(list[i]);
            for (var u = 0; u < a.length; u++) {
                a[u].addEventListener('click', this.handle_event, false);
            }
        }
        // var b = document.querySelectorAll('#nong-search-select')[0];
        // b.addEventListener('change', this.handle_event, false);
    },
    after: function(target, newnode) {
        target.parentElement.insertBefore(newnode, target.nextElementSibling);
    },
    parsetext: function(text) {
        var doc = null;
        try {
            doc = document.implementation.createHTMLDocument('');
            doc.documentElement.innerHTML = text;
            return doc;
        }
        catch (e) {
            alert('parse error');
        }
    },
    insert_js: function(js, maglink) {
        var script = document.createElement('script');
        script.setAttribute('type', 'text/javascript');
        console.log(script);
        script.innerHTML = '(' + js.toString() + ')(\'' + maglink + '\')';
        document.body.appendChild(script);
    },
    add_mini_table: function(sel, func) {
        var a = $(sel);
        for (var i = a.length - 1; i >= 0; i--) {
            a[i].parentElement.insertBefore(a[i], magnet_table.mini()); //TODO
            func(a[i]);
        }
    },
};
var magnet_table = {
    template: {
        create_head: function() {
            var a = document.createElement('tr');
            a.className = 'nong-row';
            a.id = 'nong-head';
            var list = [
                '标题',
                '大小',
                '操作',
                '离线下载'
            ];
            for (var i = 0; i < list.length; i++) {
                var b = this.head.cloneNode(true);
                b.firstChild.textContent = list[i];
                a.appendChild(b);
            }
            // var select_box = this.create_select_box();
            // a.firstChild.appendChild(select_box);
            return a;
        },
        create_row: function(data) {
            var a = document.createElement('tr');
            a.className = 'nong-row';
            a.setAttribute('maglink', data.maglink);
            var b = document.createElement('td');
            var list = [
                this.create_info(data.title, data.maglink),
                this.create_size(data.size),
                this.create_operation(data.maglink),
                this.create_offline()
            ];
            for (var i = 0; i < list.length; i++) {
                var c = b.cloneNode(true);
                c.appendChild(list[i]);
                a.appendChild(c);
            }
            return a;
        },
        create_loading: function() {
            var a = document.createElement('tr');
            a.className = 'nong-row';
            var p = document.createElement('p');
            p.textContent = 'Loading';
            p.id = 'notice';
            a.appendChild(p);
            return a;
        },
        create_info: function(title, maglink) {
            var a = this.info.cloneNode(true);
            a.firstChild.textContent = title;
            a.firstChild.href = maglink;
            return a;
        },
        create_size: function(size) {
            var a = this.size.cloneNode(true);
            a.textContent = size;
            return a;
        },
        create_operation: function(maglink) {
            var a = this.operation.cloneNode(true);
            a.firstChild.href = maglink;
            return a;
        },
        create_offline: function() {
            var a = this.offline.cloneNode(true);
            a.className = 'nong-offline';
            return a;
        },
        create_select_box: function() {
            var select_box = document.createElement('select');
            select_box.id = 'nong-search-select';
            select_box.setAttribute('title', '切换搜索结果');
            var search_name = GM_getValue('search', default_search_name);
            for (var k in search_engines) {
                var o = document.createElement('option');
                if (k == search_name) {
                    o.setAttribute('selected', 'selected');
                }
                o.setAttribute('value', k);
                o.textContent = k;
                select_box.appendChild(o);
            }
            return select_box;
        },
        head: (function() {
            var a = document.createElement('th');
            var b = document.createElement('a');
            a.appendChild(b);
            return a;
        })(),
        info: (function() {
            var a = document.createElement('div');
            var b = document.createElement('a');
            b.textContent = 'name';
            b.href = 'src';
            a.appendChild(b);
            return a;
        })(),
        size: function() {
            var p = document.createElement('p');
            p.textContent = 'size';
            return p;
        }(),
        operation: (function() {
            var a = document.createElement('div');
            var copy = document.createElement('a');
            copy.className = 'nong-copy';
            copy.textContent = '复制';
            a.appendChild(copy);
            return a;
        })(),
        offline: (function() {
            var a = document.createElement('div');
            var b = document.createElement('a');
            b.className = 'nong-offline-download';
            b.target = '_blank';
            for (var k in offline_sites) {
                if (offline_sites[k].enable) {
                    var c = b.cloneNode(true);
                    c.href = offline_sites[k].url;
                    c.textContent = offline_sites[k].name;
                    a.appendChild(c);
                }
            }
            return a;
        })(),
    },
    create_table: function() {
        var a = document.createElement('table');
        a.id = 'nong-table';
        return a;
    },
    updata_table: function(src, data) {
        // console.log(data);
        var tab = $('#nong-table')[0];
        var a = tab.querySelectorAll('.nong-row');
        for (var i = 0; i < a.length; i++) {
            if (a[i].id == 'nong-head') {
                continue;
            }
            tab.removeChild(a[i]);
        }
        for (var i = 0; i < data.length; i++) {
            tab.appendChild(this.template.create_row(data[i]));
        }
        common.reg_event();
    },
    full: function(src, data) {
        var tab = this.create_table();
        tab.appendChild(this.template.create_head());
        // for (var i = 0; i < data.length; i++) {
        //     tab.appendChild(this.template.create_row(data[i]))
        // }
        var loading = this.template.create_loading();
        tab.appendChild(loading);
        return tab;
    },
    mini: function(data) {
        var tab = this.create_table();
        tab.append(this.template.create_offline());
        return tab;
    }
};
var matched_sites = {
    //av信息查询 类
    jav: {
        re: /(javtag|javlog|avmemo).*movie.*/,
        vid: function() {
            return $('.header')[0].nextElementSibling.innerHTML;
        },
        proc: function(wrapper) {
            common.after($('#movie-share')[0], wrapper);
        }
    },
    javlibrary: {
        re: /javlib3.*\?v=.*/,
        vid: function() {
            return $('#video_id')[0].getElementsByClassName('text')[0].innerHTML;
        },
        proc: function(wrapper) {
            common.after($('#video_favorite_edit')[0], wrapper);
        }
    },
    libredmm: {
        re: /libredmm/,
        vid: function() {
            return location.href.match(/products\/(.*)/)[1];
        },
        proc: function(wrapper) {
            common.after($('.container')[0], wrapper);
        }
    },
    dmm: {
        re: /dmm\.co\.jp/,
        vid: function() {
            var result = location.href.replace(/.*cid=/, '').replace(/\/\??.*/, '').match(/[^h_0-9].*/);
            return result[0] ? result[0].replace('00', '') : '';
        },
        proc: function(wrapper) {
            common.after($('.lh4')[0], wrapper);
        }
    },
    minnano: {
        re: /minnano-av/,
        vid: function() {
            var elems = $('.t11');
            var r = '';
            for (var i = 0; i < elems.length; i++) {
                if (elems[i].textContent == '品番') {
                    r = elems[i].nextElementSibling.textContent;
                    break;
                }
            }
            return r;
        },
        proc: function(wrapper) {
            var tmp = (function() {
                var a = $('table');
                for (var i = 0; i < a.length; i++) {
                    if (a[i].bgColor == '#EEEEEE') {
                        return a[i];
                    }
                }
            })();
            common.after(tmp, wrapper);
        }
    },
    oisinbosoft: {
        re: /oisinbosoft/,
        vid: function() {
            var r = location.pathname.replace(/.*\/+/, '').replace('.html', '');
            return r.indexOf('-') == r.lastIndexOf('-') ? r : r.replace(/\w*-?/, '');
        },
        proc: function(wrapper) {
            // add_style('#magnet-tab table{clear:both;}');
            common.after($('#detail_info')[0], wrapper);
        }
    },
    javbus: {
        re: /javbus/,
        vid: function() {
            var a = $('.header')[0].nextElementSibling;
            return a ? a.textContent : '';
        },
        proc: function(wrapper) {
            common.after($('.movie')[0], wrapper);
        }
    },
    avdb: {
        re: /avdb\.la/,
        vid: function() {
            return $('.info')[0].firstElementChild.innerHTML.replace(/<.*>/, '').trim();
        },
        proc: function(wrapper) {
            common.after($('#downs')[0].previousElementSibling, wrapper);
        }
    },
    jav141: {
        re: /141jav/,
        vid: function() {
            return location.href.match(/view\/(.*)\//)[1];
        },
        proc: function(wrapper) {
            common.after($('.dlbtn')[0].previousElementSibling, wrapper);
        },
    },
    av4you: {
        re: /av4you/,
        vid: function() {
            return $('.star-detail-name')[0].textContent.trim();
        },
        proc: function(wrapper) {
            common.after($('.star-detail')[0], wrapper);
        }
    },
    dmmy18_sin: {
        re: /dmmy18\.com\/details\.aspx\?id=.*/,
        vid: function() {
            return $('.info li')[0].textContent.replace('番号:', '');
        },
        proc: function(wrapper) {
            common.after($('.head_coverbanner')[0], wrapper);
        },
    },
    //网盘下载 类
    //这些 $ 是真正的 jquery
    baidu: {
        re: /pan\.baidu\.com/,
        fill_form: function(magnet) {
            $('.icon-btn-download')[0].click();
            setTimeout(function() {
                $('.create-normal-button')[0].click();
                $('#share-offline-link').val(magnet);
                $('.dlg-ft .sbtn')[0].click();
                // setTimeout(function() {
                //     $('.btlist-bottom .sbtn')[0].click();
                // }, 3000);
            }, 1000);
        }
    },
    115: {
        re: /115\.com/,
        fill_form: function(link) {
            var rsc = setInterval(function() {
                if (document.readyState == 'complete') {
                    clearInterval(rsc);
                    setTimeout(function() {
                        Core['OFFL5Plug'].OpenLink();
                        setTimeout(function() {
                            $('#js_offline_new_add').val(link);
                        }, 300);
                    }, 1000);
                }
            }, 400);
        }
    },
    letv: {
        re: /cloud\.letv\.com/,
        fill_form: function(link) {
            setTimeout(function() {
                $('#offline-btn').click();
                setTimeout(function() {
                    $('#offline_clear_complete').prev().click();
                    setTimeout(function() {
                        $('#offline-add-link').val(link);
                    }, 500);
                }, 1000);
            }, 2000);
        }
    },
    furk: {
        re: /www\.furk\.net/,
        fill_form: function(link) {
            setTimeout(function() {
                $('#url').val(link.replace('magnet:?xt=urn:btih:', ''));
            }, 1500);
        }
    },
    360: {
        re: /yunpan\.360\.cn\/my/,
        fill_form: function(link) {
            yunpan.cmdCenter.showOfflineDia();
            setTimeout(function() {
                $('.offdl-btn-create').click();
                setTimeout(function() {
                    $('#offdlUrl').val(link);
                }, 500);
            }, 1000);
        }
    },
    uc: {
        re: /disk\.yun\.uc\.cn\//,
        fill_form: function(link) {
            setTimeout(function() {
                $('#newuclxbtn_index').click();
                setTimeout(function() {
                    $('#uclxurl').val(link);
                }, 1000);
            }, 1200);
        }
    },
    //磁链接搜索 类
    // btcherry_mul: {
    //     re: /btcherry\.net\/search\?keyword=.*/,
    //     selector: '.r div a',
    //     func: function(target) {
    //         return target.href;
    //         // $xafter('.r div a', div, function(elem) {
    //         //     //elem 等于 document.querySelectorAll(.r div a)的成员
    //         //     return elem.href;
    //     };
    // },
    // btcherry_sin: {
    //     re: /btcherry\.net\/t\/.*/,
    //     selector:'';
    //     func: function(div) {
    //         div.setAttribute('data', $('#content ul a')[0].href);
    //         common.after($('#content h1')[0], div);
    //     },
    // },
    // btdigg_multiple: {
    //     re: /btdigg/,
    //     func: function(div) {
    //         $xafter('.snippet', div, function(elem) {
    //             return elem.parentElement.getElementsByClassName('ttth')[0].firstElementChild.href;
    //         });
    //     },
    // },
    // // btdigg_single: {
    // // },
    // cilizhushou_multiple: {
    //     re: /cilizhushou/,
    //     func: function(div) {
    //         $xafter('.tail', div, function(elem) {
    //             return elem.getElementsByTagName('a')[0].href;
    //         });
    //     },
    // },
    // // shousibaocai_single: {
    // //   re: '',
    // //   func: '',
    // // },
    // btava_multiple: {
    //     re: /search\//,
    //     func: function(div) {
    //         $xafter('.data-list .date', div, function(elem) {
    //             return 'magnet:?xt=urn:btih:' + elem.parentElement.getElementsByTagName('a')[0].href.match(/hash\/(.*)/)[1];
    //         });
    //     },
    // },
    // btava_single: {
    //     re: /magnet\/detail\/hash\//,
    //     func: function(div) {
    //         div.setAttribute('data', $('#magnetLink')[0].value);
    //         common.after($('#magnetLink')[0], div);
    //     },
    // },
    // // instsee_multiple:{
    // //   re: /^http:\/\/www\.instsee.com\/$|instsee\.com\/default.aspx.*/,
    // //   func: function(div){
    // //   }
    // // },
    // demo: {
    //     re: /.*/,
    //     vid: function() {
    //         return 'demo'
    //     },
    //     proc: function(table) {
    //         common.after(document.body, table);
    //     }
    // },
};
var search_engines = {
    bt2mag: function(kw, cb) {
        GM_xmlhttpRequest({
            method: 'GET',
            url: 'http://www.bt2mag.com/search/' + kw,
            onload: function(result) {
                var doc = common.parsetext(result.responseText)
                if (!doc) {
                    //TODO
                }
                var data = [];
                var t = doc.getElementsByClassName('data-list')[0];
                if (t) {
                    var a = t.getElementsByTagName('a');
                    for (var i = 0; i < a.length; i++) {
                        if (!a[i].className.match('btn')) {
                            data.push({
                                'title': a[i].title,
                                'maglink': 'magnet:?xt=urn:btih:' + a[i].href.replace(/.*hash\//, ''),
                                'size': a[i].nextElementSibling.textContent
                                    //'src':'' TODO
                            });
                        }
                    }
                }
                cb(result.finalUrl, data);
            },
            onerror: function(e) {
                console.log(e);
            }
        })
    },
    diggbt: function(kw, cb) {
        GM_xmlhttpRequest({
            method: 'POST',
            url: this.url,
            data: 's=' + kw,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            onload: function(result) {
                var trick = function(str) {
                    var t = document.createElement('a');
                    t.outerHTML = str.match(/document.write\(\'(.*)\'\)/)[1].split('\'+\'').join('');
                    return t.href;
                }
                var doc = document.implementation.createHTMLDocument('');
                doc.documentElement.innerHTML = result.responseText;
                var data = [];
                var t = doc.getElementsByClassName('list-con')[0];
                if (t) {
                    var elems = t.getElementsByClassName('item-title');
                    for (var i = 0; i < elems.length; i++) {
                        data.push({
                            'title': elems[i].getElementsByTagName('a')[0].textContent,
                            'magnet': trick(elems[i].nextElementSibling.getElementsByTagName('script')[0].innerHTML),
                            'size': elems[i].nextElementSibling.getElementsByTagName('b')[1].textContent
                        });
                    }
                    cb(result.finalUrl, data);
                }
            },
            onerror: function(e) {
                console.log(e);
            }
        });
    },
    btlibrary: function(kw, cb) {
        GM_xmlhttpRequest({
            method: 'POST',
            url: this.url,
            data: 's=' + kw,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            onload: function(result) {
                var doc = document.implementation.createHTMLDocument('');
                doc.documentElement.innerHTML = result.responseText;
                var data = [];
                var t = doc.getElementsByClassName('list-content')[0];
                if (t) {
                    var elems = t.getElementsByClassName('item-title');
                    for (var i = 0; i < elems.length; i++) {
                        data.push({
                            'title': elems[i].getElementsByTagName('a')[0].textContent,
                            'magnet': elems[i].nextElementSibling.getElementsByTagName('a')[0].href,
                            'size': elems[i].nextElementSibling.getElementsByTagName('b')[1].textContent
                        });
                    }
                    cb(result.finalUrl, data);
                }
            },
            onerror: function(e) {
                console.log(e);
            }
        });
    },
    demo: function(kw, cb) {
        var data = [];
        var r = 0;
        for (var i = 0; i < 10; i++) {
            r = Math.round(Math.random() * 100)
            data.push({
                title: r + 'title',
                maglink: r + 'maglink',
                size: r + 'size'
            })
        }
        cb(data);
    },
};
var test = {
    cb_search: function(src, data) {
        // body...
    },
    search: function() {
        var vid = '';
        for (var k in search_engines) {
            search_engines[k](vid, function() {
                console.log(k, src, data); //?????作用域
            });
        }
    },
};

var default_search_name = 'bt2mag';
// for (var k in search_engines) {
//     default_name = k;
//     break
// }
var current_vid = ''
var current_search_name = 'bt2mag'; //GM_getValue('search', default_search_name);
var run = function() {
    common.add_style();
    if (!debugging) {
        for (var key in matched_sites) {
            if (matched_sites[key].re.test(location.href)) {
                if (matched_sites[key].proc) {
                    var table = magnet_table.full();
                    matched_sites[key].proc(table);
                    current_vid = matched_sites[key].vid();
                    if (!current_vid) {
                        $('#notice').textContent = 'Can\'t match vid';
                    }
                    search_engines[current_search_name](current_vid, function(src, data) {
                        if (data.length == 0) {
                            $('#nong-table')[0].querySelectorAll('#notice')[0].textContent = 'No search result';
                        }
                        else {
                            magnet_table.updata_table(src, data);
                        }
                    });
                }
                else if (matched_sites[key].fill_form) {
                    var js = matched_sites[key].fill_form;
                    var maglink = GM_getValue('magnet');
                    if (maglink) {
                        common.insert_js(js, maglink);
                    }
                }
                // else if (matched_sites[key].func) {
                //     common.add_mini_table(matched_sites[key].selector, matched_sites[key].func);
                // }
                break;
            }

        }
    }
    else {
        var key = 'demo';
        // current_key = key;
        search_engines.demo(matched_sites[key].vid(), function(data) {
            var table = magnet_table.full(data);
            matched_sites[key].proc(table);
            common.reg_event();
        })
    };
};
run();