From 12ce7c21c912b747a3fd1b30f22e4478ac5c092a Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:41:11 +0200 Subject: [PATCH 01/12] use mw.config for minecraft.wiki --- websites/M/Minecraft Wiki/presence.ts | 156 +++++++++++++++----------- websites/M/Minecraft Wiki/util.ts | 41 ------- 2 files changed, 89 insertions(+), 108 deletions(-) delete mode 100644 websites/M/Minecraft Wiki/util.ts diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index f2e813d6fa99..cdbf28b67f0e 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -1,15 +1,14 @@ -import { getUserNamespace, getTalkNamespace } from "./util"; - const presence = new Presence({ clientId: "1232903356025143297", }), - browsingTimestamp = Math.floor(Date.now() / 1000); + browsingTimestamp = Math.floor(Date.now() / 1000), + veactionLast = null; function hasPermissions(): boolean { return !document.querySelector(".permissions-errors"); } -presence.on("UpdateData", async () => { +async function prepare(): Promise { const presenceData: PresenceData = { startTimestamp: browsingTimestamp, }, @@ -38,27 +37,29 @@ presence.on("UpdateData", async () => { btnViewThread: "apple.btnViewThread", viewWatchlist: "minecraft wiki.viewWatchlist", }), + mwConfig = await presence.getPageletiable<{ + wgPageName: string, + wgNamespaceNumber: number, + wgTitle: string, + wgCanonicalSpecialPageName: string | false, + wgRelevantPageName: string, + wgRelevantUserName: string?, + wgIsMainPage: boolean? + }>('mw"]["config"]["values'), mainPath = pathname.split("/").filter(Boolean)[1] ?? "/", - pageTitle = document.querySelector( - "meta[property='og:title']" - )?.content, - specialNamespace = new URL( - document.querySelector("#t-specialpages a").href - ).pathname - .split("/") - .filter(Boolean)[1] - .match(/.*(?=:[^_])/)?.[0], - userNamespace = await getUserNamespace(), - talkNamespace = await getTalkNamespace(), - currentNamespace = mainPath.match(/.*(?=:[^_])/)?.[0] ?? ""; + pageTitle = mwConfig.wgPageName.replace(/_/g, ""); + + veactionLast = searchParams.get("veaction"); presenceData.largeImageKey = getComputedStyle( document.querySelector(".mw-wiki-logo") - ).backgroundImage.match(/url\("(.+)"\)/)[1]; + ).backgroundImage.match(/url\("(.+)"\)/)[1] ?? "https://cdn.rcd.gg/PreMiD/websites/M/Minecraft%20Wiki/assets/logo.png"; if ( searchParams.get("action") === "edit" || - searchParams.get("veaction") === "edit" + searchParams.get("action") === "submit" || + searchParams.get("veaction") === "edit" || + searchParams.get("veaction") === "editsource" ) { presenceData.details = hasPermissions() ? strings.editing @@ -78,67 +79,88 @@ presence.on("UpdateData", async () => { } else if (searchParams.get("search")) { presenceData.details = strings.search; presenceData.state = searchParams.get("search"); - } else if (mainPath === "/") presenceData.details = strings.viewHome; - else if (currentNamespace === userNamespace) { + } else if (mwConfig.wgNamespaceNumber === 2) { + // User namespace presenceData.details = strings.viewUser; - presenceData.state = pageTitle.slice( - decodeURIComponent(userNamespace).length + 1 - ); + presenceData.state = mwConfig.wgTitle; presenceData.buttons = [{ label: strings.buttonViewProfile, url: href }]; - } else if ( - currentNamespace.toLowerCase().includes(talkNamespace.toLowerCase()) - ) { + } else if (mwConfig.wgNamespaceNumber % 2 === 1) { + // All talk namespaces presenceData.details = strings.viewAThread; presenceData.state = - currentNamespace === talkNamespace - ? document.querySelector(".mw-page-title-main") + mwConfig.wgNamespaceNumber === 1 + ? mwConfig.wgTitle : pageTitle; presenceData.buttons = [{ label: strings.btnViewThread, url: href }]; - } else if (currentNamespace === specialNamespace) { - if (document.querySelector("#mw-prefs-form")) - // Preferences (Special:Preferences) - presenceData.details = strings.advancedSettings; - else if (document.querySelector("#mw-watchlist-form")) - // Subscriptions (Special:Watchlist) - presenceData.details = strings.viewWatchlist; - else if (document.querySelector(".mw-rcfilters-head")) { - // Recent changes (Special:RecentChanges, Special:RecentChangesLinked) - presenceData.details = strings.viewRecentChanges; - presenceData.state = document.querySelector( - "#mw-content-subtitle a" - ); - } else if (document.querySelector("#movepage")) { - // Moving a page (Special:MovePage) - presenceData.details = strings.moving; - presenceData.state = document.querySelector( - "#mw-content-subtitle a" - ); - } else if (document.querySelector("#userloginForm")) - // Logging in (Special:UserLogin, Special:CreateAccount) - presenceData.details = strings.login; - else if (document.querySelector("#mw-upload-form")) - // Upload a file (Special:Upload) - presenceData.details = strings.upload; - else if ( - document.querySelector(".mw-contributions-user-tools") - ) { - // Contributions (Special:Contributions) - presenceData.details = strings.viewContributionsOf; - presenceData.state = pageTitle.split("/").slice(1).join("/"); - } else { - presenceData.details = strings.viewAPage; - presenceData.state = pageTitle; + } else if (mwConfig.wgNamespaceNumber === -1) { + // Special namespace + switch (mwConfig.wgCanonicalSpecialPageName) { + case "Preferences": + // Preferences (Special:Preferences) + presenceData.details = strings.advancedSettings; + break; + case "Watchlist": + // Subscriptions (Special:Watchlist) + presenceData.details = strings.viewWatchlist; + break; + case "Recentchangeslinked": + // Related changes (Special:RecentChangesLinked) + presenceData.state = mwConfig.wgRelevantPageName.replace(/_/g, ''); + case "Recentchanges": + // Recent changes (Special:RecentChanges) + presenceData.details = strings.viewRecentChanges; + break; + case "Movepage": + // Moving a page (Special:MovePage) + presenceData.details = strings.moving; + presenceData.state = mwConfig.wgRelevantPageName.replace(/_/g, ''); + break; + case "Userlogin": + case "CreateAccount": + // Logging in (Special:UserLogin, Special:CreateAccount) + presenceData.details = strings.login; + break; + case "Upload": + // Upload a file (Special:Upload) + presenceData.details = strings.upload; + presenceData.state = searchParams.get("wpDestFile"); + break; + case "Contributions": + // Contributions (Special:Contributions) + presenceData.details = strings.viewContributionsOf; + presenceData.state = mwConfig.wgRelevantUserName; + break; + default: + presenceData.details = strings.viewAPage; + presenceData.state = pageTitle; } - } else if (currentNamespace) { - const namespace = decodeURIComponent(currentNamespace); + } else if (mwConfig.wgNamespaceNumber) { + // Not main namespace + const namespace = pageTitle.split(':')[0]; presenceData.details = `${strings.readingAbout} ${namespace}`; - presenceData.state = pageTitle.slice(namespace.length + 1); + presenceData.state = mwConfig.wgTitle; presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; + } else if ( + mainPath === "/" || + mwConfig.wgIsMainPage + ) { + // Main Page + presenceData.details = strings.viewHome; } else { presenceData.details = strings.viewAPage; presenceData.state = pageTitle; presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; } + return presenceData; +} - presence.setActivity(presenceData); -}); +(async (): Promise => { + var presenceData = await prepare(); + presence.on("UpdateData", async () => { + const veaction = new URLSearchParams(document.location.search).get("veaction"); + if ( veactionLast !== veaction ) { + presenceData = await prepare(); + } + else presence.setActivity(presenceData); + }); +})(); \ No newline at end of file diff --git a/websites/M/Minecraft Wiki/util.ts b/websites/M/Minecraft Wiki/util.ts deleted file mode 100644 index 77ea79575325..000000000000 --- a/websites/M/Minecraft Wiki/util.ts +++ /dev/null @@ -1,41 +0,0 @@ -const promiseCache = new Map>(); - -export async function getUserNamespace(): Promise { - const cached = sessionStorage.getItem("PMD_UserNamespace"); - if (cached) return cached; - let response: Response; - const promise = promiseCache.get("getUserNamespace"); - if (promise) response = await promise; - else { - const promise = fetch( - `https://${document.location.hostname}/w/User:Example` - ); - promiseCache.set("getUserNamespace", promise); - response = await promise; - } - sessionStorage.setItem( - "PMD_UserNamespace", - new URL(response.url).pathname.split("/").filter(Boolean)[1].split(":")[0] - ); - return sessionStorage.getItem("PMD_UserNamespace"); -} - -export async function getTalkNamespace(): Promise { - const cached = sessionStorage.getItem("PMD_TalkNamespace"); - if (cached) return cached; - let response: Response; - const promise = promiseCache.get("getTalkNamespace"); - if (promise) response = await promise; - else { - const promise = fetch( - `https://${document.location.hostname}/w/Talk:Example` - ); - promiseCache.set("getTalkNamespace", promise); - response = await promise; - } - sessionStorage.setItem( - "PMD_TalkNamespace", - new URL(response.url).pathname.split("/").filter(Boolean)[1].split(":")[0] - ); - return sessionStorage.getItem("PMD_TalkNamespace"); -} From 4ebdfbb2b75cbb6fb2ca4d450bbe11c6ff09d05d Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:54:09 +0200 Subject: [PATCH 02/12] fix some stuff --- websites/M/Minecraft Wiki/metadata.json | 2 +- websites/M/Minecraft Wiki/presence.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/websites/M/Minecraft Wiki/metadata.json b/websites/M/Minecraft Wiki/metadata.json index 1d10d5ae7350..79ff75c0a535 100644 --- a/websites/M/Minecraft Wiki/metadata.json +++ b/websites/M/Minecraft Wiki/metadata.json @@ -22,7 +22,7 @@ "*://minecraft.wiki/*", "*://*.minecraft.wiki/*" ], - "version": "1.0.1", + "version": "1.0.2", "logo": "https://cdn.rcd.gg/PreMiD/websites/M/Minecraft%20Wiki/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/M/Minecraft%20Wiki/assets/thumbnail.png", "color": "#3776A9", diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index cdbf28b67f0e..220d5ca46d58 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -1,8 +1,8 @@ const presence = new Presence({ clientId: "1232903356025143297", }), - browsingTimestamp = Math.floor(Date.now() / 1000), - veactionLast = null; + browsingTimestamp = Math.floor(Date.now() / 1000); +var veactionLast: string? = null; function hasPermissions(): boolean { return !document.querySelector(".permissions-errors"); @@ -38,13 +38,13 @@ async function prepare(): Promise { viewWatchlist: "minecraft wiki.viewWatchlist", }), mwConfig = await presence.getPageletiable<{ - wgPageName: string, - wgNamespaceNumber: number, - wgTitle: string, - wgCanonicalSpecialPageName: string | false, - wgRelevantPageName: string, - wgRelevantUserName: string?, - wgIsMainPage: boolean? + wgPageName: string; + wgNamespaceNumber: number; + wgTitle: string; + wgCanonicalSpecialPageName: string | false; + wgRelevantPageName: string; + wgRelevantUserName: string?; + wgIsMainPage: boolean?; }>('mw"]["config"]["values'), mainPath = pathname.split("/").filter(Boolean)[1] ?? "/", pageTitle = mwConfig.wgPageName.replace(/_/g, ""); From dbdf0816ed4e7118e3b87dbc28a833ea2631930f Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:57:57 +0200 Subject: [PATCH 03/12] fix typescript --- websites/M/Minecraft Wiki/presence.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index 220d5ca46d58..78dcf9939a23 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -2,7 +2,7 @@ const presence = new Presence({ clientId: "1232903356025143297", }), browsingTimestamp = Math.floor(Date.now() / 1000); -var veactionLast: string? = null; +var veactionLast: string | null = null; function hasPermissions(): boolean { return !document.querySelector(".permissions-errors"); @@ -43,8 +43,8 @@ async function prepare(): Promise { wgTitle: string; wgCanonicalSpecialPageName: string | false; wgRelevantPageName: string; - wgRelevantUserName: string?; - wgIsMainPage: boolean?; + wgRelevantUserName: string | null; + wgIsMainPage: boolean | null; }>('mw"]["config"]["values'), mainPath = pathname.split("/").filter(Boolean)[1] ?? "/", pageTitle = mwConfig.wgPageName.replace(/_/g, ""); From 359e9ab7d096e030c672fa2b59ce3290b42413b7 Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Mon, 29 Apr 2024 00:01:22 +0200 Subject: [PATCH 04/12] remove fallthrough --- websites/M/Minecraft Wiki/presence.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index 78dcf9939a23..e740f6ef8673 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -103,13 +103,15 @@ async function prepare(): Promise { // Subscriptions (Special:Watchlist) presenceData.details = strings.viewWatchlist; break; - case "Recentchangeslinked": - // Related changes (Special:RecentChangesLinked) - presenceData.state = mwConfig.wgRelevantPageName.replace(/_/g, ''); case "Recentchanges": // Recent changes (Special:RecentChanges) presenceData.details = strings.viewRecentChanges; break; + case "Recentchangeslinked": + // Related changes (Special:RecentChangesLinked) + presenceData.details = strings.viewRecentChanges; + presenceData.state = mwConfig.wgRelevantPageName.replace(/_/g, ''); + break; case "Movepage": // Moving a page (Special:MovePage) presenceData.details = strings.moving; From 7de8bd48d34ef7cf086e48d2f053a79494807f6c Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Mon, 29 Apr 2024 00:26:50 +0200 Subject: [PATCH 05/12] use getPageVariable --- websites/M/Minecraft Wiki/presence.ts | 74 ++++++++++++++++----------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index e740f6ef8673..1b119c8fa7e4 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -2,7 +2,7 @@ const presence = new Presence({ clientId: "1232903356025143297", }), browsingTimestamp = Math.floor(Date.now() / 1000); -var veactionLast: string | null = null; +let veactionLast: string | null = null; function hasPermissions(): boolean { return !document.querySelector(".permissions-errors"); @@ -37,17 +37,33 @@ async function prepare(): Promise { btnViewThread: "apple.btnViewThread", viewWatchlist: "minecraft wiki.viewWatchlist", }), - mwConfig = await presence.getPageletiable<{ - wgPageName: string; - wgNamespaceNumber: number; - wgTitle: string; - wgCanonicalSpecialPageName: string | false; - wgRelevantPageName: string; - wgRelevantUserName: string | null; - wgIsMainPage: boolean | null; - }>('mw"]["config"]["values'), + { + "mw.config.values.wgPageName": wgPageName, + "mw.config.values.wgNamespaceNumber": wgNamespaceNumber, + "mw.config.values.wgTitle": wgTitle, + "mw.config.values.wgCanonicalSpecialPageName": wgCanonicalSpecialPageName, + "mw.config.values.wgRelevantPageName": wgRelevantPageName, + "mw.config.values.wgRelevantUserName": wgRelevantUserName, + "mw.config.values.wgIsMainPage": wgIsMainPage + } = await presence.getPageVariable<{ + "mw.config.values.wgPageName": string, + "mw.config.values.wgNamespaceNumber": number, + "mw.config.values.wgTitle": string, + "mw.config.values.wgCanonicalSpecialPageName": string | false, + "mw.config.values.wgRelevantPageName": string, + "mw.config.values.wgRelevantUserName": string | null, + "mw.config.values.wgIsMainPage": boolean | null + }>([ + "mw.config.values.wgPageName", + "mw.config.values.wgNamespaceNumber", + "mw.config.values.wgTitle", + "mw.config.values.wgCanonicalSpecialPageName", + "mw.config.values.wgRelevantPageName", + "mw.config.values.wgRelevantUserName", + "mw.config.values.wgIsMainPage" + ]), mainPath = pathname.split("/").filter(Boolean)[1] ?? "/", - pageTitle = mwConfig.wgPageName.replace(/_/g, ""); + pageTitle = wgPageName.replace(/_/g, " "); veactionLast = searchParams.get("veaction"); @@ -79,22 +95,22 @@ async function prepare(): Promise { } else if (searchParams.get("search")) { presenceData.details = strings.search; presenceData.state = searchParams.get("search"); - } else if (mwConfig.wgNamespaceNumber === 2) { + } else if (wgNamespaceNumber === 2) { // User namespace presenceData.details = strings.viewUser; - presenceData.state = mwConfig.wgTitle; + presenceData.state = wgTitle; presenceData.buttons = [{ label: strings.buttonViewProfile, url: href }]; - } else if (mwConfig.wgNamespaceNumber % 2 === 1) { + } else if (wgNamespaceNumber % 2 === 1) { // All talk namespaces presenceData.details = strings.viewAThread; presenceData.state = - mwConfig.wgNamespaceNumber === 1 - ? mwConfig.wgTitle + wgNamespaceNumber === 1 + ? wgTitle : pageTitle; presenceData.buttons = [{ label: strings.btnViewThread, url: href }]; - } else if (mwConfig.wgNamespaceNumber === -1) { + } else if (wgNamespaceNumber === -1) { // Special namespace - switch (mwConfig.wgCanonicalSpecialPageName) { + switch (wgCanonicalSpecialPageName) { case "Preferences": // Preferences (Special:Preferences) presenceData.details = strings.advancedSettings; @@ -110,12 +126,12 @@ async function prepare(): Promise { case "Recentchangeslinked": // Related changes (Special:RecentChangesLinked) presenceData.details = strings.viewRecentChanges; - presenceData.state = mwConfig.wgRelevantPageName.replace(/_/g, ''); + presenceData.state = wgRelevantPageName.replace(/_/g, " "); break; case "Movepage": // Moving a page (Special:MovePage) presenceData.details = strings.moving; - presenceData.state = mwConfig.wgRelevantPageName.replace(/_/g, ''); + presenceData.state = wgRelevantPageName.replace(/_/g, " "); break; case "Userlogin": case "CreateAccount": @@ -130,25 +146,23 @@ async function prepare(): Promise { case "Contributions": // Contributions (Special:Contributions) presenceData.details = strings.viewContributionsOf; - presenceData.state = mwConfig.wgRelevantUserName; + presenceData.state = wgRelevantUserName; break; default: presenceData.details = strings.viewAPage; presenceData.state = pageTitle; } - } else if (mwConfig.wgNamespaceNumber) { + } else if (wgNamespaceNumber) { // Not main namespace - const namespace = pageTitle.split(':')[0]; + const namespace = pageTitle.split(":")[0]; presenceData.details = `${strings.readingAbout} ${namespace}`; - presenceData.state = mwConfig.wgTitle; + presenceData.state = wgTitle; presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; } else if ( mainPath === "/" || - mwConfig.wgIsMainPage - ) { - // Main Page - presenceData.details = strings.viewHome; - } else { + wgIsMainPage + ) presenceData.details = strings.viewHome; + else { presenceData.details = strings.viewAPage; presenceData.state = pageTitle; presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; @@ -157,7 +171,7 @@ async function prepare(): Promise { } (async (): Promise => { - var presenceData = await prepare(); + let presenceData = await prepare(); presence.on("UpdateData", async () => { const veaction = new URLSearchParams(document.location.search).get("veaction"); if ( veactionLast !== veaction ) { From 3d6f300c58d8dfa0602571649d482e4777b65e48 Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Mon, 29 Apr 2024 00:28:12 +0200 Subject: [PATCH 06/12] fix getPageVariable --- websites/M/Minecraft Wiki/presence.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index 1b119c8fa7e4..6a5538753e8e 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -53,7 +53,7 @@ async function prepare(): Promise { "mw.config.values.wgRelevantPageName": string, "mw.config.values.wgRelevantUserName": string | null, "mw.config.values.wgIsMainPage": boolean | null - }>([ + }>( "mw.config.values.wgPageName", "mw.config.values.wgNamespaceNumber", "mw.config.values.wgTitle", @@ -61,7 +61,7 @@ async function prepare(): Promise { "mw.config.values.wgRelevantPageName", "mw.config.values.wgRelevantUserName", "mw.config.values.wgIsMainPage" - ]), + ), mainPath = pathname.split("/").filter(Boolean)[1] ?? "/", pageTitle = wgPageName.replace(/_/g, " "); From 5edc262e4a614816758937a15abb79065ddcc06b Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Mon, 29 Apr 2024 00:30:25 +0200 Subject: [PATCH 07/12] fix for lint --- websites/M/Minecraft Wiki/presence.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index 6a5538753e8e..2aa5f689fe31 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -174,9 +174,7 @@ async function prepare(): Promise { let presenceData = await prepare(); presence.on("UpdateData", async () => { const veaction = new URLSearchParams(document.location.search).get("veaction"); - if ( veactionLast !== veaction ) { - presenceData = await prepare(); - } + if ( veactionLast !== veaction ) presenceData = await prepare(); else presence.setActivity(presenceData); }); })(); \ No newline at end of file From 39505545f932f469ce1f8e2bafbab71797aa0702 Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Mon, 29 Apr 2024 00:52:38 +0200 Subject: [PATCH 08/12] fix lint warnings --- websites/M/Minecraft Wiki/presence.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index 2aa5f689fe31..027273b32be5 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -62,7 +62,6 @@ async function prepare(): Promise { "mw.config.values.wgRelevantUserName", "mw.config.values.wgIsMainPage" ), - mainPath = pathname.split("/").filter(Boolean)[1] ?? "/", pageTitle = wgPageName.replace(/_/g, " "); veactionLast = searchParams.get("veaction"); @@ -154,14 +153,10 @@ async function prepare(): Promise { } } else if (wgNamespaceNumber) { // Not main namespace - const namespace = pageTitle.split(":")[0]; - presenceData.details = `${strings.readingAbout} ${namespace}`; + presenceData.details = `${strings.readingAbout} ${pageTitle.split(":")[0]}`; presenceData.state = wgTitle; presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; - } else if ( - mainPath === "/" || - wgIsMainPage - ) presenceData.details = strings.viewHome; + } else if (wgIsMainPage) presenceData.details = strings.viewHome; else { presenceData.details = strings.viewAPage; presenceData.state = pageTitle; @@ -173,8 +168,8 @@ async function prepare(): Promise { (async (): Promise => { let presenceData = await prepare(); presence.on("UpdateData", async () => { - const veaction = new URLSearchParams(document.location.search).get("veaction"); - if ( veactionLast !== veaction ) presenceData = await prepare(); + if ( veactionLast !== new URLSearchParams(document.location.search).get("veaction") ) + presenceData = await prepare(); else presence.setActivity(presenceData); }); })(); \ No newline at end of file From 8bcb27160b13425d3e0c689a91507fbfcb63d19b Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Mon, 29 Apr 2024 00:54:00 +0200 Subject: [PATCH 09/12] remove pathname --- websites/M/Minecraft Wiki/presence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index 027273b32be5..e52b1288fafc 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -12,7 +12,7 @@ async function prepare(): Promise { const presenceData: PresenceData = { startTimestamp: browsingTimestamp, }, - { href, pathname, search } = document.location, + { href, search } = document.location, searchParams = new URLSearchParams(search), strings = await presence.getStrings({ viewHome: "general.viewHome", From 1c69b7dcf89450254d6c8c81e18c7c2fac57be15 Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Mon, 29 Apr 2024 00:57:36 +0200 Subject: [PATCH 10/12] why is this still failing? --- websites/M/Minecraft Wiki/presence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index e52b1288fafc..1c335d7fabf2 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -168,7 +168,7 @@ async function prepare(): Promise { (async (): Promise => { let presenceData = await prepare(); presence.on("UpdateData", async () => { - if ( veactionLast !== new URLSearchParams(document.location.search).get("veaction") ) + if (veactionLast !== new URLSearchParams(document.location.search).get("veaction")) presenceData = await prepare(); else presence.setActivity(presenceData); }); From b5ccb0e92975aadeee931793bb0009c08920c2dc Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Mon, 29 Apr 2024 01:17:44 +0200 Subject: [PATCH 11/12] prettier fixed maybe? --- websites/M/Minecraft Wiki/presence.ts | 324 +++++++++++++------------- 1 file changed, 163 insertions(+), 161 deletions(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index 1c335d7fabf2..ad651765404c 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -1,175 +1,177 @@ const presence = new Presence({ - clientId: "1232903356025143297", - }), - browsingTimestamp = Math.floor(Date.now() / 1000); + clientId: "1232903356025143297", +}), +browsingTimestamp = Math.floor(Date.now() / 1000); let veactionLast: string | null = null; function hasPermissions(): boolean { - return !document.querySelector(".permissions-errors"); +return !document.querySelector(".permissions-errors"); } async function prepare(): Promise { - const presenceData: PresenceData = { - startTimestamp: browsingTimestamp, - }, - { href, search } = document.location, - searchParams = new URLSearchParams(search), - strings = await presence.getStrings({ - viewHome: "general.viewHome", - viewUser: "general.viewUser", - viewAThread: "general.viewAThread", - buttonViewProfile: "general.buttonViewProfile", - editing: "general.editing", - advancedSettings: "google classroom.settings", - viewAPage: "general.viewAPage", - buttonViewPage: "general.buttonViewPage", - readingAbout: "general.readingAbout", - moving: "minecraft wiki.moving", - viewSourceOf: "minecraft wiki.viewSourceOf", - viewHistory: "minecraft wiki.viewHistory", - changeProtection: "minecraft wiki.changeProtection", - viewProtection: "minecraft wiki.viewProtection", - search: "general.search", - upload: "youtube.upload", - viewContributionsOf: "minecraft wiki.viewContributionsOf", - viewRecentChanges: "minecraft wiki.viewRecentChanges", - login: "kahoot.login", - btnViewThread: "apple.btnViewThread", - viewWatchlist: "minecraft wiki.viewWatchlist", - }), - { - "mw.config.values.wgPageName": wgPageName, - "mw.config.values.wgNamespaceNumber": wgNamespaceNumber, - "mw.config.values.wgTitle": wgTitle, - "mw.config.values.wgCanonicalSpecialPageName": wgCanonicalSpecialPageName, - "mw.config.values.wgRelevantPageName": wgRelevantPageName, - "mw.config.values.wgRelevantUserName": wgRelevantUserName, - "mw.config.values.wgIsMainPage": wgIsMainPage - } = await presence.getPageVariable<{ - "mw.config.values.wgPageName": string, - "mw.config.values.wgNamespaceNumber": number, - "mw.config.values.wgTitle": string, - "mw.config.values.wgCanonicalSpecialPageName": string | false, - "mw.config.values.wgRelevantPageName": string, - "mw.config.values.wgRelevantUserName": string | null, - "mw.config.values.wgIsMainPage": boolean | null - }>( - "mw.config.values.wgPageName", - "mw.config.values.wgNamespaceNumber", - "mw.config.values.wgTitle", - "mw.config.values.wgCanonicalSpecialPageName", - "mw.config.values.wgRelevantPageName", - "mw.config.values.wgRelevantUserName", - "mw.config.values.wgIsMainPage" - ), - pageTitle = wgPageName.replace(/_/g, " "); - - veactionLast = searchParams.get("veaction"); +const presenceData: PresenceData = { + startTimestamp: browsingTimestamp, + }, + { href, search } = document.location, + searchParams = new URLSearchParams(search), + strings = await presence.getStrings({ + viewHome: "general.viewHome", + viewUser: "general.viewUser", + viewAThread: "general.viewAThread", + buttonViewProfile: "general.buttonViewProfile", + editing: "general.editing", + advancedSettings: "google classroom.settings", + viewAPage: "general.viewAPage", + buttonViewPage: "general.buttonViewPage", + readingAbout: "general.readingAbout", + moving: "minecraft wiki.moving", + viewSourceOf: "minecraft wiki.viewSourceOf", + viewHistory: "minecraft wiki.viewHistory", + changeProtection: "minecraft wiki.changeProtection", + viewProtection: "minecraft wiki.viewProtection", + search: "general.search", + upload: "youtube.upload", + viewContributionsOf: "minecraft wiki.viewContributionsOf", + viewRecentChanges: "minecraft wiki.viewRecentChanges", + login: "kahoot.login", + btnViewThread: "apple.btnViewThread", + viewWatchlist: "minecraft wiki.viewWatchlist", + }), + { + "mw.config.values.wgPageName": wgPageName, + "mw.config.values.wgNamespaceNumber": wgNamespaceNumber, + "mw.config.values.wgTitle": wgTitle, + "mw.config.values.wgCanonicalSpecialPageName": wgCanonicalSpecialPageName, + "mw.config.values.wgRelevantPageName": wgRelevantPageName, + "mw.config.values.wgRelevantUserName": wgRelevantUserName, + "mw.config.values.wgIsMainPage": wgIsMainPage, + } = await presence.getPageVariable<{ + "mw.config.values.wgPageName": string; + "mw.config.values.wgNamespaceNumber": number; + "mw.config.values.wgTitle": string; + "mw.config.values.wgCanonicalSpecialPageName": string | false; + "mw.config.values.wgRelevantPageName": string; + "mw.config.values.wgRelevantUserName": string | null; + "mw.config.values.wgIsMainPage": boolean | null; + }>( + "mw.config.values.wgPageName", + "mw.config.values.wgNamespaceNumber", + "mw.config.values.wgTitle", + "mw.config.values.wgCanonicalSpecialPageName", + "mw.config.values.wgRelevantPageName", + "mw.config.values.wgRelevantUserName", + "mw.config.values.wgIsMainPage" + ), + pageTitle = wgPageName.replace(/_/g, " "); + +veactionLast = searchParams.get("veaction"); - presenceData.largeImageKey = getComputedStyle( +presenceData.largeImageKey = + getComputedStyle( document.querySelector(".mw-wiki-logo") - ).backgroundImage.match(/url\("(.+)"\)/)[1] ?? "https://cdn.rcd.gg/PreMiD/websites/M/Minecraft%20Wiki/assets/logo.png"; + ).backgroundImage.match(/url\("(.+)"\)/)[1] ?? + "https://cdn.rcd.gg/PreMiD/websites/M/Minecraft%20Wiki/assets/logo.png"; - if ( - searchParams.get("action") === "edit" || - searchParams.get("action") === "submit" || - searchParams.get("veaction") === "edit" || - searchParams.get("veaction") === "editsource" - ) { - presenceData.details = hasPermissions() - ? strings.editing - : strings.viewSourceOf; - presenceData.state = pageTitle; - } else if (searchParams.get("action") === "history") { - presenceData.details = strings.viewHistory; - presenceData.state = pageTitle; - } else if ( - searchParams.get("action") === "protect" || - searchParams.get("action") === "unprotect" - ) { - presenceData.details = hasPermissions() - ? strings.changeProtection - : strings.viewProtection; - presenceData.state = pageTitle; - } else if (searchParams.get("search")) { - presenceData.details = strings.search; - presenceData.state = searchParams.get("search"); - } else if (wgNamespaceNumber === 2) { - // User namespace - presenceData.details = strings.viewUser; - presenceData.state = wgTitle; - presenceData.buttons = [{ label: strings.buttonViewProfile, url: href }]; - } else if (wgNamespaceNumber % 2 === 1) { - // All talk namespaces - presenceData.details = strings.viewAThread; - presenceData.state = - wgNamespaceNumber === 1 - ? wgTitle - : pageTitle; - presenceData.buttons = [{ label: strings.btnViewThread, url: href }]; - } else if (wgNamespaceNumber === -1) { - // Special namespace - switch (wgCanonicalSpecialPageName) { - case "Preferences": - // Preferences (Special:Preferences) - presenceData.details = strings.advancedSettings; - break; - case "Watchlist": - // Subscriptions (Special:Watchlist) - presenceData.details = strings.viewWatchlist; - break; - case "Recentchanges": - // Recent changes (Special:RecentChanges) - presenceData.details = strings.viewRecentChanges; - break; - case "Recentchangeslinked": - // Related changes (Special:RecentChangesLinked) - presenceData.details = strings.viewRecentChanges; - presenceData.state = wgRelevantPageName.replace(/_/g, " "); - break; - case "Movepage": - // Moving a page (Special:MovePage) - presenceData.details = strings.moving; - presenceData.state = wgRelevantPageName.replace(/_/g, " "); - break; - case "Userlogin": - case "CreateAccount": - // Logging in (Special:UserLogin, Special:CreateAccount) - presenceData.details = strings.login; - break; - case "Upload": - // Upload a file (Special:Upload) - presenceData.details = strings.upload; - presenceData.state = searchParams.get("wpDestFile"); - break; - case "Contributions": - // Contributions (Special:Contributions) - presenceData.details = strings.viewContributionsOf; - presenceData.state = wgRelevantUserName; - break; - default: - presenceData.details = strings.viewAPage; - presenceData.state = pageTitle; - } - } else if (wgNamespaceNumber) { - // Not main namespace - presenceData.details = `${strings.readingAbout} ${pageTitle.split(":")[0]}`; - presenceData.state = wgTitle; - presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; - } else if (wgIsMainPage) presenceData.details = strings.viewHome; - else { - presenceData.details = strings.viewAPage; - presenceData.state = pageTitle; - presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; +if ( + searchParams.get("action") === "edit" || + searchParams.get("action") === "submit" || + searchParams.get("veaction") === "edit" || + searchParams.get("veaction") === "editsource" +) { + presenceData.details = hasPermissions() + ? strings.editing + : strings.viewSourceOf; + presenceData.state = pageTitle; +} else if (searchParams.get("action") === "history") { + presenceData.details = strings.viewHistory; + presenceData.state = pageTitle; +} else if ( + searchParams.get("action") === "protect" || + searchParams.get("action") === "unprotect" +) { + presenceData.details = hasPermissions() + ? strings.changeProtection + : strings.viewProtection; + presenceData.state = pageTitle; +} else if (searchParams.get("search")) { + presenceData.details = strings.search; + presenceData.state = searchParams.get("search"); +} else if (wgNamespaceNumber === 2) { + // User namespace + presenceData.details = strings.viewUser; + presenceData.state = wgTitle; + presenceData.buttons = [{ label: strings.buttonViewProfile, url: href }]; +} else if (wgNamespaceNumber % 2 === 1) { + // All talk namespaces + presenceData.details = strings.viewAThread; + presenceData.state = wgNamespaceNumber === 1 ? wgTitle : pageTitle; + presenceData.buttons = [{ label: strings.btnViewThread, url: href }]; +} else if (wgNamespaceNumber === -1) { + // Special namespace + switch (wgCanonicalSpecialPageName) { + case "Preferences": + // Preferences (Special:Preferences) + presenceData.details = strings.advancedSettings; + break; + case "Watchlist": + // Subscriptions (Special:Watchlist) + presenceData.details = strings.viewWatchlist; + break; + case "Recentchanges": + // Recent changes (Special:RecentChanges) + presenceData.details = strings.viewRecentChanges; + break; + case "Recentchangeslinked": + // Related changes (Special:RecentChangesLinked) + presenceData.details = strings.viewRecentChanges; + presenceData.state = wgRelevantPageName.replace(/_/g, " "); + break; + case "Movepage": + // Moving a page (Special:MovePage) + presenceData.details = strings.moving; + presenceData.state = wgRelevantPageName.replace(/_/g, " "); + break; + case "Userlogin": + case "CreateAccount": + // Logging in (Special:UserLogin, Special:CreateAccount) + presenceData.details = strings.login; + break; + case "Upload": + // Upload a file (Special:Upload) + presenceData.details = strings.upload; + presenceData.state = searchParams.get("wpDestFile"); + break; + case "Contributions": + // Contributions (Special:Contributions) + presenceData.details = strings.viewContributionsOf; + presenceData.state = wgRelevantUserName; + break; + default: + presenceData.details = strings.viewAPage; + presenceData.state = pageTitle; } - return presenceData; +} else if (wgNamespaceNumber) { + // Not main namespace + presenceData.details = `${strings.readingAbout} ${pageTitle.split(":")[0]}`; + presenceData.state = wgTitle; + presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; +} else if (wgIsMainPage) presenceData.details = strings.viewHome; +else { + presenceData.details = strings.viewAPage; + presenceData.state = pageTitle; + presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; +} +return presenceData; } (async (): Promise => { - let presenceData = await prepare(); - presence.on("UpdateData", async () => { - if (veactionLast !== new URLSearchParams(document.location.search).get("veaction")) - presenceData = await prepare(); - else presence.setActivity(presenceData); - }); -})(); \ No newline at end of file +let presenceData = await prepare(); +presence.on("UpdateData", async () => { + if ( + veactionLast !== + new URLSearchParams(document.location.search).get("veaction") + ) + presenceData = await prepare(); + else presence.setActivity(presenceData); +}); +})(); From c501b03204f7b25ac62aac955ce67d57fe0dcd1c Mon Sep 17 00:00:00 2001 From: MarkusRost <37275477+Markus-Rost@users.noreply.github.com> Date: Mon, 29 Apr 2024 01:26:30 +0200 Subject: [PATCH 12/12] arg --- websites/M/Minecraft Wiki/presence.ts | 324 +++++++++++++------------- 1 file changed, 162 insertions(+), 162 deletions(-) diff --git a/websites/M/Minecraft Wiki/presence.ts b/websites/M/Minecraft Wiki/presence.ts index ad651765404c..fff6fd302d21 100644 --- a/websites/M/Minecraft Wiki/presence.ts +++ b/websites/M/Minecraft Wiki/presence.ts @@ -1,177 +1,177 @@ const presence = new Presence({ - clientId: "1232903356025143297", -}), -browsingTimestamp = Math.floor(Date.now() / 1000); + clientId: "1232903356025143297", + }), + browsingTimestamp = Math.floor(Date.now() / 1000); let veactionLast: string | null = null; function hasPermissions(): boolean { -return !document.querySelector(".permissions-errors"); + return !document.querySelector(".permissions-errors"); } async function prepare(): Promise { -const presenceData: PresenceData = { - startTimestamp: browsingTimestamp, - }, - { href, search } = document.location, - searchParams = new URLSearchParams(search), - strings = await presence.getStrings({ - viewHome: "general.viewHome", - viewUser: "general.viewUser", - viewAThread: "general.viewAThread", - buttonViewProfile: "general.buttonViewProfile", - editing: "general.editing", - advancedSettings: "google classroom.settings", - viewAPage: "general.viewAPage", - buttonViewPage: "general.buttonViewPage", - readingAbout: "general.readingAbout", - moving: "minecraft wiki.moving", - viewSourceOf: "minecraft wiki.viewSourceOf", - viewHistory: "minecraft wiki.viewHistory", - changeProtection: "minecraft wiki.changeProtection", - viewProtection: "minecraft wiki.viewProtection", - search: "general.search", - upload: "youtube.upload", - viewContributionsOf: "minecraft wiki.viewContributionsOf", - viewRecentChanges: "minecraft wiki.viewRecentChanges", - login: "kahoot.login", - btnViewThread: "apple.btnViewThread", - viewWatchlist: "minecraft wiki.viewWatchlist", - }), - { - "mw.config.values.wgPageName": wgPageName, - "mw.config.values.wgNamespaceNumber": wgNamespaceNumber, - "mw.config.values.wgTitle": wgTitle, - "mw.config.values.wgCanonicalSpecialPageName": wgCanonicalSpecialPageName, - "mw.config.values.wgRelevantPageName": wgRelevantPageName, - "mw.config.values.wgRelevantUserName": wgRelevantUserName, - "mw.config.values.wgIsMainPage": wgIsMainPage, - } = await presence.getPageVariable<{ - "mw.config.values.wgPageName": string; - "mw.config.values.wgNamespaceNumber": number; - "mw.config.values.wgTitle": string; - "mw.config.values.wgCanonicalSpecialPageName": string | false; - "mw.config.values.wgRelevantPageName": string; - "mw.config.values.wgRelevantUserName": string | null; - "mw.config.values.wgIsMainPage": boolean | null; - }>( - "mw.config.values.wgPageName", - "mw.config.values.wgNamespaceNumber", - "mw.config.values.wgTitle", - "mw.config.values.wgCanonicalSpecialPageName", - "mw.config.values.wgRelevantPageName", - "mw.config.values.wgRelevantUserName", - "mw.config.values.wgIsMainPage" - ), - pageTitle = wgPageName.replace(/_/g, " "); + const presenceData: PresenceData = { + startTimestamp: browsingTimestamp, + }, + { href, search } = document.location, + searchParams = new URLSearchParams(search), + strings = await presence.getStrings({ + viewHome: "general.viewHome", + viewUser: "general.viewUser", + viewAThread: "general.viewAThread", + buttonViewProfile: "general.buttonViewProfile", + editing: "general.editing", + advancedSettings: "google classroom.settings", + viewAPage: "general.viewAPage", + buttonViewPage: "general.buttonViewPage", + readingAbout: "general.readingAbout", + moving: "minecraft wiki.moving", + viewSourceOf: "minecraft wiki.viewSourceOf", + viewHistory: "minecraft wiki.viewHistory", + changeProtection: "minecraft wiki.changeProtection", + viewProtection: "minecraft wiki.viewProtection", + search: "general.search", + upload: "youtube.upload", + viewContributionsOf: "minecraft wiki.viewContributionsOf", + viewRecentChanges: "minecraft wiki.viewRecentChanges", + login: "kahoot.login", + btnViewThread: "apple.btnViewThread", + viewWatchlist: "minecraft wiki.viewWatchlist", + }), + { + "mw.config.values.wgPageName": wgPageName, + "mw.config.values.wgNamespaceNumber": wgNamespaceNumber, + "mw.config.values.wgTitle": wgTitle, + "mw.config.values.wgCanonicalSpecialPageName": wgCanonicalSpecialPageName, + "mw.config.values.wgRelevantPageName": wgRelevantPageName, + "mw.config.values.wgRelevantUserName": wgRelevantUserName, + "mw.config.values.wgIsMainPage": wgIsMainPage, + } = await presence.getPageVariable<{ + "mw.config.values.wgPageName": string; + "mw.config.values.wgNamespaceNumber": number; + "mw.config.values.wgTitle": string; + "mw.config.values.wgCanonicalSpecialPageName": string | false; + "mw.config.values.wgRelevantPageName": string; + "mw.config.values.wgRelevantUserName": string | null; + "mw.config.values.wgIsMainPage": boolean | null; + }>( + "mw.config.values.wgPageName", + "mw.config.values.wgNamespaceNumber", + "mw.config.values.wgTitle", + "mw.config.values.wgCanonicalSpecialPageName", + "mw.config.values.wgRelevantPageName", + "mw.config.values.wgRelevantUserName", + "mw.config.values.wgIsMainPage" + ), + pageTitle = wgPageName.replace(/_/g, " "); -veactionLast = searchParams.get("veaction"); + veactionLast = searchParams.get("veaction"); -presenceData.largeImageKey = - getComputedStyle( - document.querySelector(".mw-wiki-logo") - ).backgroundImage.match(/url\("(.+)"\)/)[1] ?? - "https://cdn.rcd.gg/PreMiD/websites/M/Minecraft%20Wiki/assets/logo.png"; + presenceData.largeImageKey = + getComputedStyle( + document.querySelector(".mw-wiki-logo") + ).backgroundImage.match(/url\("(.+)"\)/)[1] ?? + "https://cdn.rcd.gg/PreMiD/websites/M/Minecraft%20Wiki/assets/logo.png"; -if ( - searchParams.get("action") === "edit" || - searchParams.get("action") === "submit" || - searchParams.get("veaction") === "edit" || - searchParams.get("veaction") === "editsource" -) { - presenceData.details = hasPermissions() - ? strings.editing - : strings.viewSourceOf; - presenceData.state = pageTitle; -} else if (searchParams.get("action") === "history") { - presenceData.details = strings.viewHistory; - presenceData.state = pageTitle; -} else if ( - searchParams.get("action") === "protect" || - searchParams.get("action") === "unprotect" -) { - presenceData.details = hasPermissions() - ? strings.changeProtection - : strings.viewProtection; - presenceData.state = pageTitle; -} else if (searchParams.get("search")) { - presenceData.details = strings.search; - presenceData.state = searchParams.get("search"); -} else if (wgNamespaceNumber === 2) { - // User namespace - presenceData.details = strings.viewUser; - presenceData.state = wgTitle; - presenceData.buttons = [{ label: strings.buttonViewProfile, url: href }]; -} else if (wgNamespaceNumber % 2 === 1) { - // All talk namespaces - presenceData.details = strings.viewAThread; - presenceData.state = wgNamespaceNumber === 1 ? wgTitle : pageTitle; - presenceData.buttons = [{ label: strings.btnViewThread, url: href }]; -} else if (wgNamespaceNumber === -1) { - // Special namespace - switch (wgCanonicalSpecialPageName) { - case "Preferences": - // Preferences (Special:Preferences) - presenceData.details = strings.advancedSettings; - break; - case "Watchlist": - // Subscriptions (Special:Watchlist) - presenceData.details = strings.viewWatchlist; - break; - case "Recentchanges": - // Recent changes (Special:RecentChanges) - presenceData.details = strings.viewRecentChanges; - break; - case "Recentchangeslinked": - // Related changes (Special:RecentChangesLinked) - presenceData.details = strings.viewRecentChanges; - presenceData.state = wgRelevantPageName.replace(/_/g, " "); - break; - case "Movepage": - // Moving a page (Special:MovePage) - presenceData.details = strings.moving; - presenceData.state = wgRelevantPageName.replace(/_/g, " "); - break; - case "Userlogin": - case "CreateAccount": - // Logging in (Special:UserLogin, Special:CreateAccount) - presenceData.details = strings.login; - break; - case "Upload": - // Upload a file (Special:Upload) - presenceData.details = strings.upload; - presenceData.state = searchParams.get("wpDestFile"); - break; - case "Contributions": - // Contributions (Special:Contributions) - presenceData.details = strings.viewContributionsOf; - presenceData.state = wgRelevantUserName; - break; - default: - presenceData.details = strings.viewAPage; - presenceData.state = pageTitle; + if ( + searchParams.get("action") === "edit" || + searchParams.get("action") === "submit" || + searchParams.get("veaction") === "edit" || + searchParams.get("veaction") === "editsource" + ) { + presenceData.details = hasPermissions() + ? strings.editing + : strings.viewSourceOf; + presenceData.state = pageTitle; + } else if (searchParams.get("action") === "history") { + presenceData.details = strings.viewHistory; + presenceData.state = pageTitle; + } else if ( + searchParams.get("action") === "protect" || + searchParams.get("action") === "unprotect" + ) { + presenceData.details = hasPermissions() + ? strings.changeProtection + : strings.viewProtection; + presenceData.state = pageTitle; + } else if (searchParams.get("search")) { + presenceData.details = strings.search; + presenceData.state = searchParams.get("search"); + } else if (wgNamespaceNumber === 2) { + // User namespace + presenceData.details = strings.viewUser; + presenceData.state = wgTitle; + presenceData.buttons = [{ label: strings.buttonViewProfile, url: href }]; + } else if (wgNamespaceNumber % 2 === 1) { + // All talk namespaces + presenceData.details = strings.viewAThread; + presenceData.state = wgNamespaceNumber === 1 ? wgTitle : pageTitle; + presenceData.buttons = [{ label: strings.btnViewThread, url: href }]; + } else if (wgNamespaceNumber === -1) { + // Special namespace + switch (wgCanonicalSpecialPageName) { + case "Preferences": + // Preferences (Special:Preferences) + presenceData.details = strings.advancedSettings; + break; + case "Watchlist": + // Subscriptions (Special:Watchlist) + presenceData.details = strings.viewWatchlist; + break; + case "Recentchanges": + // Recent changes (Special:RecentChanges) + presenceData.details = strings.viewRecentChanges; + break; + case "Recentchangeslinked": + // Related changes (Special:RecentChangesLinked) + presenceData.details = strings.viewRecentChanges; + presenceData.state = wgRelevantPageName.replace(/_/g, " "); + break; + case "Movepage": + // Moving a page (Special:MovePage) + presenceData.details = strings.moving; + presenceData.state = wgRelevantPageName.replace(/_/g, " "); + break; + case "Userlogin": + case "CreateAccount": + // Logging in (Special:UserLogin, Special:CreateAccount) + presenceData.details = strings.login; + break; + case "Upload": + // Upload a file (Special:Upload) + presenceData.details = strings.upload; + presenceData.state = searchParams.get("wpDestFile"); + break; + case "Contributions": + // Contributions (Special:Contributions) + presenceData.details = strings.viewContributionsOf; + presenceData.state = wgRelevantUserName; + break; + default: + presenceData.details = strings.viewAPage; + presenceData.state = pageTitle; + } + } else if (wgNamespaceNumber) { + // Not main namespace + presenceData.details = `${strings.readingAbout} ${pageTitle.split(":")[0]}`; + presenceData.state = wgTitle; + presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; + } else if (wgIsMainPage) presenceData.details = strings.viewHome; + else { + presenceData.details = strings.viewAPage; + presenceData.state = pageTitle; + presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; } -} else if (wgNamespaceNumber) { - // Not main namespace - presenceData.details = `${strings.readingAbout} ${pageTitle.split(":")[0]}`; - presenceData.state = wgTitle; - presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; -} else if (wgIsMainPage) presenceData.details = strings.viewHome; -else { - presenceData.details = strings.viewAPage; - presenceData.state = pageTitle; - presenceData.buttons = [{ label: strings.buttonViewPage, url: href }]; -} -return presenceData; + return presenceData; } (async (): Promise => { -let presenceData = await prepare(); -presence.on("UpdateData", async () => { - if ( - veactionLast !== - new URLSearchParams(document.location.search).get("veaction") - ) - presenceData = await prepare(); - else presence.setActivity(presenceData); -}); + let presenceData = await prepare(); + presence.on("UpdateData", async () => { + if ( + veactionLast !== + new URLSearchParams(document.location.search).get("veaction") + ) + presenceData = await prepare(); + else presence.setActivity(presenceData); + }); })();