From 1e20913db6ee0ef4ce882a31ccbd7faf6d4df528 Mon Sep 17 00:00:00 2001 From: Dark_Ville Date: Thu, 14 Nov 2024 14:34:08 +0100 Subject: [PATCH 1/2] fix(DashNet): prevent memory leak & change to pagevar code --- websites/D/DashNet/metadata.json | 2 +- websites/D/DashNet/presence.ts | 54 +++++++++++++++++--------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/websites/D/DashNet/metadata.json b/websites/D/DashNet/metadata.json index 7bafeb9ca50a..83f2ea8fb8a5 100644 --- a/websites/D/DashNet/metadata.json +++ b/websites/D/DashNet/metadata.json @@ -15,7 +15,7 @@ }, "url": "dashnet.org", "regExp": "([a-z0-9-]+[.])*dashnet[.]org[/]", - "version": "1.3.15", + "version": "1.3.16", "logo": "https://cdn.rcd.gg/PreMiD/websites/D/DashNet/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/D/DashNet/assets/thumbnail.png", "color": "#042B48", diff --git a/websites/D/DashNet/presence.ts b/websites/D/DashNet/presence.ts index 423c7bb1f4ee..51b7ea2dee04 100644 --- a/websites/D/DashNet/presence.ts +++ b/websites/D/DashNet/presence.ts @@ -1,24 +1,33 @@ let presence: Presence, newID: string, latestID: string; function presenceSet(): void { - if (document.location.pathname.includes("/cookieclicker/")) { + if (!latestID && !newID) { + newID = document.location.pathname.includes("/cookieclicker/") + ? "676126246928777250" + : "676120967159742465"; + presence = new Presence({ clientId: newID }); + } + + if ( + document.location.pathname.includes("/cookieclicker/") && + latestID !== "676126246928777250" + ) { presence = new Presence({ clientId: "676126246928777250" }); newID = "676126246928777250"; - } else { + } else if ( + !document.location.pathname.includes("/cookieclicker/") && + latestID !== "676120967159742465" + ) { presence = new Presence({ clientId: "676120967159742465" }); newID = "676120967159742465"; } - - if (newID !== latestID && latestID) { - presence.clearActivity(); - latestID = newID; - } + latestID = newID; } const browsingTimestamp = Math.floor(Date.now() / 1000); presenceSet(); -presence.on("UpdateData", () => { +presence.on("UpdateData", async () => { const presenceData: PresenceData = { largeImageKey: "https://cdn.rcd.gg/PreMiD/websites/D/DashNet/assets/logo.png", @@ -28,23 +37,18 @@ presence.on("UpdateData", () => { presenceSet(); if (document.location.pathname.includes("/cookieclicker/")) { - const cookies = document - .querySelector("#cookies") - .textContent.replace( - document.querySelector("#cookies div").textContent, - "" - ); - if (cookies.includes(" cookies")) presenceData.details = cookies; - else presenceData.details = cookies.replace("cookies", " cookies"); - - presenceData.state = document - .querySelector("#cookies div") - .textContent.replace("per second :", "Per second:"); - presenceData.smallImageKey = - "https://cdn.rcd.gg/PreMiD/websites/D/DashNet/assets/0.png"; - presenceData.smallImageText = `Legacy level: ${ - document.querySelector("#ascendNumber").textContent - }`; + const cookies = await presence.getPageVariable( + "Game.cookies", + "Game.cookiesPs", + "Game.ascendMeterLevel" + ); + presenceData.details = `${ + Math.round(Number(cookies["Game.cookies"]) * 100) / 100 + } cookies`; + presenceData.state = `${ + Math.round(Number(cookies["Game.cookiesPs"]) * 100) / 100 + } cookies per second`; + presenceData.smallImageText = `Legacy level: ${cookies["Game.ascendMeterLevel"]}`; } else if (document.location.pathname === "/") { presenceData.details = "Browsing DashNet's"; presenceData.state = "video games and other fun things"; From ca296f3c35e8bb80925f5f74ffabceffcb25bdb0 Mon Sep 17 00:00:00 2001 From: Dark_Ville Date: Sat, 16 Nov 2024 09:09:04 +0100 Subject: [PATCH 2/2] perf(DashNet): improve code --- websites/D/DashNet/presence.ts | 58 +++++++++++++++++----------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/websites/D/DashNet/presence.ts b/websites/D/DashNet/presence.ts index 51b7ea2dee04..8fdfd7b5894d 100644 --- a/websites/D/DashNet/presence.ts +++ b/websites/D/DashNet/presence.ts @@ -1,20 +1,20 @@ let presence: Presence, newID: string, latestID: string; -function presenceSet(): void { +function presenceSet(pathname: string): void { if (!latestID && !newID) { - newID = document.location.pathname.includes("/cookieclicker/") + newID = pathname.includes("/cookieclicker/") ? "676126246928777250" : "676120967159742465"; presence = new Presence({ clientId: newID }); } if ( - document.location.pathname.includes("/cookieclicker/") && + pathname.includes("/cookieclicker/") && latestID !== "676126246928777250" ) { presence = new Presence({ clientId: "676126246928777250" }); newID = "676126246928777250"; } else if ( - !document.location.pathname.includes("/cookieclicker/") && + !pathname.includes("/cookieclicker/") && latestID !== "676120967159742465" ) { presence = new Presence({ clientId: "676120967159742465" }); @@ -25,18 +25,19 @@ function presenceSet(): void { const browsingTimestamp = Math.floor(Date.now() / 1000); -presenceSet(); +presenceSet(document.location.pathname); presence.on("UpdateData", async () => { const presenceData: PresenceData = { - largeImageKey: - "https://cdn.rcd.gg/PreMiD/websites/D/DashNet/assets/logo.png", - startTimestamp: browsingTimestamp, - }; + largeImageKey: + "https://cdn.rcd.gg/PreMiD/websites/D/DashNet/assets/logo.png", + startTimestamp: browsingTimestamp, + }, + { pathname } = document.location; - presenceSet(); + presenceSet(pathname); - if (document.location.pathname.includes("/cookieclicker/")) { + if (pathname.includes("/cookieclicker/")) { const cookies = await presence.getPageVariable( "Game.cookies", "Game.cookiesPs", @@ -49,41 +50,40 @@ presence.on("UpdateData", async () => { Math.round(Number(cookies["Game.cookiesPs"]) * 100) / 100 } cookies per second`; presenceData.smallImageText = `Legacy level: ${cookies["Game.ascendMeterLevel"]}`; - } else if (document.location.pathname === "/") { + } else if (pathname === "/") { presenceData.details = "Browsing DashNet's"; presenceData.state = "video games and other fun things"; presenceData.smallImageKey = Assets.Reading; - } else if (document.location.pathname.includes("/legacy/")) + } else if (pathname.includes("/legacy/")) presenceData.details = "Playing Legacy"; - else if (document.location.pathname.includes("/igm/")) + else if (pathname.includes("/igm/")) presenceData.details = "Making an idle game"; - else if (document.location.pathname.includes("/randomgen/")) + else if (pathname.includes("/randomgen/")) presenceData.details = "Using RandomGen"; - else if (document.location.pathname.includes("/nested/")) + else if (pathname.includes("/nested/")) presenceData.details = "Playing Nested"; - else if (document.location.pathname.includes("/murdergames/")) + else if (pathname.includes("/murdergames/")) presenceData.details = "Playing Murder Games"; - else if (document.location.pathname.includes("/lsystem/")) + else if (pathname.includes("/lsystem/")) presenceData.details = "Playing Tutrle Toy"; - else if (document.location.pathname.includes("/taskmaster/")) + else if (pathname.includes("/taskmaster/")) presenceData.details = "Using TaskMaster"; - else if (document.location.pathname.includes("/cookies2cash/")) + else if (pathname.includes("/cookies2cash/")) presenceData.details = "Using Cookies2Cash"; - else if (document.location.pathname.includes("/musicgen/")) + else if (pathname.includes("/musicgen/")) presenceData.details = "Using MusicGen"; - else if (document.location.pathname.includes("/dungeongenerator/")) + else if (pathname.includes("/dungeongenerator/")) presenceData.details = "Using Dungeon Generator"; - else if (document.location.pathname.includes("/dreamlog/")) + else if (pathname.includes("/dreamlog/")) presenceData.details = "Playing Dreamlog"; - else if (document.location.pathname.includes("/PretendEverything/")) + else if (pathname.includes("/PretendEverything/")) presenceData.details = "Playing PretendEverything"; - else if (document.location.pathname.includes("/teaparty/")) + else if (pathname.includes("/teaparty/")) presenceData.details = "Having a tea party"; - else if (document.location.pathname.includes("/mailtopia/")) + else if (pathname.includes("/mailtopia/")) presenceData.details = "Playing mailtopia"; - else if (document.location.pathname.includes("/life")) - presenceData.details = "Playing Life"; - else if (document.location.pathname.includes("/3dtest/2")) + else if (pathname.includes("/life")) presenceData.details = "Playing Life"; + else if (pathname.includes("/3dtest/2")) presenceData.details = "Using WebGL test"; if (presenceData.details) presence.setActivity(presenceData);