Last active
June 26, 2021 08:15
-
-
Save houshuang/93a320a5b3d447d13613735be2d68bec to your computer and use it in GitHub Desktop.
Roam JS for putting a page/block on your left sidebar
This file contains 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
// MIT Licensed | |
// Author: jwilson8767 | |
/** | |
* Waits for an element satisfying selector to exist, then resolves promise with the element. | |
* Useful for resolving race conditions. | |
* | |
* @param selector | |
* @returns {Promise} | |
*/ | |
function elementReady(selector) { | |
return new Promise((resolve, reject) => { | |
let el = document.querySelector(selector); | |
if (el) {resolve(el);} | |
new MutationObserver((mutationRecords, observer) => { | |
// Query for elements matching the specified selector | |
Array.from(document.querySelectorAll(selector)).forEach((element) => { | |
resolve(element); | |
//Once we have resolved we don't need the observer anymore. | |
observer.disconnect(); | |
}); | |
}) | |
.observe(document.documentElement, { | |
childList: true, | |
subtree: true | |
}); | |
}); | |
} | |
elementReady(".starred-pages-wrapper").then(()=>{ | |
const wrap = document.getElementsByClassName('starred-pages-wrapper')[0] | |
wrap.style.margin = "-20px -60px"; | |
wrap.style.padding = "0px"; | |
wrap.style.width = "280px"; | |
window.roamAlphaAPI.ui.components.renderBlock( | |
{uid: '5OdyKgIIQ', el: wrap})}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for the code! It turned out to be very useful))
Do you know how to make the injected blocks scrollable in case there are more than the sidebar height?