Keymap Overlay for Custom Layouts on monkeytype.com (Updated)

Swap keys repeatedly on a base keymap layout till you get your modified version of the layout

You will need to install an extension such as Tampermonkey, Greasemonkey 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 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.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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         Keymap Overlay for Custom Layouts on monkeytype.com (Updated)
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Swap keys repeatedly on a base keymap layout till you get your modified version of the layout
// @author       full alt
// @match        https://monkeytype.com/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    async function swap(key1, key2){
        var s1 = "[data-key='"+key1+"']"
        var s2 = "[data-key='"+key2+"']"
        var k1 = document.querySelectorAll(s1)[0];
        var k2 = document.querySelectorAll(s2)[0];
        k1.setAttribute("data-key",key2)
        k2.setAttribute("data-key",key1)
        var tempk1val = k1.getElementsByTagName("span")[0].innerText
        k1.getElementsByTagName("span")[0].innerText = k2.getElementsByTagName("span")[0].innerText
        k2.getElementsByTagName("span")[0].innerText = tempk1val
    }

    //just right click anywhere for the changes to be made
    //the goal is to have keys swap places with each other on the keymap to suit your layout
    window.oncontextmenu = async function (){
        //IMPORTANT: For letters use inputs like "hH" or "jJ" since the updated site has 2 characters being used
        //for symbols, if you don't know the what the key is then just inspect element the key and see what the 'id' of the element is
        /*
        OLD CODE, IGNORE THIS
        swap("O","Semicolon");
        swap("F","G");
        swap("Z","Quote");
        swap("K","Quote");
        swap("D","Quote");
        swap("C","Quote");
        swap("X","Quote");
        */
        await swap("vV","fF");
        await swap("mM","qQ");
        await swap("fF","zZ");
        await swap("gG","kK");
        await swap("pP","cC");
        await swap("fF","kK");
        await swap("mM","kK");
    };
})();