Greasy Fork

Greasy Fork is available in English.

标记已点击链接(会话版)

点击链接变暗并添加波浪线,标记会保存直到标签页关闭

当前为 2025-07-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         标记已点击链接(会话版)
// @description  点击链接变暗并添加波浪线,标记会保存直到标签页关闭
// @version      3.1
// @author       WJ
// @match        *://*/*
// @license      MIT
// @grant        none
// @namespace http://greasyfork.icu/users/914996
// ==/UserScript==

(function() {
    'use strict';
    
    // 注入强制样式(核心修改)
    const style = document.createElement('style');
    style.textContent = 'a.x-marked{opacity:0.5!important;text-decoration:underline wavy #00CED1!important}';
    document.head.appendChild(style);
    
    const marked = JSON.parse(sessionStorage.xMarkedLinks || '{}');
    
    // 简化标记函数
    const mark = a => a.classList.add('x-marked');
    
    // 精简初始化
    const init = () => {
        document.querySelectorAll('a[href]').forEach(a => {
            if (marked[a.href]) mark(a);
        });
    };
    
    // 基本DOM监听
    new MutationObserver(init).observe(document, {
        childList: true,
        subtree: true
    });
    
    // 精简点击处理
    document.addEventListener('click', e => {
        const a = e.target.closest('a[href]');
        if (!a || a.closest('nav,.nav,.navbar,.navigation,.menu,.menubar,.breadcrumb,header,.header,footer,.footer,.pagination,.tabs,.tabbar,.sidebar,.aside,#sidebar,#aside,[role="navigation"],[role="menu"],[role="tablist"],[role="banner"]')) return;
        
        marked[a.href] = true;
        sessionStorage.xMarkedLinks = JSON.stringify(marked);
        mark(a);
    }, true);
    
    // 启动初始化
    if (document.readyState === 'complete') init();
    else document.addEventListener('DOMContentLoaded', init);
})();