Emoji Tweet Buttons

ボタン一つで絵文字ツイートができます。

目前为 2024-05-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         Emoji Tweet Buttons
// @namespace    http://tampermonkey.net/
// @version      0.3.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==

// 指定したミリ秒待つ Promise 関数
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

// 絵文字設定
const emojis = [
  { category: ["Symbols", "記号"], names: ["Red heart", "赤色のハート"], label: "❤️" },
  { category: ["Smileys & people", "人と表情"], names: ["Eyes", { text: "目", index: 1 }], label: "👀" },
  { category: ["Smileys & people", "人と表情"], names: ["Loudly crying face", "号泣"], label: "😭" },
  { category: ["Smileys & people", "人と表情"], names: ["Pensive face", "悲しげな顔"], label: "😔" },
  { category: ["Smileys & people", "人と表情"], names: ["Person facepalming", "手のひらを顔に当てる人"], label: "🤦" },
];

// 絵文字をツイートする async 関数
async function tweetEmoji(tweetButton, category = ["Symbols", "記号"], names = ["Red heart", "赤色のハート"]) {
  let symbolsButton, emojiButton;
  while (!(symbolsButton = document.querySelector(category.map((name) => `[aria-label=${JSON.stringify(name)}]`).join(", ")))) {
    document.querySelector("[data-testid='ScrollSnap-List'] button[aria-haspopup='menu']").click();
    await wait(50);
  }
  while (
    !(emojiButton = (() => {
      for (const name of names) {
        const button = document.querySelectorAll(`[aria-label=${JSON.stringify(name.text ?? name)}]`)[name.index ?? 0];
        if (button) return button;
      }
    })())
  ) {
    symbolsButton.click();
    await wait(50);
  }
  console.log(emojiButton);
  emojiButton.click();
  await wait(5);
  tweetButton.click();
}

setInterval(() => {
  // 二種類のツイートボタンに対応
  for (const tweetButtonId of ["tweetButton", "tweetButtonInline"]) {
    const emojiButtons = document.createElement("div");
    emojiButtons.id = "emoji_tweet-" + tweetButtonId;
    if (document.getElementById(emojiButtons.id)) continue;
    const tweetButton = document.querySelector(`[data-testid=${JSON.stringify(tweetButtonId)}]`);
    if (!tweetButton || tweetButton.parentNode.parentNode.dataset.testid !== "toolBar") continue;

    // それぞれの絵文字ボタンを作る
    for (const { category, names, label } of emojis) {
      const button = document.createElement("button");
      button.innerText = label;
      button.onclick = () => tweetEmoji(tweetButton, category, names);
      emojiButtons.append(button);
    }

    tweetButton.before(emojiButtons);
  }
}, 50);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址