Greasy Fork is available in English.
Automatically clicks the "Translate post" button on X.com posts if available
当前为
// ==UserScript==
// @name Auto-Translate Posts on X/Twitter
// @version 1.0
// @description Automatically clicks the "Translate post" button on X.com posts if available
// @author https://github.com/ruukulada
// @namespace https://github.com/ruukulada
// @match https://*.x.com/*
// @license MIT
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Function to find and click the "Translate post" button
const clickTranslateButton = () => {
// Look for a <button> containing a <span> with text "Translate post"
const translateButton = Array.from(document.querySelectorAll('button span'))
.find(el => el.textContent.trim() === "Translate post");
if (translateButton) {
// Click the parent <button>
const button = translateButton.closest('button');
if (button) {
button.click();
console.log("Clicked 'Translate post' button.");
}
}
};
// Monitor for changes on the page to detect new posts
const observer = new MutationObserver((mutations) => {
for (let mutation of mutations) {
if (mutation.addedNodes.length > 0) {
clickTranslateButton();
}
}
});
// Start observing the body of the document
observer.observe(document.body, { childList: true, subtree: true });
// Initial check in case the button is already present
clickTranslateButton();
})();