switch520-auto-secret

非常便捷,帮你免去所有不必要的重复点击和填写密码

目前為 2024-10-28 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         switch520-auto-secret
// @namespace    http://tampermonkey.net/
// @version      1.2.2
// @description  非常便捷,帮你免去所有不必要的重复点击和填写密码
// @author       Kane
// @match        *://*.gamers520.com/*
// @match        *://*.gamer520.com/*
// @match        *://download.gamer520.com/*
// @match        *://download.espartasr.com/*
// @match        *://download.freer.blog/*
// @match        *://www.freer.blog/*
// @match        *://*.xxxxx528.com/*
// @match        *://www.efemovies.com/*
// @match        *://www.espartasr.com/*
// @match        *://www.piclabo.xyz/*
// @match        *://like.gamer520.com/*
// @license MIT
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gamer520.com
// ==/UserScript==

(function() {
	'use strict';
	
	const el_input = function() {
		return document.querySelector('input#password') ||
			document.querySelector(`input[type='password']`) ||
			document.querySelector(`input[name='post_password']`);
	}();
	const el_submit = function() {
		return document.querySelector(`input[type='submit']`) ||
			document.querySelector(`input[name='Submit']`) ||
			document.querySelector(`input[value='提交']`);
	}();
	
	
	document.querySelectorAll('*').forEach((node) => {
		const innerText = node.innerText;
		if (
			innerText?.startsWith('密码保护:') &&
			!innerText?.includes('上一篇') &&
			!innerText?.includes('牛夫人') &&
			!innerText?.includes('当前位置') &&
			!innerText?.includes('此内容受密码保护') &&
			!innerText?.includes('永久防迷路')
		) {
			// const [result] = innerText.match(/[0-9]{3,6}/) ?? [null];
			const secret = innerText.replace('密码保护:' , '');
			if ( secret && el_input ) {
				
				el_input.value = secret;
				el_submit.click();
			}
		}
	});
	
	
	//以下代码将百度网盘的链接+提取码融合为一个按钮,点击之后直接跳转并填充密码
	(() => {
		/**
		 * 拿到链接文本所在的P标签
		 * @type {HTMLElement}
		 */
		const containerDiv = function() {
			return Array.from(document.querySelectorAll('div.entry-content.u-text-format.u-clearfix')).find(el => {
				return (el.innerText?.includes?.('提取码')) && (el.innerText?.includes?.('链接:')) && (el.innerText?.includes?.('https://pan.baidu.com'));
			});
		}();
		
		if ( containerDiv ) {
			const [baiduLink , baiduLinkAElement] = function() {
				const aElement = Array.from(containerDiv.querySelectorAll('a')).find(el => {
					return (el.href?.startsWith?.('https://pan.baidu.com'));
				});
				return [aElement.href , aElement];
			}();
			
			const [pwdText , pwdElement] = function() {
				const pwdElement = Array.from(containerDiv.querySelectorAll('*')).find(el => el?.innerText?.startsWith?.('提取码:'));
				return [pwdElement?.innerText.replace('提取码: ' , '').replaceAll(' ' , '') , pwdElement];
			}();
			
			
			if ( !baiduLink.includes('pwd=') && pwdText ) {
				const href = baiduLink + (baiduLink.includes('?') ? `&pwd=${ pwdText }` : `?pwd=${ pwdText }`);
				baiduLinkAElement.href = href;
				baiduLinkAElement.innerText = baiduLinkAElement.innerText.replace(baiduLink , href);
			}
			
			containerDiv.removeChild(pwdElement);
		}
	})();
	
	//以下代码跳过获取下载地址的过程 , 不需要点两次立即下载
	(() => {
		const downloadButton = function() {
			return Array.from(document.querySelectorAll('a')).find(el => {
				return el.innerText === ' 立即下载';
			});
		}();
		
		let interval , invokedCount , startTime ;
		if(downloadButton){
			downloadButton.addEventListener('click', () => {
				invokedCount = 0;
				startTime = Date.now();
				interval = setInterval(() => {
					if(invokedCount >= 40 || Date.now() - startTime > 5 * 1000){
						clearInterval(interval);
						interval = null;
						invokedCount = 0;
					}else {
						invokedCount++;
						const secondDownloadButton = function() {
							return Array.from(document.querySelectorAll('*')).find(el => el.innerText === '立即下载');
						}();
						if(secondDownloadButton){
							secondDownloadButton.click();
						}
					}
				} , 100);
			})
		}
	})();
})();