-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
21 lines (17 loc) · 1.02 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const tags = ['c', 'qt', 'obj']; // these are my tags: comment, blockquote, and objection. Use whatever you want and then update the CSS style accordingly
function applyAndHideTag(tags) {
tags.forEach((tag) => {
document.querySelectorAll('span[data-tag=' + tag + ']').forEach((node) => {
if (node.closest('div.roam-block-container').classList.contains(tag + '_tag') == false) { // this check is so that this function only runs when necessary and doesn't cause the mutationObserver to go into an infinite loop
node.closest('div.roam-block-container').classList.add(tag + '_tag');
node.parentNode.innerHTML = node.parentNode.innerHTML.replace('</span> ', '</span>'); //since the custom CSS will hide the tag, this gets ready of the resulting leading whitespace
}
});
});
}
const mutationObserver = new MutationObserver(() => applyAndHideTag(tags))
const config = {
childList: true,
subtree: true
};
mutationObserver.observe(document.documentElement, config);