-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
27 lines (24 loc) · 900 Bytes
/
content.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
const sidebarInitObserver = new MutationObserver((mutationsList, observer) => {
const targetElement = document.querySelector(".notion-sidebar");
if (targetElement) {
observer.disconnect();
const expandedObserver = new MutationObserver(expandedObserverCallback);
expandedObserver.observe(targetElement, {
subtree: true,
childList: true,
attributes: false,
});
}
});
let previousExpanded = null;
function expandedObserverCallback(mutationsList, observer) {
const targetElement = document.querySelector(".notion-sidebar");
const sidebarData = JSON.parse(
localStorage.getItem("LRU:KeyValueStore2:sidebar")
);
const expanded = sidebarData["value"]["expanded"];
if (expanded !== previousExpanded) {
targetElement.style.display = expanded ? "block" : "none";
}
}
sidebarInitObserver.observe(document.body, { subtree: true, childList: true });