标记已点击链接

点击链接变暗并加波浪线,标记持续到标签页关闭

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         标记已点击链接
// @description  点击链接变暗并加波浪线,标记持续到标签页关闭
// @version      1.0
// @author       WJ
// @match        *://*/*
// @license      MIT
// @grant        none
// @run-at       document-body
// @namespace https://greasyfork.org/users/914996
// ==/UserScript==

(() => {
  'use strict';

  // 样式:变暗+波浪线
  const sheet = new CSSStyleSheet();
  sheet.replaceSync('a.x-marked{opacity:.7!important;text-decoration:underline wavy #0ce!important}');
  document.adoptedStyleSheets.push(sheet);

  // 读取已标记
  const marked = new Set(JSON.parse(sessionStorage.xMarked || '[]'));

  // 标记链接的函数
  const mark = a => a.classList.toggle('x-marked', marked.has(a.href));

  // 首次全扫
  document.body.querySelectorAll('a[href]').forEach(mark);

  // 监听新节点
  new MutationObserver(muts => muts.forEach(m => m.addedNodes.forEach(n =>
    n.nodeType === 1 && (n.tagName === 'A' ? mark(n)
      : n.querySelectorAll?.('a[href]').forEach(mark))
  ))).observe(document.body, {childList: true, subtree: true});

  // 点击记录
  document.addEventListener('click', e => {
    const a = e.target.closest('a[href]');
    if (a && !a.closest(`
      nav,footer,aside,
      .btn,.nav,.navbar,.navigation,.menu,.menubar,
      .breadcrumb,.pagination,.tabs,.tabbar,.sidebar,.footer,
      [role="navigation"],[role="menu"],[role="tablist"],[role="banner"]`)){
    marked.add(a.href);
    sessionStorage.xMarked = JSON.stringify([...marked]);
    a.classList.add('x-marked')}
  }, true);
})();