Greasy Fork

Greasy Fork is available in English.

触屏翻页脚本

点击屏幕上方空白处上翻,屏幕空白处下方下翻

当前为 2024-07-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         触屏翻页脚本
// @version      1.0
// @description  点击屏幕上方空白处上翻,屏幕空白处下方下翻
// @author       ChatGPT
// @match        *://*/*
// @run-at       document-end
// @grant        none
// @namespace http://greasyfork.icu/users/452911
// ==/UserScript==

(function() {
    'use strict';

    var clicked = false; // 标记是否点击过屏幕

    document.addEventListener('click', function(e) {
        if (clicked) {
            // 防止连续点击
            return;
        }

        clicked = true;
        setTimeout(function() {
            var clickedY = e.clientY; // 获取鼠标点击位置的Y坐标
            var threshold = window.innerHeight / 2; // 判断上下滑动的阈值

            if (clickedY < threshold) {
                // 点击了屏幕上半屏
                window.scrollBy(0, -window.innerHeight / 6 * 5); // 上滑六分之五屏
            } else {
                // 点击了屏幕下半屏
                window.scrollBy(0, window.innerHeight / 6 * 5); // 下滑六分之五屏
            }

            clicked = false;
        }, 200); // 设置延迟时间
    });

})();