-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbackup-keyboard-cheat-sheet.js
28 lines (27 loc) · 1.24 KB
/
backup-keyboard-cheat-sheet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Backup Keyboard Cheat Sheet
// version 2024.4.5
// https://forum.vivaldi.net/post/745999
// Writes the contents of the keyboard cheat sheet to your clipboard in markdown
// format. Open user interface console, open keyboard cheat sheet popup, paste
// code and hit Enter to execute.
const sheet = document.querySelector(".keyboardShortcutsWrapper");
const heading = sheet.querySelector("h1").innerText;
const pb1 = "<style>\n tr{page-break-inside:avoid}\n</style>\n\n";
const pb2 = `<div style="page-break-after:avoid"></div>`;
let output = `${pb1}# ${heading}\n\n<table>\n`;
sheet.querySelectorAll(".category").forEach((category, key, arr) => {
const caps = category.firstChild.innerText.toUpperCase();
output += ` <tr><td><b>${caps}</b></td><td>${pb2}</td></tr>\n`;
category.querySelectorAll(".keycombo").forEach((command) => {
output += ` <tr><td>${command.innerText}</td><td>`;
command.querySelectorAll("input").forEach((combo, key, arr) => {
output += combo.value;
if (Object.is(arr.length - 1, key)) output += "</td></tr>\n";
else output += "<br>";
});
});
if (Object.is(arr.length - 1, key)) output += "</table>";
else output += " <tr><td> </td><td> </td></tr>\n";
});
copy(output);
console.info(output);