Forked from jonnyirwin/keybr-colemakdh-ortholinear-split
Created
January 7, 2023 18:47
-
-
Save pinguinson/3b718d808c642ee5b2d7840299e0fa4c to your computer and use it in GitHub Desktop.
Inspired by https://gist.github.com/Zyst/3f58009943653e7873d30f1c748cf9ce, the following is used to help setup keybr.com to work for learning ColemakDH and specifically on an ortholinear split keyboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name KeyBR Colemak-DH Ortholinear Split | |
// @namespace http://tampermonkey.net/ | |
// @version v1.0 | |
// @description Switch Colemak layout in keybr.com to Colemak DH Ortholinear Split | |
// @author https://github.com/jonnyirwin | |
// @match https://www.keybr.com/ | |
// @icon https://www.google.com/s2/favicons?domain=keybr.com | |
// @grant none | |
// ==/UserScript== | |
(() => { | |
"use strict"; | |
const top = "qwfpbjluy;".split(""); | |
const middle = "arstgmneio".split(""); | |
const bottom = "zxcdvkh,./".split(""); | |
const allKeyLayout = [ | |
top.map(toDataKey), | |
middle.map(toDataKey), | |
bottom.map(toDataKey), | |
]; | |
const splitSpacing = 100; | |
const keyDimension = 42; | |
function ifElse(pred, f, g) { | |
return function (x) { | |
return pred(x) ? f(x) : g(x); | |
}; | |
} | |
function getRowAndColumn(dataKey) { | |
const row = allKeyLayout.findIndex((row) => row.includes(dataKey)); | |
console.log({ dataKey, row }); | |
return [row, allKeyLayout[row].findIndex((row) => row.includes(dataKey))]; | |
} | |
function toDataKey(char) { | |
if (/[a-z]/.test(char)) return `Key${char.toUpperCase()}`; | |
if (char === ";") return "Semicolon"; | |
if (char === ",") return "Comma"; | |
if (char === ".") return "Period"; | |
if (char === "/") return "Slash"; | |
} | |
function keepKey(element) { | |
return ( | |
element.dataset && | |
element.dataset.key && | |
/Key|Comma|Period|^Slash|Semicolon/i.test(element.dataset.key) | |
); | |
} | |
function removeElement(element) { | |
element.parentElement.removeChild(element); | |
} | |
function setKeyPosition(element) { | |
const [row, column] = getRowAndColumn(element.dataset.key); | |
element.setAttribute("x", column < 5 ? column * keyDimension : column * keyDimension + splitSpacing); | |
element.setAttribute("y", row * keyDimension); | |
} | |
const loopToFindKeyboard = () => { | |
const kb = document.querySelector("main > div > div > svg"); | |
if (document.title === "Typing Practice" && kb) { | |
const allKeys = [...document.querySelectorAll("svg>svg>svg")]; | |
allKeys.forEach(ifElse(keepKey, setKeyPosition, removeElement)); | |
} | |
setTimeout(loopToFindKeyboard, 500); | |
}; | |
loopToFindKeyboard(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment