()
| 23 | } |
| 24 | |
| 25 | async function populatePage() { |
| 26 | const h2s = document.querySelectorAll("h2"); |
| 27 | const byGroup = Object.groupBy(allCommands, (el) => el.group); |
| 28 | const commandToOptionsToKeys = |
| 29 | (await chrome.storage.session.get("commandToOptionsToKeys")).commandToOptionsToKeys; |
| 30 | |
| 31 | const commandTemplate = document.querySelector("template#command").content; |
| 32 | const keysTemplate = document.querySelector("template#keys").content; |
| 33 | |
| 34 | for (const h2 of Array.from(h2s)) { |
| 35 | const group = h2.dataset["group"]; |
| 36 | let commands = byGroup[group]; |
| 37 | // Display them in alphabetical order. |
| 38 | commands = commands.sort((a, b) => b.name.localeCompare(a.name)); |
| 39 | for (const command of commands) { |
| 40 | // Here, we're going to list all of the keys bound to this command, and for now, we're not |
| 41 | // going to visually distinguish versions of the command with options and versions without. |
| 42 | const keys = Object.values(commandToOptionsToKeys[command.name] || {}) |
| 43 | .flat(1); |
| 44 | const el = commandTemplate.cloneNode(true); |
| 45 | // Used for linking to commands using the URL fragment, and by the tests. |
| 46 | el.querySelector(".command").id = command.name; |
| 47 | el.querySelector("h3 code").textContent = command.name; |
| 48 | |
| 49 | const keysEl = el.querySelector(".key-bindings"); |
| 50 | for (const key of keys.sort(compareKeys)) { |
| 51 | const node = keysTemplate.cloneNode(true); |
| 52 | node.querySelector(".key").textContent = key; |
| 53 | keysEl.appendChild(node); |
| 54 | } |
| 55 | |
| 56 | el.querySelector(".desc").textContent = command.desc; |
| 57 | if (command.details) { |
| 58 | el.querySelector(".details").textContent = command.details; |
| 59 | } |
| 60 | |
| 61 | if (command.options) { |
| 62 | const ul = el.querySelector(".options ul"); |
| 63 | for (const [name, desc] of Object.entries(command.options)) { |
| 64 | const li = document.createElement("li"); |
| 65 | li.innerHTML = `<code>${name}</code>: ` + replaceBackticksWithCodeTags(desc); |
| 66 | ul.appendChild(li); |
| 67 | } |
| 68 | } else { |
| 69 | el.querySelector(".options").remove(); |
| 70 | } |
| 71 | h2.after(el); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | const testEnv = globalThis.window == null; |
| 77 | if (!testEnv) { |
no test coverage detected