-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathloaderBuilder.js
115 lines (97 loc) · 4.14 KB
/
loaderBuilder.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
export default class LoaderBuilder {
#onlineMatch = `// @match https://bondageprojects.elementfx.com/*
// @match https://www.bondageprojects.elementfx.com/*
// @match https://bondage-europe.com/*
// @match https://www.bondage-europe.com/*
// @match https://bondageprojects.com/*
// @match https://www.bondageprojects.com/*`;
#localMatch = '// @match http://localhost:*/*'
constructor() {
this.isLocal = !process.env.NETLIFY;
this.isBranch = !this.isLocal && process.env.BRANCH === 'main' || process.env.BRANCH === 'beta';
this.branch = process.env.BRANCH;
this.pr = process.env.REVIEW_ID;
this.label = this.isLocal ? 'local ' : (this.branch === 'main' ? '' : (this.branch.startsWith('pull/') ? `PR #${this.pr}` : this.branch) + ' ');
this.URL = this.isLocal ? 'http://localhost:4000' : (process.env.CONTEXT === 'production' ? process.env.URL : process.env.DEPLOY_PRIME_URL);
}
getUserScriptMeta(isFUSAM) {
return `// ==UserScript==
// @name WCE ${this.label}loader${isFUSAM ? ' with FUSAM' : ''}
// @namespace https://www.bondageprojects.com/
// @version ${isFUSAM ? '1.5' : '1.2'}
// @description Wholesome Club Extensions (WCE) - enhancements for the bondage club - fork of FBC 5.8
// @author Sidious, Stella
// @supportURL https://github.com/KittenApps/WCE
${this.isLocal ? this.#localMatch : this.#onlineMatch}
// @icon https://wce-docs.vercel.app/img/logo.png
// @grant none
// @run-at document-end
// ==/UserScript==`;
}
generateFusamLoader() {
if (this.isBranch) {
return `${this.getUserScriptMeta(true)}
import(\`https://sidiousious.gitlab.io/bc-addon-loader/fusam.js?v=\${(Date.now()/10000).toFixed(0)}\`);
var fusam = JSON.parse(localStorage.getItem("fusam.settings") || "{}");
fusam.enabledDistributions ??= {};
fusam.enabledDistributions.WCE ??= "${process.env.BRANCH === 'main' ? 'stable' : 'dev'}";
const URL = fusam.enabledDistributions.WCE === "stable" ? "https://wce.netlify.app" : "https://beta--wce.netlify.app" ;
var preloadLink = document.createElement("link");
preloadLink.href = \`\${URL}/wce.js\`;
preloadLink.rel = "modulepreload";
document.head.appendChild(preloadLink);
var dexiePreloadLink = document.createElement("link");
dexiePreloadLink.href = \`\${URL}/dexie.js\`;
dexiePreloadLink.rel = "modulepreload";
document.head.appendChild(dexiePreloadLink);
delete fusam.enabledDistributions.FBC;
localStorage.setItem("fusam.settings", JSON.stringify(fusam));`;
} else {
return `${this.getUserScriptMeta(true)}
import(\`https://sidiousious.gitlab.io/bc-addon-loader/fusam.js?v=\${(Date.now()/10000).toFixed(0)}\`).then(() => import("${this.URL}/wce.js"));
var preloadLink = document.createElement("link");
preloadLink.href = "${this.URL}/wce.js";
preloadLink.rel = "modulepreload";
document.head.appendChild(preloadLink);
var dexiePreloadLink = document.createElement("link");
dexiePreloadLink.href = "${this.URL}/dexie.js";
dexiePreloadLink.rel = "modulepreload";
document.head.appendChild(dexiePreloadLink);
var fusam = JSON.parse(localStorage.getItem("fusam.settings") || "{}");
fusam.enabledDistributions ??= {};
delete fusam.enabledDistributions.WCE;
delete fusam.enabledDistributions.FBC;
localStorage.setItem("fusam.settings", JSON.stringify(fusam));`;
}
}
generateStandaloneLoader() {
return `${this.getUserScriptMeta(false)}
var preloadLink = document.createElement("link");
preloadLink.href = "${this.URL}/wce.js";
preloadLink.rel = "modulepreload";
document.head.appendChild(preloadLink);
var dexiePreloadLink = document.createElement("link");
dexiePreloadLink.href = "${this.URL}/dexie.js";
dexiePreloadLink.rel = "modulepreload";
document.head.appendChild(dexiePreloadLink);
var fusam = JSON.parse(localStorage.getItem("fusam.settings") || "{}");
fusam.enabledDistributions ??= {};
delete fusam.enabledDistributions.WCE;
delete fusam.enabledDistributions.FBC;
localStorage.setItem("fusam.settings", JSON.stringify(fusam));
if (typeof FUSAM === "object" && FUSAM?.present) {
import("${this.URL}/wce.js");
} else {
let storeFUSAM;
Object.defineProperty(window, "FUSAM", {
set(n) {
storeFUSAM = n;
import("${this.URL}/wce.js");
},
get() {
return storeFUSAM;
},
});
}`
}
}