Baidu Pan SuperKey

度盘万能钥匙,云盘万能钥匙扩展改成 GM 脚本

As of 2018-06-19. See the latest version.

// ==UserScript==
// @name		Baidu Pan SuperKey
// @namespace	a@b.c
// @author		jasake
// @description	度盘万能钥匙,云盘万能钥匙扩展改成 GM 脚本
// @description	有需要的请使用原版扩展:https://addons.mozilla.org/zh-CN/firefox/addon/ypsuperkey/
// @include		https://pan.baidu.com/share/init?surl=*
// @include		https://pan.baidu.com/wap/init?surl=*
// @charset		UTF-8
// @version		0.3
// @grant		GM_xmlhttpRequest
// @run-at		document-end
// ==/UserScript==

var input = document.querySelector('.pickpw input[tabindex="1"], .access-box input#accessCode'),
	btn = document.querySelector('.pickpw a.g-button, .access-box a#getfileBtn'),
	label = document.querySelector('.pickpw dt, .access-box label[for=accessCode]');
label.style.margin="-5px 0 10px";
label.innerHTML += '<br>度盘万能钥匙:';

//if (location.hash && /^#([a-zA-Z0-9]{4})$/.test(location.hash)) return;//v2
if (location.hash && /^#([a-zA-Z0-9]{4})$/.test(location.hash)) {//v3,三秒后
	var hash = RegExp.$1;
	label.innerHTML += '网址符合格式带有提取码:'.fontcolor('green') + hash.fontcolor('red') + ',若无其他脚本动作,三秒后自动填写并点击'.fontcolor('green');
	setTimeout(function() {
		input.value = hash;
		btn.click();
	},
	3e3);
	return;
}

var url ='https://ypsuperkey.meek.com.cn/api/items/BDY-'
		+ location.href.match(/\/init\?surl=((?:\w|-)+)/)[1] + '?access_key=4fxNbkKKJX2pAm3b8AEu2zT5d2MbqGbD&client_version=2018.8';

GM_xmlhttpRequest({
	method: 'GET',
	url: url,
	onload: function(xhr) {
		var e = JSON.parse(xhr.responseText);
		label.innerHTML += xhr.status == 200 ? ('连接成功,'.fontcolor('blue') + (e.access_code ? '密码已获取'.fontcolor('blue') : '但密码找不到'.fontcolor('red'))) : (e.message + ',服务器状态:' + xhr.statusText + '(' + xhr.status + ')').fontcolor('red');//状态提示
		if (xhr.status == 200 && e.access_code) {
			input.value = e.access_code;//填写密码
			setTimeout(function(){btn.click();}, 1e3);//一秒后自动点击
		}
	}
});