Skip to content

Instantly share code, notes, and snippets.

@yutopp
Last active March 27, 2023 13:55
Show Gist options
  • Save yutopp/0186d786174cd2e2a3aae57aaae0e889 to your computer and use it in GitHub Desktop.
Save yutopp/0186d786174cd2e2a3aae57aaae0e889 to your computer and use it in GitHub Desktop.
// twitter webでツイートを削除するスクリプト
// 2023/3/27時点のtwitterのUIに対応しています。
//
// 自分のプロフィールページを開いた状態でブラウザのConsoleから以下のスクリプトを実行することで、自身のツイートを削除します。
// (挙動を理解してから実行することをおすすめします。スクリプトの作成者は、実行によって生じたいかなる損害に対しても責任を負いません。)
//
let waitForElement = (selector) => {
return new Promise((resolve, reject) => {
const element = document.querySelector(selector);
if (element) {
resolve(element);
}
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const nodes = Array.from(mutation.addedNodes);
for (const node of nodes) {
if (!(node instanceof HTMLElement)) {
continue;
}
if (node.matches(selector)) {
observer.disconnect();
resolve(node);
} else {
const el = node.querySelector(selector);
if (el) {
observer.disconnect();
resolve(el);
}
}
}
});
});
observer.observe(document.documentElement, { childList: true, subtree: true });
});
}
let deleteTweets = async () => {
const elements = document.querySelectorAll('[data-testid=cellInnerDiv]');
for (let elem of elements) {
const more = elem.querySelector('[aria-haspopup="menu"]');
if (more == null) {
continue;
}
more.click();
const dropdown = await waitForElement('[data-testid=Dropdown]');
const d = dropdown.childNodes[0];
if (d.innerText != "Delete") {
continue;
}
d.click();
const deleteBtn = await waitForElement('[data-testid=confirmationSheetConfirm]');
deleteBtn.click();
}
};
// 以下を満足行くまでたたく
deleteTweets();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment