阅读小说时增强功能:1. 预加载下一页;2. 自动填充人机验证;
Verze ze dne
// ==UserScript==
// @name 第一版主小说阅读
// @namespace https://diyibanzhu.org/
// @version 0.2
// @description 阅读小说时增强功能:1. 预加载下一页;2. 自动填充人机验证;
// @author Essence
// @match https://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=diyibanzhu.org
// @run-at document-end
// @license MIT
// ==/UserScript==
// 站点名。域名经常变动,没有更好的判断方法
const SITE_NAME = "歪歪蒂艾斯";
// 脚本页面:预加载下一页
const nextPage = ()=>{
// 依次找到"下一页"的元素:优先“下一页”,其次“下一章”
const nextLink = document.querySelector("a.curr")?.nextElementSibling || document.querySelector("a.next");
console.log("脚本将预加载下一页", nextLink, nextLink?.href);
// If we found a matching link
if (nextLink && nextLink.href) {
// 通过"link prefetching"实现预加载下一页
const link = document.createElement("link");
// 注意:最后第一版主网站的章中最后的一页的 URL 的 href 是以"javascript:"开头,其它页是正常的 URL
let href = nextLink.href;
if(href.startsWith("javascript:")){
const params = href.match(/\d+/g)
href = "/" + params.slice(0, -1).join("/") + "_" + params.slice(-1) + ".html";
}
link.href = href;
link.rel = "prefetch";
document.head.appendChild(link);
}
}
// 脚本页面:自动填充人机验证
const verifyPage = ()=>{
document.querySelector("input#password").value="1234";
document.querySelector("div.login a").click();
}
(function() {
'use strict';
// Your code here...
// 不是目标网站
if(!document.title.includes(SITE_NAME)){
return;
}
// 脚本页面:预加载下一页
if(document.querySelector("h1.page-title")?.textContent?.trim()){
console.log("预加载下一页");
nextPage();
}
// 脚本页面:自动填充人机验证
if(document.querySelector("div.title")?.textContent?.includes("为防止恶意访问")){
console.log("自动填充人机验证");
verifyPage();
}
})();