Last active
January 20, 2024 06:51
-
-
Save picasso250/8c9f1d1275a8760c90c3d426ca31ec0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name lowlightRecommended-twitter | |
// @namespace Violentmonkey Scripts | |
// @match https://twitter.com/* | |
// @grant none | |
// @version 1.0 | |
// @author - | |
// @description 2024/1/18 14:45:09 | |
// ==/UserScript== | |
function applyStyles() { | |
// 获取所有的 span 元素 | |
const allSpans = document.querySelectorAll('span'); | |
// 遍历每个 span 元素 | |
allSpans.forEach(span => { | |
// 检查 span 的文本内容是否为 "推荐" 或者以 "由 XXX 推广" 结尾 | |
if ( | |
span.textContent.trim() === '推荐' || | |
/^由 .+ 推广$/.test(span.textContent.trim())) { | |
// 获取最近的父级 article 元素 | |
const parentArticle = span.closest('article'); | |
// 检查是否找到了父级 article 元素 | |
if (parentArticle) { | |
parentArticle.style.opacity = '0.5'; | |
} | |
} | |
}); | |
} | |
// 每隔1秒执行applyStyles函数 | |
setInterval(applyStyles, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个方式确实太暴力了, 个人感觉性能不好, 可以参考下面的监听模式