Insert 0-width into Tweet

Prevent your tweet from searching

Version vom 26.09.2021. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Insert 0-width into Tweet
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Prevent your tweet from searching
// @author       eggplants
// @homepage     https://github.com/eggplants
// @match        https://twitter.com/compose/tweet
// @grant        none
// ==/UserScript==

/*jshint esversion: 8 */

function rafAsync() {
    return new Promise(resolve => {
        requestAnimationFrame(resolve);
    });
}

async function checkElement(selector) {
    let q = null;
    while (q === null) {
        await rafAsync();
        q = document.querySelector(selector);
    }
    return q;
}

window.onload = function () {
    "use strict";
    let btn = document.createElement("button");
    btn.innerHTML = "Insert 0-width space";
    btn.onclick = function () {
        let elms = Array.from(
            document.querySelectorAll('span[data-text="true"],br[data-text="true"]')
        );
        if (elms.length === 0) {
            // do nothing
        } else if (elms[elms.length-1].tagName !== "BR") {
            alert(
                "Put a new line at the end of your tweet!"
            );
        } else {
            elms.forEach((e) => {
                e.innerText = e.innerText
                    .replaceAll("​", "")
                    .replaceAll(/(.)/g, "$1​");
            });
            console.log("inserted!");
        }
    };
    const qs =
        "div.css-1dbjc4n.r-1iusvr4.r-16y2uox.r-1777fci" +
        ".r-1h8ys4a.r-1bylmt5.r-13tjlyg.r-7qyjyx.r-1ftll1t" +
        "> div:nth-child(3) > div > div > div:nth-child(1)";
    checkElement(qs).then((e) => {
        console.info(e);
        e.appendChild(btn);
    });
    console.log("loaded!");
};