try to take over the world!
当前为
// ==UserScript==
// @name 预加载下一章/页,方向键上/下一章
// @namespace http://tampermonkey.net/
// @version 0.3
// @description try to take over the world!
// @author wodexianghua
// @match http://*/*
// @match https://*/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
var shang = false;
var xia = false;
var searchText_now = [];
var found_pre_now;
var found_next_now;
var iscanfenye = true;
var searchText = {
pre: ["上一章", "上一页", "pre", "<"],
next: ["下一章", "下一页", "next", ">"]
}
document.addEventListener('keydown', function (event) {
if (document.activeElement.nodeName != 'BODY') return;
else if (document.activeElement.nodeName == 'BODY' && !iscanfenye) {
return;
}
if (event.keyCode == 37) {
shang = true;
} else if (event.keyCode == 39) {
xia = true;
}
//是否按下左右键
if (shang || xia) {
if (shang) {
if (found_pre_now != undefined && document.contains(found_pre_now) && isincludes(found_pre_now, searchText.pre)) {
shang = false;
found_pre_now.click();
return;
} else {
searchText_now = searchText.pre;
}
} else {
if (found_next_now != undefined && document.contains(found_next_now) && isincludes(found_next_now, searchText.next)) {
xia = false;
found_next_now.click();
return;
} else {
searchText_now = searchText.next;
}
}
let found = getpreornextelement(searchText_now);
if (found != undefined) found.click();
shang = false;
xia = false;
}
});
//如果有视频在播放,禁用左右键翻页
let video = document.querySelector('video');
if (video != null) {
video.addEventListener("play", function () {
iscanfenye = false;
});
video.addEventListener("pause", function () {
iscanfenye = true;
});
}
setTimeout(() => {
foundnextpage();
foundpreviouspage();
}, 8000);
function foundpreviouspage() {
found_pre_now = getpreornextelement(searchText.pre);
}
//预加载下一页
function foundnextpage() {
found_next_now = getpreornextelement(searchText.next);
//如果没找到或者href是javascript的话就退出
if (found_next_now == undefined) {
return;
} else if ((found_next_now != "没找到") && found_next_now.getAttribute('href').includes("javascript")) {
return;
}
let xiaurl = found_next_now.getAttribute('href');
if (!xiaurl.includes(document.domain)) {
var ishttps = 'https:' == document.location.protocol ? true : false;
if (ishttps) {
xiaurl = 'https://' + xiaurl;
} else {
xiaurl = 'http://' + xiaurl;
}
}
var head = document.querySelector('head');
head.insertAdjacentHTML('beforeend', '<link rel="prefetch" href="' + xiaurl + '" />');
return;
}
/**
* @param {string[]} searchTextarry
* @return {HTMLAnchorElement}
*/
function getpreornextelement(searchTextarry) {
for (const iterator of searchTextarry) {
if (document.body.innerText.includes(iterator)) {
let aTags = document.getElementsByTagName("a");
for (const iterator of searchTextarry) {
for (let i = 0; i < aTags.length; i++) {
if (aTags[i].textContent.includes(iterator) || (aTags[i].className == "next" | aTags[i].className == "n" | aTags[i].className == "pre" | aTags[i].className == "p")) {
let found = aTags[i];
return found;
}
}
}
}
}
return undefined;
}
/**
* @param {string[]} searchTextarry
* @param {string} Text
*/
function isincludes(Text, searchTextarry) {
for (const iterator of searchTextarry) {
if (Text.textContent.includes(iterator)) {
return true;
}
}
return false;
}
// Your code here...
})();