Skip to content

Instantly share code, notes, and snippets.

@jonnyirwin
Last active January 7, 2023 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonnyirwin/e3d3a260d953be7e6831c116c93d8d5e to your computer and use it in GitHub Desktop.
Save jonnyirwin/e3d3a260d953be7e6831c116c93d8d5e 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.
// ==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