Greasy Fork is available in English.
点击链接变暗并添加波浪线,标记会保存直到标签页关闭
当前为
// ==UserScript==
// @name 标记已点击链接(会话版)
// @description 点击链接变暗并添加波浪线,标记会保存直到标签页关闭
// @version 3.0
// @author WJ
// @match *://*/*
// @license MIT
// @grant none
// @namespace http://greasyfork.icu/users/914996
// ==/UserScript==
(function() {
'use strict';
const marked = JSON.parse(sessionStorage.xMarkedLinks || '{}');
// 标记单个链接
const mark = a => {
a.style.cssText = 'opacity:0.5; text-decoration:underline wavy #00CED1';
};
// 初始化标记
const init = () => {
Object.keys(marked).forEach(url => {
document.querySelectorAll(`a[href="${url}"]`).forEach(mark);
});
};
// 监听页面变化
new MutationObserver(init).observe(document, {
childList: true,
subtree: true
});
// 初始化
document.addEventListener('DOMContentLoaded', init);
// 点击处理
document.addEventListener('click', e => {
const a = e.target.closest('a[href]');
if (!a || marked[a.href]) return;
// 排除导航区域(添加3.0版本的全部排除区域)
if (!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"]
`)) {
marked[a.href] = true;
sessionStorage.xMarkedLinks = JSON.stringify(marked);
document.querySelectorAll(`a[href="${a.href}"]`).forEach(mark);
}
}, true);
})();