-
Notifications
You must be signed in to change notification settings - Fork 62
/
Load.js
145 lines (136 loc) · 4.91 KB
/
Load.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
console.log("Load.js is executing");
if (window.location.search.includes("abovevtt=true")) {
let loadingOverlay = document.createElement('div');
loadingOverlay.setAttribute("id", "loading_overlay");
(document.body || document.documentElement).appendChild(loadingOverlay);
let loadingBg = document.createElement('div');
loadingBg.setAttribute("id", "loading_overlay_bg");
loadingOverlay.appendChild(loadingBg);
if (window.location.pathname.includes("/encounters/")) {
loadingBg.setAttribute("class", "dm");
} else if (window.location.pathname.includes("/characters/")) {
loadingBg.setAttribute("class", "player");
}
}
let l = document.createElement('div');
l.setAttribute("style", "display:none;");
l.setAttribute("id", "extensionpath");
l.setAttribute("data-path", chrome.runtime.getURL("/"));
(document.body || document.documentElement).appendChild(l);
let avttVersion = document.createElement('div');
avttVersion.setAttribute("style", "display:none;");
avttVersion.setAttribute("id", "avttversion");
avttVersion.setAttribute("data-version", chrome.runtime.getManifest().version);
(document.body || document.documentElement).appendChild(avttVersion);
// load stylesheets
[
"abovevtt.css",
"jquery-ui.min.css",
"jquery.ui.theme.min.css",
"jquery.contextMenu.css",
"color-picker.min.css",
"spectrum-2.0.8.min.css",
"magnific-popup.css",
"DiceContextMenu/DiceContextMenu.css"
].forEach(function(value, index, array) {
let l = document.createElement('link');
l.href = chrome.runtime.getURL(value);
l.rel = "stylesheet";
console.log(`attempting to append ${value}`);
(document.head || document.documentElement).appendChild(l);
});
// load scripts
window.scripts = [
// External Dependencies
{ src: "jquery-3.6.0.min.js" },
{ src: "jquery-ui.min.js" },
{ src: "jquery.csv.js" },
//{ src: "jquery.ui.widget.min.js" },
//{ src: "jquery.ui.mouse.min.js" },
{ src: "jquery.ui.touch-punch.js" },
{ src: "jquery.contextMenu.js" },
{ src: "jquery.magnific-popup.min.js" },
{ src: "spectrum-2.0.8.min.js" },
// { src: "jquery.ajax.queue.js" },
{ src: "purify.min.js" },
{ src: "rpg-dice-roller.bundle.min.js" },
{ src: "color-picker.js" },
{ src: "mousetrap.1.6.5.min.js" },
{ src: "peerjs.min.js" },
{ src: "fuse.min.js" },
// AboveVTT Files
{ src: "environment.js" },
{ src: "AboveApi.js" },
{ src: "DDBApi.js" },
{ src: "AOETemplates.js" },
{ src: "Text.js" },
{ src: "CombatTracker.js" },
{ src: "EncounterHandler.js" },
{ src: "Fog.js" },
{ src: "Journal.js" },
{ src: "KeypressHandler.js" },
{ src: "MessageBroker.js" },
{ src: "MonsterDice.js" },
{ src: "PlayerPanel.js" },
{ src: "SceneData.js" },
{ src: "scenedata/bgdia-scene-data.js" },
{ src: "scenedata/tod-scene-data.js" },
{ src: "scenedata/toa-scene-data.js" },
{ src: "scenedata/doip-scene-data.js" },
{ src: "scenedata/lmop-scene-data.js" },
{ src: "scenedata/pbtso-scene-data.js" },
{ src: "scenedata/loe-scene-data.js" },
{ src: "scenedata/veor-scene-data.js" },
{ src: "ScenesHandler.js" },
{ src: "ScenesPanel.js" },
{ src: "Settings.js" },
{ src: "SidebarPanel.js" },
{ src: "StatHandler.js" },
{ src: "Token.js" },
{ src: "TokenMenu.js" },
{ src: "ChatObserver.js" },
{ src: "DiceContextMenu/DiceContextMenu.js" },
{ src: "TokensPanel.js" },
{ src: "TokenCustomization.js" },
{ src: "built-in-tokens.js" },
{ src: "PeerManager.js" },
{ src: "PeerCommunication.js" },
{ src: "peerVideo.js"},
{ src: "ajaxQueue/ajaxQueueIndex.js", type: "module" },
{ src: "DiceRoller.js" },
{ src: "Main.js" },
{ src: "MonsterStatBlock.js" },
// AboveVTT files that execute when loaded
{ src: "CoreFunctions.js" }, // Make sure CoreFunctions executes before anything else
{ src: "CampaignPage.js" },
{ src: "CharactersPage.js" },
{ src: "audio/index.js", type: "module" },
{ src: "onedrive/onedrivemsal.js" },
{ src: "onedrive/onedrivepicker.js" },
// Startup must be the last file to execute. This is what actually loads the app. It requires all the previous files to be loaded first
{ src: "Startup.js", type: "module" }
]
if(!window.location.pathname.includes("/characters/")){
window.scripts = window.scripts.filter(d=> d.src != 'CharactersPage.js');
}
// Too many of our scripts depend on each other.
// This ensures that they are loaded sequentially to avoid any race conditions.
function injectScript() {
if (scripts.length === 0) {
delete window.scripts;
return;
}
let nextScript = window.scripts.shift();
let s = document.createElement('script');
s.src = chrome.runtime.getURL(nextScript.src);
if (nextScript.type !== undefined) {
s.setAttribute('type', nextScript.type);
}
console.log(`attempting to append ${nextScript.src}`);
s.onload = function() {
console.log(`finished injecting ${nextScript.src}`);
injectScript();
};
(document.head || document.documentElement).appendChild(s);
}
injectScript();