Tap to Scroll (Ignore Links)

Tap the top or bottom of the screen to scroll the page up or down, while ignoring taps on links and interactive elements. Double-tap to close active article (only on FreshRSS). Preserve original double-click behavior on other websites.

当前为 2025-02-04 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Tap to Scroll (Ignore Links)
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Tap the top or bottom of the screen to scroll the page up or down, while ignoring taps on links and interactive elements. Double-tap to close active article (only on FreshRSS). Preserve original double-click behavior on other websites.
// @author       Your Name
// @homepage     https://greasyfork.org/en/scripts/525817
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Define the threshold for tap zones (e.g., top 20% and bottom 20% of the screen)
    const tapZoneThreshold = 0.2; // 20% of the screen height

    // Single-tap event for scrolling
    document.addEventListener('click', function (event) {
        // Check if the tap is on an interactive element (e.g., link, button, input)
        const interactiveElements = ['A', 'BUTTON', 'INPUT', 'TEXTAREA', 'SELECT', 'LABEL'];
        if (interactiveElements.includes(event.target.tagName)) {
            return; // Ignore taps on interactive elements
        }

        const screenHeight = window.innerHeight;
        const tapY = event.clientY; // Y-coordinate of the tap

        // Determine if the tap is in the top or bottom zone
        if (tapY < screenHeight * tapZoneThreshold) {
            // Tap in the top zone: scroll up
            window.scrollBy({ top: -window.innerHeight * 0.8, behavior: 'smooth' });
        } else if (tapY > screenHeight * (1 - tapZoneThreshold)) {
            // Tap in the bottom zone: scroll down
            window.scrollBy({ top: window.innerHeight * 0.8, behavior: 'smooth' });
        }
    });

    // Double-tap event
    document.addEventListener('dblclick', function (event) {
        // Check if the current webpage is FreshRSS
        const isFreshRSS = window.document.title.endsWith("· FreshRSS"); // Adjust the condition as needed

        if (isFreshRSS) {
            // Custom behavior for FreshRSS
            // Check if the double-tap is on an interactive element
            const interactiveElements = ['A', 'BUTTON', 'INPUT', 'TEXTAREA', 'SELECT', 'LABEL'];
            if (interactiveElements.includes(event.target.tagName)) {
                return; // Ignore double-taps on interactive elements
            }

            // Find the closest element with both 'current' and 'active' classes
            const activeElement = event.target.closest('.current.active');
            if (activeElement) {
                // Remove the 'active' class
                activeElement.classList.remove('active');
                // console.log('Removed "active" class from:', activeElement);
            }
        } else {
            // Allow the original double-click behavior on non-FreshRSS webpages
            return; // Do nothing, let the browser handle the double-click
        }
    });
})();