Mods I know yall are “busy” but Twitter ➡️ “X” embeds gotta start working

Status
Not open for further replies.

bnew

Veteran
Joined
Nov 1, 2015
Messages
51,004
Reputation
7,865
Daps
147,240
use a word replacer browser extension until they upgrade.
 

bnew

Veteran
Joined
Nov 1, 2015
Messages
51,004
Reputation
7,865
Daps
147,240
used bing chat to create a userscript that replaces and occurrence of https://x.com or https://www.x.com with https://twitter.com.
it'll only replace the text in the input field on thecoli when bbcode is enabled.

0WhpwKl.gif

i was doing ctrl-v https://twitter.com/PBS/status/1642240482813042688 and as you can see it automatically changed to twitter.com.
if you have a x.com link in html mode editor and switch to bbcode editor, the url won't change immediately, you'll have to press space, type something or hit ENTER inside the field for it to change. theres a small annoying cursor position issue i couldn't get rid of without causing other bugs.

edit:
Toggle the "BB code" button and then the buttons to the left should turn grey.
1gNRnIE.png

Code:
// ==UserScript==
// @name Replace X.com URLs with Twitter.com URLs
// @namespace    http://tampermonkey.net/
// @description Replaces URLs containing "https://twitter.com" or "https://twitter.com" with "https://twitter.com".
// @author Author Name
// @version 1.0
// @match        https://www.thecoli.com/threads/*
// @match        https://thecoli.com/threads/*
// @match        https://xenforo.com/community/forums/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to get the current cursor position in a text input field
    function getCursorPosition(input) {
        let position = 0;
        if ('selectionStart' in input) {
            position = input.selectionStart;
        } else if (document.selection) {
            input.focus();
            let selection = document.selection.createRange();
            selection.moveStart('character', -input.value.length);
            position = selection.text.length;
        }
        return position;
    }

    // Function to set the cursor position in a text input field
    function setCursorPosition(input, position) {
        if (input.setSelectionRange) {
            input.focus();
            input.setSelectionRange(position, position);
        } else if (input.createTextRange) {
            let range = input.createTextRange();
            range.collapse(true);
            range.moveEnd('character', position);
            range.moveStart('character', position);
            range.select();
        }
    }

// Function to replace URLs in text input fields
function replaceURLs(event) {
    // Get all editable fields on the page
    let editableFields = document.querySelectorAll('[contenteditable="true"], .fr-element.fr-view.fr-element-scroll-visible');

    // Get the target element of the event
    let target = event.target;

    // Check if the target is a text input field or an editable field
    if (target.matches('textarea.input') || editableFields.includes(target)) {
            // Save the current cursor position
            let cursorPosition = getCursorPosition(target);

            // Replace URLs in the value or innerHTML of the target element
            let lines = target.value ? target.value.split('\n') : target.innerHTML.split('\n');
            for (let i = 0; i < lines.length; i++) {
                lines[i] = lines[i].replace(/https:\/\/(www\.)?x\.com/g, 'https://twitter.com');
                if (i === cursorPosition.line) {
                    cursorPosition.column = lines[i].length;
                }
            }
            target.value ? target.value = lines.join('\n') : target.innerHTML = lines.join('\n');

            // Restore the cursor position
            setCursorPosition(target, cursorPosition);
        }
    }

    // Function to prevent cursor movement by arrow keys
//    function preventCursorMovement(event) {
        // Check if the key pressed is left or right arrow
//        if (event.keyCode == 37 || event.keyCode == 39) {
            // Prevent the default behavior of the key
            event.preventDefault();
//        }
//    }

    // Add event listeners for input and keydown events on the document
    document.addEventListener('input', replaceURLs);
//    document.addEventListener('keydown', preventCursorMovement);
})();





A,I generated instructions:
Here are the step-by-step instructions to add the userscript to Chrome or Firefox:
For Chrome:

  1. Install the Tampermonkey extension from the Chrome Web Store.
  2. Once Tampermonkey is installed, click on the Tampermonkey icon in the toolbar and select “Create a new script…”
  3. Paste your userscript into the editor and save it.
  4. The userscript should now be installed and will run whenever you visit a page that matches its @match or @include rules.
For Firefox:

  1. Install the Greasemonkey or Tampermonkey extension from the Firefox Add-ons site.
  2. Once Greasemonkey or Tampermonkey is installed, click on the Greasemonkey or Tampermonkey icon in the toolbar and select “Add a new script…”
  3. Paste your userscript into the editor and save it.
  4. The userscript should now be installed and will run whenever you visit a page that matches its @match or @include rules.

you can also use the userscript on android with firefox or kiwi browser.
 
Last edited:
Status
Not open for further replies.
Top