通过关键字模糊推文
效果:https://twitter.com/dao_leno/status/1673992286009720832?s=20
复制这段 JavaScript 代码到 Arc 浏览器 Boost -> Code -> JS 代码框
const keywords = ["keyword1", "keyword2", "keyword3"];
const observer = new MutationObserver(handleMutation);
let hoverTimeout;
const hoverDuration = 3000; // Customize the hover duration (in milliseconds)
const blurValue = "5px"; // Customize the blur value
observer.observe(document.documentElement, { childList: true, subtree: true });
function handleMutation(mutationsList) {
for (const mutation of mutationsList) {
if (mutation.type === "childList") {
mutation.addedNodes.forEach(addedNode => {
if (addedNode instanceof HTMLElement) {
const tweetTextElements = addedNode.querySelectorAll(
'[data-testid="tweet"]'
);
Array.from(tweetTextElements).forEach(element => {
keywords.forEach(keyword => {
if (element.textContent.includes(keyword)) {
element.style.filter = `blur(${blurValue})`;
element.addEventListener("mouseenter", handleMouseEnter);
element.addEventListener("mouseleave", handleMouseLeave);
}
});
});
}
});
}
}
}
function handleMouseEnter() {
const element = this;
hoverTimeout = setTimeout(() => {
element.style.filter = "none";
}, hoverDuration);
}
function handleMouseLeave() {
clearTimeout(hoverTimeout);
const element = this;
element.style.filter = `blur(${blurValue})`;
}
安装油猴插件
创建新脚本,复制粘贴以下内容并保存
// ==UserScript==
// @name Twitter Blur Keywords
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Blur tweets containing specified keywords on Twitter
// @author daoleno
// @match https://twitter.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const keywords = ["keyword1", "keyword2", "keyword3"];
const blurValue = "5px"; // Customize the blur value
const tweetContainerSelector = '[data-testid="tweet"]';
function handleMutation(mutation) {
const addedNodes = mutation.addedNodes;
for (const addedNode of addedNodes) {
if (addedNode instanceof HTMLElement) {
const tweetTextElements = addedNode.querySelectorAll(tweetContainerSelector);
Array.from(tweetTextElements).forEach(element => {
keywords.forEach(keyword => {
if (element.textContent.includes(keyword)) {
element.style.filter = `blur(${blurValue})`;
}
});
});
}
}
}
const observer = new MutationObserver(mutationsList => {
for (const mutation of mutationsList) {
if (mutation.type === "childList") {
handleMutation(mutation);
}
}
});
observer.observe(document.body, { childList: true, subtree: true });
})();
const keywords = ["keyword1", "keyword2", "keyword3"]; // Customize keywords
const hoverDuration = 3000; // Customize the hover duration (in milliseconds)
const blurValue = "5px"; // Customize the blur value