Greasy Fork

Greasy Fork is available in English.

360,百度网盘链接

360,百度网盘链接自动添加访问密码

当前为 2015-11-05 提交的版本,查看 最新版本

// ==UserScript==
// @name        360,百度网盘链接
// @author      林岑影
// @description 360,百度网盘链接自动添加访问密码
// @namespace   
// @icon        http://disk.yun.uc.cn/favicon.ico
// @license     GPL version 3
// @encoding    utf-8
// @date        18/07/2015
// @modified    11/04/2015
// @include     *
// @exclude     http://pan.baidu.com/*
// @exclude     http://yunpan.360.cn/*
// @exclude     http://yunpan.cn/*
// @exclude     http://vdisk.weibo.com/*
// @grant       unsafeWindow
// @grant       GM_setClipboard
// @run-at      document-end
// @version     2.0.8
// ==/UserScript==

(function(window){
    var autoHash = function(){
        this.config = {
            domain: {
                "baidu":"pan.baidu.com/s/",
                "yunpan":"yunpan.cn",
                "vdisk":"vdisk.weibo.com"
            },
            reg: /(码|问)[\s|:|:]*([a-zA-Z0-9]{4,4})([\W\s]+|$)/g
        }
    };
    autoHash.prototype = {
        init: function(){
            this.auto();
            var toolbar = document.querySelector("body");
            toolbar.addEventListener("click", hash.delegate(hash.buttonsFilter, hash.buttonHandler));
        },
        delegate: function(criteria, listener) {
            return function (e) {
                var el = e.target;
                if (criteria(el)) {
                    e.delegateTarget = el;
                    listener.apply(this, arguments);
                }
                return;
            };
        },
        buttonsFilter: function(elem) {
            var href = typeof elem == "object" ? elem.getAttribute("href") : "",
                isDomain = false;
            if (!href) return false;
            for (var index in hash.config.domain) {
                if (href.indexOf(hash.config.domain[index]) > -1) {
                    isDomain = true;
                    break;
                }
            }
            return isDomain;
        },
        buttonHandler: function(e) {
            var a    = e.delegateTarget,
                link = a.getAttribute("href");
            if (link.indexOf("#")>-1) return true;
            hash.replace(a, link);
        },
        replace: function(a, link){
            link = link || a.getAttribute("href");
            var body = document.querySelector("body").innerHTML,
                arr_body = body.split('"'+link),
                text = arr_body[1].split('href=')[0],
                re = this.config.reg,
                r = re.exec(text);
            if (r && r[2]) {
                a.setAttribute("href", link+"#"+r[2]);
            } else {
                text = a.parentNode.innerText,
                r = re.exec(text);
                if (r && r[2]) {
                    a.setAttribute("href", link+"#"+r[2]);
                }
            }
        },
        auto: function() {
            var alllink = document.querySelectorAll("a");
            for (var index in alllink) {
                if (this.buttonsFilter(alllink[index])) {
                    this.replace(alllink[index]);
                }
            }
        }
    };
    var hash = new autoHash();
    hash.init();
}(window));