Greasy Fork is available in English.

网盘自动填写密码【增强版】

网盘自动填写提取密码【增强版】+网盘超链接与提取码融合。

2015-11-03 06:25:11 UTC itibariyledir. En son verisyonu görün.

// ==UserScript==
// @name 			网盘自动填写密码【增强版】
// @description		网盘自动填写提取密码【增强版】+网盘超链接与提取码融合。
// @authore			极品小猫
// @namespace   	http://www.cnblogs.com/hkmhd/
// @homepage		https://greasyfork.org/scripts/13463
// @supportURL		https://greasyfork.org/scripts/13463/feedback
// @version			2.1.0
// 
// 支持的网盘
// @include     	http://pan.baidu.com/share/init?*
// @include     	http://yun.baidu.com/share/init?*
// @include     	http://www.kuaipan.cn/file/id_*
// @include     	http://*.yunpan.cn/lk/*
// @include     	http://vdisk.weibo.com/lc/*
// @include     	http://*
// @include			https://*
// 
// @exclude			/https?://www.baidu.com/(?:s|baidu)\?/
// @require			http://code.jquery.com/jquery-latest.js
// @grant			unsafeWindow
// @run-at			document-idle
// ==/UserScript==

var urls=location.href;
var hash=location.hash;
var host=location.hostname.replace(/^www\./i,'').toLowerCase();
unsafeWindow.eve = Event;

var site = {
	'yunpan.cn': {
		chk:  /^[a-z0-9]{4}$/,
		code: '.pwd-input',
		btn:  '.submit-btn'
	},
	'baidu.com': {
		chk:  /^[a-z0-9]{4}$/,
		code: '#accessCode',
		btn:  '#submitBtn'
	},
	'kuaipan.cn': {
		chk:  /^[a-z0-9]{6}$/i,
		code: '#pwdContaier .txt',
		btn:  '#btnOK',
		preSubmit: function (codeBox, okBtn) {
			$('#pwdContaier .bold').textContent = '请手动单击确认按钮然后刷新页面';
		}
	},
	'weibo.com': {
		chk:  /^[a-z0-9]{4}$/i,
		code: '#keypass',
		btn:  '.search_btn_wrap > a',
		preSubmit: function (codeBox, okBtn) {unsafeWindow.$("#validate").submit();}
	},
	'codeRule':/(?:提取码|密码|访问码?|艾码)[:: ]?\s*([a-z\d]{4})/i
};

var hostName = location.host.match(/\w+\.\w+$/)[0].toLowerCase();
var conf = site[hostName];
var HostArr = [];for(var i in site) HostArr.push(i);var HostExp = new RegExp(HostArr.join("|"),'i');	//生成校验超链接的正则

if(conf){
	// 抓取提取码
	var sCode = hash.slice(1).trim();
	
	// 调试用,检查是否为合法格式
	if (!conf.chk.test(sCode)) {
		console.log('没有 Key 或格式不对');
	} else {
		console.log ('抓取到的提取码: %s', sCode);
	}

		// 加个小延时
		setTimeout (function () {
			// 键入提取码并单击「提交」按钮,报错不用理。
			var codeBox = $(conf.code),
				btnOk = $(conf.btn);

			codeBox.val(sCode);		//填写验证码
			
			if (conf.preSubmit)
				if (conf.preSubmit (codeBox, btnOk))
					return ;

			btnOk.click();
		}, 10);
} else {
	$('A').click(function(){
		//console.log(this.parentNode.textContent);
		if(HostExp.test(event.target.href)){
			if(site['codeRule'].test(event.target.textContent)){
				console.log('在当前超链接的对象中查找密码');
				var pw=event.target.textContent.match(site['codeRule'])[1];
				event.target.href+='#'+pw;
			} else if(site['codeRule'].test(event.target.nextSibling.textContent)){
				console.log('密码在超链接后面的兄弟元素中');
				eventNext = event.target.nextSibling.textContent.trim();
				var pw=eventNext.match(site['codeRule'])[1];
				if(!/#/i.test(event.target.href)) event.target.href+='#'+pw;
			} else if(site['codeRule'].test(event.target.parentNode.textContent)){
				console.log('从父对象中查找密码');
				if(!/#/i.test(event.target.href)) event.target.href+='#'+event.target.parentNode.textContent.match(site['codeRule'])[1];
			}
		}
	})
}