Skribbl RTL

Fixes the way skribbl.io displays hebrew words.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         Skribbl RTL
// @author       Mx2
// @version      0.0.2
// @description  Fixes the way skribbl.io displays hebrew words.
// @author       You
// @include      https://skribbl.io/*
// @grant        GM_log
// @website      https://github.com/maormagori/Skribbl-RTL
// @namespace https://greasyfork.org/users/690432
// ==/UserScript==

GM_log("skribbl RTL has started.");

//Fetching the current word node
const currentWordNode = document.getElementById("currentWord");

//The observer config
const config = { characterData: true, childList: true};

//The observer's callback. called each time the inner html of current word changes.
const whenWordChanges = () =>{
    //The chagnged word.
    let word = currentWordNode.innerHTML;

    //Checking if it contains rtl characters. Atm skribbl only has one rtl language which is hebrew.
    if (containsHebrew(word)){
        // If the word contains hebrew characters we change it's direction to rtl.
        currentWordNode.style.direction = "rtl";
    }
    //If the word does not contain rtl characters and the current direction is rtl we change it back to ltr.
    else if(currentWordNode.style.direction === "rtl"){
        currentWordNode.style.direction = "ltr";
    }
}

//Runs a regex test on word and checks if it contains any unicode symbols from hebrew.
const containsHebrew = (word) => {
    return ((/[\u0590-\u05FF]/).test(word));
}

//Initializing the observer.
const observer = new MutationObserver(whenWordChanges);

//Running the observer.
observer.observe(currentWordNode, config);