有些大博客大量内容就几十个字,或者贴段代码自嗨。
不想被这些数据源刷屏,所以写了这个脚本。应该,也许,没有大问题吧?
// ==UserScript==
// @name vxna_blacklist
// @namespace http://tampermonkey.net/
// @version 2024-06-20
// @description try to take over the world!
// @author You
// @match https://v2ex.com/xna*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
const vxna_blacklist = JSON.parse(localStorage.getItem("vxna_blacklist")) || [];
let init = false;
const handle = () => {
document
.querySelectorAll(".xna-entry.cell .xna-entry-source .node")
.forEach((el) => {
if (vxna_blacklist.includes(el.text)) {
el.closest(".xna-entry.cell").style.display = "none";
} else {
if (init) return;
const fragment = document.createDocumentFragment();
const span1 = document.createElement("span");
const span2 = document.createElement("span");
span1.className = "fade";
span2.className = "fade black";
span1.innerHTML = " • ";
span2.innerHTML = " 屏蔽 ";
span2.setAttribute("data-name", el.text);
fragment.appendChild(span1);
fragment.appendChild(span2);
el.closest("div").appendChild(fragment);
}
});
init = true;
};
handle();
document.querySelector("#Main>.box").addEventListener("click", (e) => {
const target = e.target;
if (!target) return;
if (target.className === "fade black") {
vxna_blacklist.unshift(target.getAttribute("data-name"));
localStorage.setItem("vxna_blacklist", JSON.stringify(vxna_blacklist));
handle();
}
});
})();
1
InDom 186 天前 1
虽然名字也不会变,但是屏蔽规则记录 href 比 text 更可靠吧?
|
4
maladaxia 185 天前
使用官方的这个存储接口, tampermonkey 自带存储界面, 省事不少
|
6
Livid MOD 比如哪个源会需要用到这个功能?
|