1. Log in now to remove adverts - no adverts at all to registered members!

tweet fix

Discussion in 'General Chat' started by Benvenuto Cellini, Oct 9, 2025 at 3:44 AM.

  1. Benvenuto Cellini

    Benvenuto Cellini 1 of the top judges in Europe

    Joined:
    Jun 12, 2012
    Messages:
    44,604
    Likes Received:
    59,708
    got fed up having to manually change x to twitter so got some AI slop to fix it because brb wont

    all it does is change the url from x to twitter when you paste it in the media popup or if you just paste the tweet url in the comment box it will change to this sites format



    install violentmonkey addon

    add this script

    Code:
    // ==UserScript==
    // @name		fix tweet
    // @match	   *://not606.com/*
    // @grant	   none
    // @version	 1.5
    // ==/UserScript==
    (async () => {
    	"use strict";
    
    	function attachListener(input) {
    		if (input.dataset.vmBound) return;
    		input.dataset.vmBound = "1";
    		input.addEventListener("input", () => {
    			if (input.value.includes("//x.com/")) {
    				input.value = input.value.replace("//x.com/", "//twitter.com/");
    			}
    		});
    		console.log("Listener attached to #redactor_media_link input");
    	}
    
    	function attachIframeListener(iframe) {
    		if (iframe.dataset.vmBound) return;
    		iframe.dataset.vmBound = "1";
    
    		const onLoad = () => {
    			const doc = iframe.contentDocument || iframe.contentWindow.document;
    			if (!doc) {
    				console.warn("Could not access iframe document");
    				return;
    			}
    
    			const editor =
    				doc.querySelector('[contenteditable="true"]') ||
    				doc.querySelector(".redactor_textCtrl") ||
    				doc.querySelector(".redactor_MessageEditor") ||
    				doc.querySelector(".redactor_BbCodeWysiwygEditor") ||
    				doc.querySelector("textarea") ||
    				doc.querySelector('div[class*="redactor"]') ||
    				doc.body;
    
    			if (!editor) {
    				console.warn("Could not find editor element in iframe");
    				console.log(
    					"Available elements:",
    					doc.body.innerHTML.substring(0, 500),
    				);
    				return;
    			}
    
    			const tweetRegex =
    				/https?:\/\/(?:www\.)?(?:x|twitter)\.com\/[^/]+\/status\/(\d+)/;
    
    			const handlePaste = (e) => {
    				const pasted = (
    					e.clipboardData || window.clipboardData
    				).getData("text");
    
    				const match = pasted.match(tweetRegex);
    				if (!match) {
    					console.log("No tweet URL found in paste");
    					return;
    				}
    
    				e.preventDefault();
    				e.stopPropagation();
    
    				const id = match[1];
    				const tag = `[MEDIA=twitter]${id}[/MEDIA]`;
    
    				if (editor.tagName === "TEXTAREA") {
    					const start = editor.selectionStart;
    					const end = editor.selectionEnd;
    					const text = editor.value;
    					editor.value =
    						text.substring(0, start) + tag + text.substring(end);
    					editor.selectionStart = editor.selectionEnd =
    						start + tag.length;
    				} else if (
    					editor.isContentEditable ||
    					editor.contentEditable === "true"
    				) {
    					const selection = doc.getSelection();
    
    					if (selection.rangeCount > 0) {
    						const range = selection.getRangeAt(0);
    						range.deleteContents();
    
    						const textNode = doc.createTextNode(tag);
    						range.insertNode(textNode);
    
    						range.setStartAfter(textNode);
    						range.setEndAfter(textNode);
    						selection.removeAllRanges();
    						selection.addRange(range);
    					} else {
    						editor.innerHTML += tag;
    					}
    				} else {
    					editor.textContent += tag;
    				}
    
    				editor.dispatchEvent(new Event("input", { bubbles: true }));
    				editor.dispatchEvent(new Event("change", { bubbles: true }));
    
    				console.log("Replaced tweet URL →", tag);
    			};
    
    			editor.addEventListener("paste", handlePaste);
    
    			console.log("Iframe paste listener attached to:", editor.tagName);
    		};
    
    		if (iframe.contentDocument?.readyState === "complete") {
    			onLoad();
    		} else {
    			iframe.addEventListener("load", onLoad, { once: true });
    		}
    	}
    
    	const existingInput = document.getElementById("redactor_media_link");
    	if (existingInput) attachListener(existingInput);
    
    	const existingIframe = document.querySelector(
    		"iframe.redactor_BbCodeWysiwygEditor",
    	);
    	if (existingIframe) attachIframeListener(existingIframe);
    
    	const observer = new MutationObserver((mutations) => {
    		for (const m of mutations) {
    			for (const node of m.addedNodes) {
    				if (node.nodeType !== 1) continue;
    
    				if (node.id === "redactor_media_link") {
    					attachListener(node);
    				} else {
    					const el = node.querySelector?.("#redactor_media_link");
    					if (el) attachListener(el);
    				}
    
    				if (
    					node.tagName === "IFRAME" &&
    					(node.classList.contains("redactor_BbCodeWysiwygEditor") ||
    						node.classList.contains("redactor_MessageEditor") ||
    						node.classList.contains("redactor_textCtrl"))
    				) {
    					attachIframeListener(node);
    				} else {
    					const iframe = node.querySelector?.(
    						'iframe[class*="redactor"]',
    					);
    					if (iframe) attachIframeListener(iframe);
    				}
    			}
    		}
    	});
    
    	observer.observe(document.body, { childList: true, subtree: true });
    })();
    
     
    #1

Share This Page