360,百度网盘链接自动添加访问密码
当前为
// ==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 09/10/2015
// @include *
// @exclude http://pan.baidu.com/*
// @exclude http://yunpan.360.cn/*
// @exclude http://yunpan.cn/*
// @grant unsafeWindow
// @grant GM_setClipboard
// @run-at document-end
// @version 2.0.6
// ==/UserScript==
(function(window){
var autoHash = function(){
};
autoHash.prototype = {
init: function(){
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 = elem.getAttribute("href");
return href && (href.indexOf("pan.baidu.com/s/") > 0 || href.indexOf("yunpan.cn") > 0);
},
buttonHandler: function(e) {
var a = e.delegateTarget,
link = a.getAttribute("href");
if (link.indexOf("#")>-1) return true;
var body = document.querySelector("body").innerHTML,
arr_body = body.split('"'+link),
text = arr_body[1].split('href=')[0],
re = /(码|问)[\s|:|:]*([a-zA-Z0-9]{4,4})([\W\s]+|$)/g,
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]);
}
}
}
};
var hash = new autoHash();
hash.init();
}(window));