-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathLoadCharacterPage.js
69 lines (61 loc) · 2.43 KB
/
LoadCharacterPage.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
/* LoadCharacterPage.js
*
* Double-check the manifest, but this script should only be executed on the character sheet when abovevtt is not running
*/
console.log("LoadCharacterPage.js is executing");
// Make sure we don't execute this file if Load.js has executed
const isVttGamePage = window.location.search.includes("abovevtt=true");
if (!isVttGamePage) {
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);
// load stylesheets
[
"DiceContextMenu/DiceContextMenu.css",
"jquery.contextMenu.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);
});
window.scripts = [
// External Dependencies
{ src: "jquery-3.6.0.min.js" },
{ src: "jquery.contextMenu.js" },
// AboveVTT Files
{ src: "DiceContextMenu/DiceContextMenu.js" },
{ src: "MonsterDice.js" },
{ src: "DiceRoller.js" },
{ src: "DDBApi.js" },
{ src: "MessageBroker.js" },
{ src: "rpg-dice-roller.bundle.min.js" },
// AboveVTT files that execute when loaded
{ src: "CoreFunctions.js" }, // Make sure CoreFunctions executes first
{ src: "CharactersPage.js" } // Make sure CharactersPage executes last
]
// Too many of our scripts depend on each other.
// This ensures that they are loaded sequentially to avoid any race conditions.
function injectScript() {
if (window.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();
}