From 6a09c230d1f6cc5b67539dba88e1c2f24fa71b28 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Mon, 24 Oct 2022 18:59:53 +1100 Subject: rearrange test client's index a bit --- assets/cacheMisses | 5 ++ assets/client_test/developers.html | 1 - assets/client_test/index.html | 146 ++++++++++++++++---------------- assets/preload-plugins/autoRegister.js | 62 -------------- assets/preload-plugins/checkLocale.js | 46 ++++++++++ assets/preload-plugins/loginRedirect.js | 27 +++--- assets/public/checkLocale.js | 47 ---------- 7 files changed, 136 insertions(+), 198 deletions(-) delete mode 100644 assets/preload-plugins/autoRegister.js create mode 100644 assets/preload-plugins/checkLocale.js delete mode 100644 assets/public/checkLocale.js (limited to 'assets') diff --git a/assets/cacheMisses b/assets/cacheMisses index 056f4d66..2f68a713 100644 --- a/assets/cacheMisses +++ b/assets/cacheMisses @@ -183,3 +183,8 @@ dbdc2f57ed1a7f2f01a342ab2e6fb032.svg 9a31e0f65d520cc12d7f42374d59a2d1.svg d759f3acc6286c964cc8118d7f68b374.svg eeacc28d3c62a7cf1154a2bc11968ad8.svg +9fa091f676e4451ee5946fed948cb8fe.svg +7c010dc6da25c012643ea22c1f002bb4.svg +9ea87b934848cd1f5c4bc7f1fcdac803.png +626aaed496ac12bbdb68a86b46871a1f.svg +66f6c781fe86c346fbaf3390618668fc.svg diff --git a/assets/client_test/developers.html b/assets/client_test/developers.html index 2a4402d7..1673e982 100644 --- a/assets/client_test/developers.html +++ b/assets/client_test/developers.html @@ -26,7 +26,6 @@ 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); diff --git a/assets/client_test/index.html b/assets/client_test/index.html index 7a3e4695..da6e2854 100644 --- a/assets/client_test/index.html +++ b/assets/client_test/index.html @@ -1,80 +1,78 @@ - - - - Discord Test Client - - - - - - -
- - - - - - - - - + }, 1000) + */ + + + + + + +
+ + + + + + + + \ No newline at end of file diff --git a/assets/preload-plugins/autoRegister.js b/assets/preload-plugins/autoRegister.js deleted file mode 100644 index bb0b903d..00000000 --- a/assets/preload-plugins/autoRegister.js +++ /dev/null @@ -1,62 +0,0 @@ -// 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/assets/preload-plugins/checkLocale.js b/assets/preload-plugins/checkLocale.js new file mode 100644 index 00000000..0fbc73ee --- /dev/null +++ b/assets/preload-plugins/checkLocale.js @@ -0,0 +1,46 @@ +// 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 supportedLocales = [ + "bg", + "cs", + "da", + "de", + "el", + "en-GB", + "es-ES", + "fi", + "fr", + "hi", + "hr", + "hu", + "it", + "ja", + "ko", + "lt", + "nl", + "no", + "pl", + "pt-BR", + "ro", + "ru", + "sv-SE", + "th", + "tr", + "uk", + "vi", + "zh-CN", + "zh-TW" +]; + +const settings = JSON.parse(localStorage.getItem("UserSettingsStore")); +if (settings && !supportedLocales.includes(settings.locale)) { + // fix client locale wrong and client not loading at all + settings.locale = "en-US"; + localStorage.setItem("UserSettingsStore", JSON.stringify(settings)); +} \ No newline at end of file diff --git a/assets/preload-plugins/loginRedirect.js b/assets/preload-plugins/loginRedirect.js index c527d79d..cda4da44 100644 --- a/assets/preload-plugins/loginRedirect.js +++ b/assets/preload-plugins/loginRedirect.js @@ -1,17 +1,16 @@ -if (window.location.hostname == "127.0.0.1" || window.location.hostname == "localhost") - throw "disabling loginRedirect because localhost"; +if (window.location.hostname !== "127.0.0.1" && window.location.hostname !== "localhost") { + const redirectIfOnLogin = () => { + const path = window.location.pathname; + if (path == "/login" || path == "/register" || !localStorage.getItem("token")) { + window.location.pathname = "/login"; + //window.location.reload(); + } + }; -const redirectIfOnLogin = () => { - const path = window.location.pathname; - if (path == "/login" || path == "/register" || !localStorage.getItem("token")) { - window.location.pathname = "/login"; - //window.location.reload(); - } -}; + const observer = new MutationObserver((mutations) => { + redirectIfOnLogin(); + }); + observer.observe(document, { subtree: true, childList: true }); -const observer = new MutationObserver((mutations) => { redirectIfOnLogin(); -}); -observer.observe(document, { subtree: true, childList: true }); - -redirectIfOnLogin(); \ No newline at end of file +} \ No newline at end of file diff --git a/assets/public/checkLocale.js b/assets/public/checkLocale.js deleted file mode 100644 index 016d66c8..00000000 --- a/assets/public/checkLocale.js +++ /dev/null @@ -1,47 +0,0 @@ - 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 supportedLocales = [ - "bg", - "cs", - "da", - "de", - "el", - "en-GB", - "es-ES", - "fi", - "fr", - "hi", - "hr", - "hu", - "it", - "ja", - "ko", - "lt", - "nl", - "no", - "pl", - "pt-BR", - "ro", - "ru", - "sv-SE", - "th", - "tr", - "uk", - "vi", - "zh-CN", - "zh-TW" - ]; - - const settings = JSON.parse(localStorage.getItem("UserSettingsStore")); - if (settings && !supportedLocales.includes(settings.locale)) { - // fix client locale wrong and client not loading at all - settings.locale = "en-US"; - localStorage.setItem("UserSettingsStore", JSON.stringify(settings)); - } \ No newline at end of file -- cgit 1.4.1