X.com to Twitter.com Embedded Tweet in Voz

Replace x.com links with embedded tweets

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         X.com to Twitter.com Embedded Tweet in Voz
// @namespace    Embedded Tweet in Voz
// @version      2.1
// @description  Replace x.com links with embedded tweets
// @icon         https://www.google.com/s2/favicons?sz=64&domain=voz.vn
// @author       kylyte
// @match        https://voz.vn/t/*
// @match        https://voz.vn/conversations/*
// @match        https://voz.vn/whats-new/profile-posts/*
// @match        https://voz.vn/u/*
// @run-at       document-idle
// @license      GPL-3.0
// ==/UserScript==

(function() {
    'use strict';
    function addTwitterWidgetsScript() {
        if (!document.querySelector('script[src="//platform.twitter.com/widgets.js"]')) {
            const script = document.createElement('script');
            script.src = "//platform.twitter.com/widgets.js";
            script.charset = "utf-8";
            document.head.appendChild(script);
        }
    }
    function replaceDivWithBlockquote() {
        const divs = document.querySelectorAll('div.bbCodeBlock--unfurl');
        divs.forEach(div => {
            const anchor = div.querySelector('a[href^="https://x.com"]');
            if (anchor) {
                const href = anchor.getAttribute('href');
                const postIdMatch = href.match(/status\/(\d+)/);
                if (postIdMatch && postIdMatch[1]) {
                    const postId = postIdMatch[1];
                    const blockquote = document.createElement('blockquote');
                    blockquote.className = "twitter-tweet";
                    const link = document.createElement('a');
                    link.href = `https://twitter.com/twitterapi/status/${postId}`;
                    link.target = "_blank";
                    link.textContent = `https://twitter.com/twitterapi/status/${postId}`;
                    blockquote.appendChild(link);
                    div.parentNode.replaceChild(blockquote, div);
                    addTwitterWidgetsScript();
                }
            }
        });
    }

    window.addEventListener('load', replaceDivWithBlockquote);
    const observer = new MutationObserver(replaceDivWithBlockquote);
    observer.observe(document.body, { childList: true, subtree: true });
})();