Skip to content

Instantly share code, notes, and snippets.

@weijarz
Last active July 4, 2023 02:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weijarz/439a48717c10dd790cdb793c4f47ff4d to your computer and use it in GitHub Desktop.
Save weijarz/439a48717c10dd790cdb793c4f47ff4d to your computer and use it in GitHub Desktop.
Mute twitter user with one click 按住 alt 键点击推文一键 mute 用户
// ==UserScript==
// @name One click to mute the twitter user - twitter.com
// @namespace Violentmonkey Scripts
// @match https://twitter.com/*
// @grant none
// @version 1.0
// @author weijarz
// @description 6/28/2023, 12:46:22 PM
// ==/UserScript==
document.addEventListener('click', (ev) => {
if (!(ev.altKey || ev.button === 1)) return;
const article = ev.target.closest('article');
if (!article) return;
const btnArr = article.querySelectorAll('div[aria-haspopup="menu"][role="button"][data-testid="caret"]');
if (btnArr.length !== 1) return;
ev.stopPropagation();
ev.preventDefault();
setTimeout(() => {
btnArr[0].click();
setTimeout(() => {
const menuArr = document.querySelectorAll('div[data-testid="Dropdown"]');
if (menuArr.length !== 1) return
for (const mi of menuArr[0].querySelectorAll('div[role="menuitem"]')) {
console.log('MenuItem', mi.innerText);
if (/^(隐藏|Mute)\s@/u.test(mi.innerText)) {
console.log('Fuck', mi.innerText);
mi.click();
break;
}
}
}, 200);
}, 10);
}, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment