-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
52 lines (46 loc) · 1.55 KB
/
main.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
47
48
49
50
51
52
// styles:
import floatingPanel from "./styles/floatingPanel.css?inline";
import colorPicker from "./styles/colorPicker.css?inline";
import vizzyThemer from "./styles/vizzyThemer.css?inline";
import others from "./styles/others.css?inline";
import customFolds from "./styles/customFolds.css?inline";
import expandViews from "./styles/expandViews.css?inline";
// scripts:
import Selectors from "./utils/selectors";
import injectVizzard from "./vizzard";
import makeLogoClickable from "./scripts/vizzyLogoClickable";
window.addEventListener("load", function () {
// trigger vizzard reload and inject styles as well
vizzardReload(true);
});
// run function when navigating to a different page
new MutationObserver(function () {
vizzardReload();
}).observe(document.querySelector("title"), {
subtree: true,
characterData: true,
childList: true,
});
const vizzardReload = (inj_styles = false) => {
setTimeout(() => {
if (inj_styles) {
// load custom css
GM_addStyle(vizzyThemer);
GM_addStyle(colorPicker);
GM_addStyle(floatingPanel);
GM_addStyle(others);
GM_addStyle(customFolds);
GM_addStyle(expandViews);
}
// inject scripts that will run on any vizzy page
makeLogoClickable();
const editorBase = Selectors().editor;
// make sure we are in an editor
// make sure that the vizzard is not already injected
if (!editorBase || editorBase?.classList.contains("vizzard-injected"))
return;
// inject vizzard
injectVizzard();
editorBase.classList.add("vizzard-injected");
}, 2000);
};