ボタン一つでハートのツイートができます。
目前為
// ==UserScript==
// @name Favorite Tweet Buttons
// @namespace http://tampermonkey.net/
// @version 0.2.0
// @description ボタン一つでハートのツイートができます。
// @author TwoSquirrels
// @license MIT
// @match https://twitter.com/*
// @match https://x.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=x.com
// @grant none
// ==/UserScript==
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function favoriteTweet(favNum = 1) {
let symbolsButton, heartButton;
while (!(symbolsButton = document.querySelector("[aria-label='Symbols'], [aria-label='記号']"))) {
document.querySelector("[data-testid='ScrollSnap-List'] button[aria-haspopup='menu']").click();
await wait(50);
};
while (!(heartButton = document.querySelector("[aria-label='Red heart'], [aria-label='赤色のハート']"))) {
symbolsButton.click();
await wait(50);
};
for (let i = 0; i < favNum; i++) {
heartButton.click();
await wait(5);
}
document.querySelector("[data-testid='tweetButtonInline']").click();
}
const favButtons = document.createElement("div");
favButtons.id = "favorite-tweet";
for (const favNum of [1,2,3,4,5]) {
const button = document.createElement("button");
button.innerText = favNum;
button.onclick = () => favoriteTweet(favNum);
favButtons.append(button);
}
setInterval(() => {
if (document.querySelector("[data-testid='toolBar']")) {
if (!document.getElementById("favorite-tweet-inline")) {
document.querySelector("[data-testid='tweetButtonInline']").before(favButtons);
}
if (!document.getElementById("favorite-tweet-normal")) {
document.querySelector("[data-testid='tweetButton']").before(favButtons);
}
}
}, 50);