From ed133380fbc74ef3b6930d1ea125205ffe2e36fc Mon Sep 17 00:00:00 2001 From: The Arcane Brony Date: Wed, 20 Oct 2021 17:54:54 +0200 Subject: Add plugin & css support, add styling to differentiate from discord.com --- api/assets/autoRegister.js | 57 --------------------------- api/assets/preload-plugins/autoRegister.js | 62 ++++++++++++++++++++++++++++++ api/client_test/index.html | 27 ++++++++++++- api/src/middlewares/TestClient.ts | 14 ++++++- 4 files changed, 101 insertions(+), 59 deletions(-) delete mode 100644 api/assets/autoRegister.js create mode 100644 api/assets/preload-plugins/autoRegister.js (limited to 'api') diff --git a/api/assets/autoRegister.js b/api/assets/autoRegister.js deleted file mode 100644 index 29f93370..00000000 --- a/api/assets/autoRegister.js +++ /dev/null @@ -1,57 +0,0 @@ - // Auto register guest account: - const prefix = [ - "mysterious", - "adventurous", - "courageous", - "precious", - "cynical", - "despicable", - "suspicious", - "gorgeous", - "lovely", - "stunning", - "based", - "keyed", - "ratioed", - "twink", - "phoned" - ]; - const suffix = [ - "Anonymous", - "Lurker", - "User", - "Enjoyer", - "Hunk", - "Top", - "Bottom", - "Sub", - "Coolstar", - "Wrestling", - "TylerTheCreator", - "Ad" - ]; - - Array.prototype.random = function () { - return this[Math.floor(Math.random() * this.length)]; - }; - - function _generateName() { - return `${prefix.random()}${suffix.random()}`; - } - - const token = JSON.parse(localStorage.getItem("token")); - if (!token && location.pathname !== "/login" && location.pathname !== "/register") { - fetch(`${window.GLOBAL_ENV.API_ENDPOINT}/auth/register`, { - method: "POST", - headers: { "content-type": "application/json" }, - body: JSON.stringify({ username: `${_generateName()}`, consent: true }) //${Date.now().toString().slice(-4)} - }) - .then((x) => x.json()) - .then((x) => { - localStorage.setItem("token", `"${x.token}"`); - if (!window.localStorage) { - // client already loaded -> need to reload to apply the newly registered user token - location.reload(); - } - }); - } diff --git a/api/assets/preload-plugins/autoRegister.js b/api/assets/preload-plugins/autoRegister.js new file mode 100644 index 00000000..bb0b903d --- /dev/null +++ b/api/assets/preload-plugins/autoRegister.js @@ -0,0 +1,62 @@ +// Auto register guest account: +const prefix = [ + "mysterious", + "adventurous", + "courageous", + "precious", + "cynical", + "flamer ", + "despicable", + "suspicious", + "gorgeous", + "impeccable", + "lovely", + "stunning", + "keyed", + "phoned", + "glorious", + "amazing", + "strange", + "arcane" +]; +const suffix = [ + "Anonymous", + "Boy", + "Lurker", + "Keyhitter", + "User", + "Enjoyer", + "Hunk", + "Coolstar", + "Wrestling", + "TylerTheCreator", + "Ad", + "Gamer", + "Games", + "Programmer" +]; + +Array.prototype.random = function () { + return this[Math.floor(Math.random() * this.length)]; +}; + +function _generateName() { + return `${prefix.random()}${suffix.random()}`; +} + +var token = JSON.parse(localStorage.getItem("token")); +if (!token && location.pathname !== "/login" && location.pathname !== "/register") { + fetch(`${window.GLOBAL_ENV.API_ENDPOINT}/auth/register`, { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ username: `${_generateName()}`, consent: true }) //${Date.now().toString().slice(-4)} + }) + .then((x) => x.json()) + .then((x) => { + localStorage.setItem("token", `"${x.token}"`); + if (!window.localStorage) { + // client already loaded -> need to reload to apply the newly registered user token + location.reload(); + } + }); +} diff --git a/api/client_test/index.html b/api/client_test/index.html index 92499034..2ff0b469 100644 --- a/api/client_test/index.html +++ b/api/client_test/index.html @@ -4,6 +4,10 @@ Discord Test Client + + + + @@ -38,12 +42,33 @@ ALGOLIA_KEY: "aca0d7082e4e63af5ba5917d5e96bed0" }; GLOBAL_ENV.MEDIA_PROXY_ENDPOINT = location.protocol + "//" + GLOBAL_ENV.CDN_HOST; + const localStorage = window.localStorage; + // TODO: remote auth + // window.GLOBAL_ENV.REMOTE_AUTH_ENDPOINT = window.GLOBAL_ENV.GATEWAY_ENDPOINT.replace(/wss?:/, ""); + localStorage.setItem("gatewayURL", window.GLOBAL_ENV.GATEWAY_ENDPOINT); + localStorage.setItem( + "DeveloperOptionsStore", + `{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}` + ); + + + const token = JSON.parse(localStorage.getItem("token")); + if(token) { + document.querySelector("#logincss").remove(); + } + + const settings = JSON.parse(localStorage.getItem("UserSettingsStore")); + if (settings && settings.locale.length <= 2) { + // fix client locale wrong and client not loading at all + settings.locale = "en-US"; + localStorage.setItem("UserSettingsStore", JSON.stringify(settings)); + } - + diff --git a/api/src/middlewares/TestClient.ts b/api/src/middlewares/TestClient.ts index b718bdab..7d981f0c 100644 --- a/api/src/middlewares/TestClient.ts +++ b/api/src/middlewares/TestClient.ts @@ -24,8 +24,20 @@ export default function TestClient(app: Application) { html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`); } - app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets"))); + //plugins + var files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins")); + var plugins = ""; + files.forEach(x =>{if(x.endsWith(".js")) plugins += `\n`; }); + html = html.replaceAll("", plugins); + //preload plugins + files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins")); + plugins = ""; + files.forEach(x =>{if(x.endsWith(".js")) plugins += `\n`; }); + html = html.replaceAll("", plugins); + + app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets"))); + app.get("/assets/:file", async (req: Request, res: Response) => { delete req.headers.host; var response: FetchResponse; -- cgit 1.4.1 From 8df80f659ad343b2782abefaabdbe9f8b684c27e Mon Sep 17 00:00:00 2001 From: The Arcane Brony Date: Fri, 22 Oct 2021 09:56:36 +0200 Subject: Attempt to fix auto register --- api/client_test/index.html | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'api') diff --git a/api/client_test/index.html b/api/client_test/index.html index 2ff0b469..b19d5f0d 100644 --- a/api/client_test/index.html +++ b/api/client_test/index.html @@ -51,11 +51,12 @@ `{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}` ); - - const token = JSON.parse(localStorage.getItem("token")); - if(token) { - document.querySelector("#logincss").remove(); - } + setInterval(() => { + var token = JSON.parse(localStorage.getItem("token")); + if (token) { + document.querySelector("#logincss").remove(); + } + }, 1000); const settings = JSON.parse(localStorage.getItem("UserSettingsStore")); if (settings && settings.locale.length <= 2) { -- cgit 1.4.1 From ae6bfb54a48adaacea82a5ced3456cee5e977b0b Mon Sep 17 00:00:00 2001 From: The Arcane Brony Date: Thu, 11 Nov 2021 22:14:33 +0100 Subject: Fix autoregister, add inline plugins --- .vscode/settings.json | 4 ++++ api/assets/dff87c953f43b561d71fbcfe8a93a79a.png | 0 2 files changed, 4 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 api/assets/dff87c953f43b561d71fbcfe8a93a79a.png (limited to 'api') diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..46e4e52f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "awooga.originalColorCustomizations": {}, + "workbench.colorCustomizations": {} +} \ No newline at end of file diff --git a/api/assets/dff87c953f43b561d71fbcfe8a93a79a.png b/api/assets/dff87c953f43b561d71fbcfe8a93a79a.png new file mode 100644 index 00000000..e69de29b -- cgit 1.4.1 From a61bba7e27a0d0081d176aac6900c09f7d695428 Mon Sep 17 00:00:00 2001 From: The Arcane Brony Date: Thu, 11 Nov 2021 22:17:21 +0100 Subject: Inline plugin support --- api/client_test/index.html | 6 +++--- api/package-lock.json | 2 ++ api/src/middlewares/TestClient.ts | 11 ++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'api') diff --git a/api/client_test/index.html b/api/client_test/index.html index b19d5f0d..0b3a775a 100644 --- a/api/client_test/index.html +++ b/api/client_test/index.html @@ -4,9 +4,9 @@ Discord Test Client - - - + + + diff --git a/api/package-lock.json b/api/package-lock.json index e8ebd5bf..a4ad6b2b 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -84,6 +84,7 @@ "pg": "^8.7.1", "proxy-agent": "^5.0.0", "reflect-metadata": "^0.1.13", + "sqlite3": "^5.0.2", "typeorm": "^0.2.38", "typescript": "^4.4.2", "typescript-json-schema": "^0.50.1" @@ -16162,6 +16163,7 @@ "pg": "^8.7.1", "proxy-agent": "^5.0.0", "reflect-metadata": "^0.1.13", + "sqlite3": "^5.0.2", "ts-node": "^10.2.1", "typeorm": "^0.2.38", "typescript": "^4.4.2", diff --git a/api/src/middlewares/TestClient.ts b/api/src/middlewares/TestClient.ts index 7d981f0c..b50f4e5c 100644 --- a/api/src/middlewares/TestClient.ts +++ b/api/src/middlewares/TestClient.ts @@ -23,10 +23,15 @@ export default function TestClient(app: Application) { if (GATEWAY_ENDPOINT) { html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`); } - - //plugins - var files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins")); + // inline plugins + var files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins")); var plugins = ""; + files.forEach(x =>{if(x.endsWith(".js")) plugins += `\n`; }); + html = html.replaceAll("", plugins); + + // plugins + files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins")); + plugins = ""; files.forEach(x =>{if(x.endsWith(".js")) plugins += `\n`; }); html = html.replaceAll("", plugins); //preload plugins -- cgit 1.4.1 From 2c6d37fad06098720fe9d053971d270c8e40af29 Mon Sep 17 00:00:00 2001 From: The Arcane Brony Date: Sun, 14 Nov 2021 16:30:12 +0100 Subject: Add user.css --- api/assets/user.css | 1 + 1 file changed, 1 insertion(+) create mode 100644 api/assets/user.css (limited to 'api') diff --git a/api/assets/user.css b/api/assets/user.css new file mode 100644 index 00000000..a7e5c4f3 --- /dev/null +++ b/api/assets/user.css @@ -0,0 +1 @@ +/* Your custom CSS goes here, enjoy! */ \ No newline at end of file -- cgit 1.4.1