Skip to content

Instantly share code, notes, and snippets.

@Narazaka
Created January 16, 2024 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Narazaka/cba836fe086546d6da8b1d6f64288cc2 to your computer and use it in GitHub Desktop.
Save Narazaka/cba836fe086546d6da8b1d6f64288cc2 to your computer and use it in GitHub Desktop.
// @ts-check
setInterval(() => {
const tweets = document.querySelectorAll('article[data-testid="tweet"]');
for (let i = 0; i < tweets.length; i++) {
const tweet = tweets[i];
if(tweet.querySelector('.spam-button') != null){
// 追加済ならスキップ
continue;
}
// スパムボタンの親要素を取得
const spamButtonDom = tweet.querySelector('div > div > div:nth-child(2) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1)> div:nth-child(1)');//> div:nth-child(1) > div
// 詳細ボタンを取得
const showMenuButton = tweet.querySelector('div[data-testid="caret"]');
addSpamButton(spamButtonDom, showMenuButton);
}
const userCells = document.querySelectorAll('[data-testid="UserCell"]');
for (let i = 0; i < userCells.length; i++) {
const tweet = userCells[i];
if(tweet.querySelector('.spam-button') != null){
// 追加済ならスキップ
continue;
}
// スパムボタンの親要素を取得
const spamButtonDom = tweet.querySelector('div > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)> div:nth-child(1) > a > div');//> div:nth-child(1) > div
// 詳細ボタンを取得
const showMenuButton = tweet.querySelector('[aria-haspopup="menu"]');
addSpamButton(spamButtonDom, showMenuButton);
}
function addSpamButton(spamButtonDom, showMenuButton) {
// 新しいボタン要素を作成
// スパム報告ボタン
let spamButton = document.createElement('button');
spamButton.textContent = '🚨スパム';
spamButton.className = 'spam-button';
spamButton.style = ' background-color:#444; color: #ccc; border-radius: 5px; border: none; padding: 0px 5px 0px 5px; margin: 0px 5px; cursor:pointer;white-space: nowrap; ';// background-color: #ff0000;
// 暴力報告ボタン
let violenceButton = document.createElement('button');
violenceButton.textContent = '🔪暴力';
violenceButton.className = 'spam-button-violence';
violenceButton.style = ' background-color:#444; color: #ccc; border-radius: 5px; border: none; padding: 0px 5px; margin: 0px 1px; cursor:pointer;white-space: nowrap; ';// background-color: #ff0000;
const execMuteSpamBlock = (mode) => {
// ツイートメニューを表示
console.log("show post menu");
const clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
showMenuButton.dispatchEvent(clickEvent);
// // ポストを報告をクリック
console.log("click report button");
console.log(Array.from(document.querySelectorAll('[data-testid="Dropdown"] > [role="menuitem"]')))
const reportButton = document.querySelector('div[data-testid="report"]');
//console.log(reportButton);
reportButton.dispatchEvent(clickEvent);
// フェーズ1:スパム報告
setTimeout(() => {
const modeName = mode == 'spam' ? 'スパム' : '暴力的な発言';
console.log(`click ${modeName} button`);
let idx = mode == 'spam' ? 6 : 3;
const reportLabel1 = document.querySelector(`div[role="radiogroup"] > div > label:nth-child(${idx})`);
const reportClick1 = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
reportLabel1.dispatchEvent(reportClick1);
// 次へ
const nextButton = document.querySelector('div[data-testid="ChoiceSelectionNextButton"]');
nextButton.dispatchEvent(reportClick1);
setTimeout(() => {
if(mode == 'violence'){
// フェーズ2:暴力の賛美
console.log("click 暴力の賛美 button");
const reportLabel2 = document.querySelector('div[role="radiogroup"] > div > label:nth-child(2)');
const reportClick2 = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
reportLabel2.dispatchEvent(reportClick2);
// 次へ
const nextButton = document.querySelector('div[data-testid="ChoiceSelectionNextButton"]');
nextButton.dispatchEvent(reportClick2);
}
setTimeout(()=>{
// フェーズ3:ミュート
console.log("click mute button");
const muteButtonParent = document.querySelector(' div[role="group"] > div:nth-child(2) > div:nth-child(1) > div > div:nth-child(2) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)');
const muteButton = muteButtonParent.querySelectorAll('div[role="button"]');
const muteClick = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
muteButton[0].dispatchEvent(muteClick);
setTimeout(()=>{
// フェーズ4:ブロック
console.log("click block button");
// ツイートメニューを表示
const clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
showMenuButton.dispatchEvent(clickEvent);
const reportButton = document.querySelector('div[data-testid="block"]');
reportButton.dispatchEvent(clickEvent);
setTimeout(() => {
const blockButton = document.querySelector('div[data-testid="confirmationSheetConfirm"]');
const clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
blockButton.dispatchEvent(clickEvent);
}, 250);
},250);
},250);
}, 250);
}, 1000);
};
spamButton.addEventListener('click', function(e) {
e.preventDefault();
execMuteSpamBlock('spam');
});
violenceButton.addEventListener('click', function(e) {
e.preventDefault();
execMuteSpamBlock('violence');
});
let allContainer = document.createElement("div");
allContainer.style.display = "flex";
allContainer.style.flexDirection = "row";
allContainer.style.justifyContent = "start";
let container = document.createElement("div");
container.style.display = "none";
let showButton = document.createElement("button");
showButton.textContent = '❗報告';
showButton.style = ' background-color:#ccc; color: #333; border-radius: 5px; border: none; padding: 0px 5px; margin: 0px 1px; cursor:pointer;white-space: nowrap; ';// background-color: #ff0000;
showButton.addEventListener("click", (e) => {
e.preventDefault();
container.style.display = container.style.display === "none" ? "" : "none";
})
container.appendChild(spamButton);
container.appendChild(violenceButton);
allContainer.appendChild(showButton);
allContainer.appendChild(container);
spamButtonDom.appendChild(allContainer);
}
}, 2000);// 2秒に1回実行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment