Last active
December 24, 2021 04:28
-
-
Save SamuelDavis/6de29beef39b257d5e9a9ab14ccb7905 to your computer and use it in GitHub Desktop.
Scrape the Vim commands from https://openvim.com/development.html
This file contains hidden or 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
let data = Array.from(document.querySelectorAll(".commands-container h2")).map( | |
(el) => { | |
return { | |
heading: el.textContent, | |
items: Array.from(el.nextElementSibling.children).map((el) => { | |
const [answers, ...description] = el.textContent | |
.trim() | |
.split(/\s+-\s+/); | |
return { | |
description: description.join(" - "), | |
answers: answers.split(" or ").map((cmd) => { | |
if (cmd.match(/^[^a-z0-9]/i)) return [cmd]; | |
return cmd | |
.split(" + ") | |
.map((cmd) => { | |
if (cmd === "Ctrl") return "<ctrl>"; | |
return cmd.split("").map((cmd) => { | |
if (cmd.match("[A-Z]")) return ["<shift>", cmd.toLowerCase()]; | |
return cmd; | |
}); | |
}) | |
.flat(5); | |
}), | |
}; | |
}), | |
}; | |
} | |
); | |
let onClick = () => { | |
document.body.removeEventListener("click", onClick); | |
navigator.clipboard | |
.writeText(JSON.stringify(data, null, 2)) | |
.then(() => alert("Commands copied to clipboard.")) | |
.catch((err) => { | |
throw err; | |
}); | |
}; | |
document.body.addEventListener("click", onClick); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment