Greasy Fork is available in English.

Add quote-tweet links

Add a quote-tweet link

// ==UserScript==
// @name         Add quote-tweet links
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  Add a quote-tweet link
// @author       Noah Peterson
// @match        https://x.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=twitter.com
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

let hasRun = false;

function addQuoteLink() {
    let anchors = document.getElementsByTagName("a");

    for (let i = 0; i < anchors.length; i++) {
        for (let j = 0; j < anchors[i].childNodes.length; j++) {
            if (anchors[i].childNodes[j].tagName == "TIME") {
                let user = anchors[i].href.substring(anchors[i].href.indexOf(".com/")+5);
                user = user.substring(0, user.indexOf("/"));
                if (window.location.href.match(user)) {
                    let new_elem = document.createElement("a");
                    new_elem.textContent = " (Quotes) ";
                    new_elem.href = document.URL + "/quotes";
                    new_elem.style.color = "rgb(231, 233, 234)"
                    new_elem.style.textDecoration = "none"
                    anchors[i].parentElement.insertBefore(new_elem, anchors[i].nextSibling);
                    hasRun = true;
                    break;
                }
            }
        }
        if (hasRun) {
            break;
        }
    }
}

let previousURL = undefined;

setInterval(() => {
    const currentUrl = window.location.href;
    if (currentUrl != previousURL) {
        previousURL = currentUrl;
        hasRun = false;
    }
    if (!hasRun && currentUrl.match("status") != null) {
        addQuoteLink();
    }
}, 100);