Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DashNet): prevent memory leak & change to pagevar code #8892

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion websites/D/DashNet/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
106 changes: 55 additions & 51 deletions websites/D/DashNet/presence.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,89 @@
let presence: Presence, newID: string, latestID: string;
function presenceSet(): void {
if (document.location.pathname.includes("/cookieclicker/")) {
function presenceSet(pathname: string): void {
if (!latestID && !newID) {
newID = pathname.includes("/cookieclicker/")
? "676126246928777250"
: "676120967159742465";
presence = new Presence({ clientId: newID });
}

if (
pathname.includes("/cookieclicker/") &&
latestID !== "676126246928777250"
) {
presence = new Presence({ clientId: "676126246928777250" });
newID = "676126246928777250";
} else {
} else if (
!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();
presenceSet(document.location.pathname);

presence.on("UpdateData", () => {
presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey:
"https://cdn.rcd.gg/PreMiD/websites/D/DashNet/assets/logo.png",
startTimestamp: browsingTimestamp,
};

presenceSet();
largeImageKey:
"https://cdn.rcd.gg/PreMiD/websites/D/DashNet/assets/logo.png",
startTimestamp: browsingTimestamp,
},
{ pathname } = document.location;

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");
presenceSet(pathname);

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
}`;
} else if (document.location.pathname === "/") {
if (pathname.includes("/cookieclicker/")) {
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 (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);
Expand Down
Loading