Greasy Fork

来自缓存

Greasy Fork is available in English.

pageHelper

小工具

当前为 2020-08-28 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         pageHelper
// @namespace    http://tampermonkey.net/
// @version      0.3.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 = 1
    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}
        },1000)
    }

    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;z-index:1024;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);
        } else {//chrome 浏览器下模拟事件
            evtObj = document.createEvent('UIEvents');
            evtObj.initUIEvent(evtType, true, true);

            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);
    }
}