Keymap Overlay For Monkeytype

Modify keymap layout by replacing keys, works with keymap next

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         Keymap Overlay For Monkeytype
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Modify keymap layout by replacing keys, works with keymap next
// @author       Pira
// @match        https://monkeytype.com/
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const keyMapping = {
        q: "q",
        w: "w",
        e: "e",
        r: "r",
        t: "t",
        y: "y",
        u: "u",
        i: "i",
        o: "o",
        p: "p",
        "[": "[",
        "]": "]",
        a: "a",
        s: "s",
        d: "d",
        f: "f",
        g: "g",
        h: "h",
        j: "j",
        k: "k",
        l: "l",
        ";": ";",
        "'": "'",
        z: "z",
        x: "x",
        c: "c",
        v: "v",
        b: "b",
        n: "n",
        m: "m",
        ',': ",",
        '.': ".",
        '/': "/"
    };

    async function modifyKeymap() {
  const keys = document.querySelectorAll('.keymapKey');
  const updatedMapping = {};

  keys.forEach(function(key) {
    const letter = key.querySelector('.letter');
    const currentKey = letter.textContent.toLowerCase();
    const newKey = keyMapping[currentKey];

      if (currentKey === ',<' && keyMapping[currentKey]) {
                letter.textContent = keyMapping[currentKey];}
    if (newKey) {
      const tempValue = letter.textContent;
      letter.textContent = newKey;
      key.setAttribute('data-key', newKey.toLowerCase() + newKey.toUpperCase());
      updatedMapping[newKey.toLowerCase()] = currentKey;
    } else {
      updatedMapping[currentKey] = currentKey;
    }
  });

  Object.assign(keyMapping, updatedMapping);
}


    function updateActiveKey() {
        const activeKeyElement = document.querySelector('.activeKey');
        const activeKey = activeKeyElement.textContent.toLowerCase();
        const mappedKey = keyMapping[activeKey];

        if (mappedKey) {
            activeKeyElement.textContent = mappedKey.toUpperCase();
        }
    }

    // Right-click event listener
    window.addEventListener("contextmenu", async function(event) {
        event.preventDefault();

        // Modify the keymap
        await modifyKeymap();

        // Update the active key
        updateActiveKey();
    });
})();