-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinjector.js
More file actions
62 lines (55 loc) · 2.13 KB
/
injector.js
File metadata and controls
62 lines (55 loc) · 2.13 KB
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
/**
* Script Loader (Centralized Dependency Manager)
* * This file dynamically creates and appends <script> tags for
* all listed files, ensuring only this file needs to be updated
* when adding or removing application dependencies.
*/
(function() {
// Prevent multiple loads
if (window.__4sp_injector_loaded) return;
window.__4sp_injector_loaded = true;
// 1. DEFINE YOUR SCRIPTS HERE
// Update this array (and ONLY this array) to manage your application's scripts.
const scriptsToLoad = [
'../ban-enforcer.js',
'../tab-disguiser.js',
'../panic-key.js',
'../analytics.js',
'../navigation.js',
'../v6-announcement.js'
];
// 2. CORE DYNAMIC LOADING FUNCTION
/**
* Creates a Promise to load a script element, resolving when loaded.
*/
function loadScript(url) {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = url;
script.async = true; // Prevents blocking the rest of the page render
// Set up event listeners
script.onload = () => {
console.log(`Script loaded: ${url}`);
resolve(url);
};
script.onerror = () => {
console.error(`Failed to load script: ${url}`);
reject(new Error(`Loading error for ${url}`));
};
// Inject the script into the document's head to start the download
document.head.appendChild(script);
});
}
// 3. INITIATE LOADING PROCESS
// Load all scripts in parallel and wait for all to complete
const loadingPromises = scriptsToLoad.map(loadScript);
Promise.all(loadingPromises)
.then(() => {
console.log('--- All application scripts loaded successfully! ---');
// OPTIONAL: Place initialization code here that requires ALL scripts to be ready.
// Example: if (window.initApp) { window.initApp(); }
})
.catch(error => {
console.error('Loader encountered errors during script loading:', error);
});
})();