Favorite Tweet Buttons

ボタン一つでハートのツイートができます。

目前為 2024-05-28 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Favorite Tweet Buttons
// @namespace    http://tampermonkey.net/
// @version      0.2.1
// @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(tweetButton, 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);
  }
  tweetButton.click();
}

setInterval(() => {
  for (const tweetButtonId of ["tweetButton", "tweetButtonInline"]) {
    const favButtons = document.createElement("div");
    favButtons.id = "favorite_tweet-" + tweetButtonId;
    if (document.getElementById(favButtons.id)) continue;
    const tweetButton = document.querySelector(`[data-testid=${JSON.stringify(tweetButtonId)}]`);
    if (!tweetButton || tweetButton.parentNode.parentNode.dataset.testid !== "toolBar") continue;
    for (const favNum of [1,2,3,4,5]) {
      const button = document.createElement("button");
      button.innerText = favNum;
      button.onclick = () => favoriteTweet(tweetButton, favNum);
      favButtons.append(button);
    }
    tweetButton?.before(favButtons);
  }
}, 50);