Alternate Case Text

Converts all text on a webpage to "a CaSe LiKe ThIs".

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Alternate Case Text
// @namespace    https://greasyfork.org
// @version      1.0
// @description  Converts all text on a webpage to "a CaSe LiKe ThIs".
// @author       LiyahMackenzie
// @license      MIT
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function toWeirdCase(text) {
        return text.split(" ").map(word =>
            word.split("").map((char, index) =>
                index % 2 === 0 ? char.toLowerCase() : char.toUpperCase()
            ).join("")
        ).join(" ");
    }

    function modifyTextNodes(node) {
        if (node.nodeType === Node.TEXT_NODE && node.nodeValue.trim().length > 0) {
            node.nodeValue = toWeirdCase(node.nodeValue);
        } else if (node.nodeType === Node.ELEMENT_NODE) {
            node.childNodes.forEach(modifyTextNodes);
        }
    }

    modifyTextNodes(document.body);
})();