Last active
September 17, 2023 18:02
-
-
Save kiprasmel/3fb1578e1f428dd1dd8e88683ca8c400 to your computer and use it in GitHub Desktop.
roam: Expand All blocks of linked refs
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
/** | |
* https://gist.github.com/kiprasmel/3fb1578e1f428dd1dd8e88683ca8c400 | |
* | |
* put in a javascript code block under a block containing {{[[roam/js]]}} text, like so: | |
* - {{[[roam/js]]}} | |
* - this code | |
*/ | |
// https://roamresearch.com/#/app/developer-documentation/page/JTLUegLiI | |
window.roamAlphaAPI.ui | |
.commandPalette | |
.addCommand({label: 'Expand All blocks of linked refs (custom)', | |
callback: expandAll, | |
"disable-hotkey": false, | |
// this is the default hotkey, and can be customized by the user. | |
// in most cases, you DO NOT want to be setting a default hotkey | |
"default-hotkey": "shift-cmd-e"}) | |
// alt instead of super on win prolly | |
function expandAll() { | |
// find all top-level blocks of linked references and expand all | |
//const elements = Array.from(document.querySelectorAll(".rm-mentions.refs-by-page-view .rm-ref-page-view .rm-bullet")) | |
const elements = Array.from(document.querySelectorAll(".rm-mentions.refs-by-page-view .rm-ref-page-view .rm-reference-item > * > .roam-block-container > .rm-block-main.rm-block__self .rm-bullet")) | |
for (const el of elements) { | |
// open context menu | |
// https://stackoverflow.com/a/52878847/9285308 | |
const event = new MouseEvent("contextmenu", { | |
bubbles: true, | |
cancelable: false, | |
view: window, | |
button: 2, | |
buttons: 0, | |
clientX: el.getBoundingClientRect().x, | |
clientY: el.getBoundingClientRect().y | |
}); | |
el.dispatchEvent(event); | |
// find the "Expand all" button and click it | |
Array.from(document.querySelectorAll('.bp3-menu-item.bp3-popover-dismiss')).find(x => x.textContent === "Expand all").click() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment