generated from mintlify/starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
46 lines (41 loc) · 1.3 KB
/
script.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function updatePageStyles() {
const currentPath = window.location.pathname;
if (currentPath.startsWith("/semantic-router")) {
document.body.classList.add("semantic-router");
document.body.classList.remove("aurelio-sdk");
document.body.classList.remove("graphai");
} else if (currentPath.startsWith("/aurelio-sdk")) {
document.body.classList.remove("semantic-router");
document.body.classList.add("aurelio-sdk");
document.body.classList.remove("graphai");
} else if (currentPath.startsWith("/graphai")) {
document.body.classList.remove("semantic-router");
document.body.classList.remove("aurelio-sdk");
document.body.classList.add("graphai");
}
}
updatePageStyles();
const debounce = (func, delay) => {
let timerId;
return function (...args) {
clearTimeout(timerId);
timerId = setTimeout(() => {
func.apply(this, args);
}, delay);
};
};
const debouncedUpdatePageStyles = debounce(() => {
updatePageStyles();
}, 100);
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.type === "childList") {
try {
debouncedUpdatePageStyles();
} catch (error) {
console.error(error);
}
}
});
});
observer.observe(document.body, { childList: true, subtree: true });