您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Double-tap to close active articles and auto-scroll to the active article in FreshRSS
当前为
- // ==UserScript==
- // @name FreshRSS Double-Tap and Auto-Scroll
- // @namespace http://tampermonkey.net/
- // @version 2.1
- // @description Double-tap to close active articles and auto-scroll to the active article in FreshRSS
- // @author Your Name
- // @homepage https://greasyfork.org/en/scripts/525912
- // @match http://192.168.1.2:1030/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // Debug mode
- const DEBUG = false;
- function debugLog(message) {
- if (DEBUG) {
- console.log(`[FreshRSS Script]: ${message}`);
- }
- }
- debugLog('Script loaded');
- // Function to scroll to element
- function scrollToElement(element) {
- if (element) {
- const header = document.querySelector('header');
- const headerHeight = header ? header.offsetHeight : 0;
- const elementPosition = element.getBoundingClientRect().top + window.pageYOffset;
- const offsetPosition = elementPosition - headerHeight - 10;
- window.scrollTo({
- top: offsetPosition,
- behavior: 'smooth'
- });
- debugLog('Scrolling to element: ' + element.id);
- }
- }
- // Handle double-tap to close
- document.addEventListener('dblclick', function(event) {
- const interactiveElements = ['A', 'BUTTON', 'INPUT', 'TEXTAREA', 'SELECT', 'LABEL'];
- if (interactiveElements.includes(event.target.tagName)) {
- debugLog('Ignored double-tap on interactive element');
- return;
- }
- const activeElement = event.target.closest('.flux.active');
- if (activeElement) {
- activeElement.classList.remove('active');
- debugLog('Closed article via double-tap');
- // scrollToElement(activeElement);
- activeElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
- }
- });
- // mutation observer to catch programmatic changes
- const observer = new MutationObserver((mutations) => {
- mutations.forEach((mutation) => {
- if (mutation.target.classList && mutation.target.classList.contains('flux')) {
- if (mutation.target.classList.contains('active')) {
- debugLog('Article became active via mutation');
- scrollToElement(mutation.target);
- }
- }
- });
- });
- // Start observing the document with the configured parameters
- observer.observe(document.body, {
- attributes: true,
- attributeFilter: ['class'],
- subtree: true
- });
- })();