Greasy Fork is available in English.
小工具
当前为
// ==UserScript==
// @name pageHelper
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 小工具
// @author 纯白约定
// @grant 纯白约定
// @include https://weread.qq.com/web/reader/*
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
// ==/UserScript==
/* global $ */
// 发送右键
function sendRightKey(){
if(!window.isEnabled){return null;}
return fireKeyEvent(document,'keydown',39);
}
(function() {
'use strict';
window.$body = $('body')
window.$document = $(document)
window.scrollOffset = 0
window.stepFlag = 1
window.offsetStep = 2
initElement(window.$body);
})();
// 开启循环任务
function startInterval(){
if(window.timerScroll==null){
window.timerScroll = setInterval(function(){
const top = window.$document.scrollTop()
if(top===0){window.stepFlag = 1}
window.scrollOffset+=window.stepFlag*window.offsetStep
window.$document.scrollTop(window.scrollOffset)
// scroll后scrollTop不变,则可以切换scroll方向了
if (top==window.$document.scrollTop()){window.stepFlag=-1}
},100)
}
if(window.timerRight==null){
window.timerRight = setInterval(function(){ fireKeyEvent(document,'keydown',39); },300000)
}
}
// 关闭循环任务
function stopInterval(){
if(window.timerScroll!=null){
clearInterval(window.timerScroll)
window.timerScroll=null
}
if(window.timerRight!=null){
clearInterval(window.timerRight)
window.timerRight=null
}
}
// 根据开关情况处理循环任务
function handleInterval(isEnabled){
if(isEnabled){
startInterval()
return
}
if(!isEnabled){
stopInterval()
}
}
window.isEnabled = false
function initElement($body){
$body.append('<button id="switch" id="switch" style="position: fixed;top: 100px;right:100px;background-color:white;width:100px;height:50px;cursor:pointer;">已关闭</button>');
$('#switch').on('click',function(){
window.isEnabled = !window.isEnabled
this.textContent = window.isEnabled ? "已开启" : "已关闭"
handleInterval(window.isEnabled)
})
}
// 模拟发送按键
function fireKeyEvent(el, evtType, keyCode) {
var evtObj;
if (document.createEvent) {
if (window.KeyEvent) {//firefox 浏览器下模拟事件
evtObj = document.createEvent('KeyEvents');
evtObj.initKeyEvent(evtType, true, true, window, true, false, false, false, keyCode, 0);
} else {//chrome 浏览器下模拟事件
evtObj = document.createEvent('UIEvents');
evtObj.initUIEvent(evtType, true, true, window, 1);
delete evtObj.keyCode;
if (typeof evtObj.keyCode === "undefined") {//为了模拟keycode
Object.defineProperty(evtObj, "keyCode", { value: keyCode });
} else {
evtObj.key = String.fromCharCode(keyCode);
}
if (typeof evtObj.ctrlKey === 'undefined') {//为了模拟ctrl键
Object.defineProperty(evtObj, "ctrlKey", { value: true });
} else {
evtObj.ctrlKey = true;
}
}
el.dispatchEvent(evtObj);
} else if (document.createEventObject) {//IE 浏览器下模拟事件
evtObj = document.createEventObject();
evtObj.keyCode = keyCode
el.fireEvent('on' + evtType, evtObj);
}
}