Replace x with xcancel

Hacky solution to replace all x.com links with xcancel.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Replace x with xcancel
// @namespace    http://tampermonkey.net/
// @version      2026-01-11
// @description  Hacky solution to replace all x.com links with xcancel.
// @author       For You
// @match        https://www.destiny.gg/bigscreen
// @icon         https://www.google.com/s2/favicons?sz=64&domain=destiny.gg
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  "use strict";

  const ORIGINAL_DOMAIN = "x.com";
  const REPLACEMENT_DOMAIN = "xcancel.com";

  const observer = new MutationObserver((mutations) => {
    for (const mutation of mutations) {
      for (const node of mutation.addedNodes) {
        if (node.querySelector) {
          const link = node.querySelector(".text a");
          replaceLink(link);
        }
      }
    }
  });

  function replaceLink(element) {
    if (!element?.innerText) return;

    element.innerText = element.innerText.replaceAll(ORIGINAL_DOMAIN, REPLACEMENT_DOMAIN);

    const href = element.getAttribute("href");
    if (href) {
      element.setAttribute("href", href.replace(ORIGINAL_DOMAIN, REPLACEMENT_DOMAIN));
    }
  }

  function register() {
    const chatFrame = document.querySelector("#chat-wrap > iframe");
    const chatDoc = chatFrame?.contentDocument;
    const chat = chatDoc?.querySelector("#chat");

    if (!chat) {
      // Dog ass loop to register the observer
      setTimeout(register, 1000);
      return;
    }

    chatDoc.querySelectorAll(".text a").forEach(replaceLink);

    observer.observe(chat, {
      subtree: true,
      childList: true,
    });
  }

  register();
})();