Skip to content

Instantly share code, notes, and snippets.

@alan-andrade

alan-andrade/next.js

Last active Mar 31, 2021
Embed
What would you like to do?
Jump to next hotkey
javascript:(() => {
const contains = (text) => `contains(text(),'${text}')`;
const conditions = (textOrArray) => textOrArray instanceof Array ? textOrArray.map(contains) : [contains(textOrArray)];
const btnXpath = (text) => `//button[${conditions(text).join(" or ")}]`;
const divXpath = (text) => `//div[${contains(text)}]`;
const findEl = (xpath) => document.evaluate(
xpath,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null).singleNodeValue;
const isWriting = () => findEl(`//div[@role="listbox"]`);
const back = () => findEl(btnXpath("Back")).click();
const flag = () => findEl(btnXpath(["Flag Class", "Unflag Class"])).click();
const skip = () => findEl(btnXpath("Skip")).click();
const next = () => findEl(btnXpath("Save + Next")).click();
const tag = () => findEl(divXpath("Choose an option")).click();
const keyMappings = {
"a": back,
"s": flag,
"d": skip,
"f": next,
"w": tag
};
const triggerFn = (key) => keyMappings[key]();
const guard = () => isWriting() ? () => {} : triggerFn;
document.onkeypress = (e) => guard()(e.key);
alert("a = Back\ns = Flag/Unflag\nd = Skip\nf = Next\nw = Write");
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment