Skip to content

Commit

Permalink
feat(Salad): add presence (#8573)
Browse files Browse the repository at this point in the history
Signed-off-by: DaG <[email protected]>
Co-authored-by: Dark_Ville <[email protected]>
  • Loading branch information
daglaroglou and Dark_Ville authored Jul 24, 2024
1 parent 680771e commit 7cad2c7
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
28 changes: 28 additions & 0 deletions websites/S/Salad/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "https://schemas.premid.app/metadata/1.10",
"author": {
"id": "852825042630475827",
"name": "daglaroglou"
},
"service": "Salad",
"description": {
"en": "Salad is a worldwide computesharing community composed of thousand of gamers. Our users, the mighty Salad Chefs, share resources from their idle PCs, power advanced computing projects, and score real-life-rewards."
},
"url": ["salad.com", "community.salad.com", "support.salad.io"],
"version": "1.0.0",
"logo": "https://i.postimg.cc/Px59fwQx/Salad-Logo.png",
"thumbnail": "https://salad.com/images/blog_all_new_container_workloads.png",
"color": "#54a628",
"category": "other",
"tags": [
"salad", "mining", "crypto"
],
"settings": [
{
"id": "privacy",
"title": "Hide Balance",
"icon": "fad fa-user-secret",
"value": false
}
]
}
94 changes: 94 additions & 0 deletions websites/S/Salad/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const presence = new Presence({
clientId: "911546577485725706",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

const enum Assets {
Logo = "https://i.imgur.com/Lc9wcdl.gif",
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
},
privacy = await presence.getSetting<boolean>("privacy"),
{ hostname, pathname } = document.location;

if (hostname.startsWith("support")) {
if (pathname.includes("troubleshooting"))
presenceData.state = "Troubleshooting";
else if (pathname.includes("app-guides")) presenceData.state = "App guides";
else if (pathname.includes("faq")) presenceData.state = "The faq";
else if (pathname.includes("company")) presenceData.state = "Company";
else if (pathname.includes("article")) {
presenceData.details = privacy
? "Support - reading an article"
: "Support - Reading article";
presenceData.state = document.querySelector(".title")?.textContent;
presenceData.smallImageKey = Assets.Reading;
} else if (pathname.includes("category")) {
presenceData.details = privacy
? "Support - viewing an article category"
: "Support - viewing article category";
presenceData.state = document.querySelector(".title")?.textContent;
presenceData.smallImageKey = Assets.Search;
} else presenceData.state = "Home";

if (!presenceData.details) {
presenceData.details = privacy
? "Support - viewing"
: "Support - browsing";
}
} else if (hostname.startsWith("community")) {
if (pathname.includes("-")) {
presenceData.details = privacy
? "Community - reading a blog post"
: "Community - reading about";
presenceData.state =
document.querySelector(".xpro-post-title")?.textContent;
presenceData.smallImageKey = Assets.Reading;
} else {
presenceData.details = "Community - Browsing...";
presenceData.smallImageKey = Assets.Search;
}
} else if (pathname.includes("/earn/summary")) {
presenceData.details = privacy
? "Viewing their summary"
: "Summary - earnings";
presenceData.state = `Balance: ${
document.querySelector(".c0116")?.textContent
}`;
} else if (pathname.includes("/account/")) {
presenceData.details = privacy
? "Viewing their account settings"
: "Account - viewing";
if (pathname.endsWith("/summary"))
presenceData.state = "Account management";
else if (pathname.endsWith("/referrals")) presenceData.state = "Referrals";
else if (pathname.endsWith("/bonuses")) presenceData.state = "Bonuses";
} else if (pathname.includes("/rewards/")) {
presenceData.details = privacy
? "Store - viewing all items"
: "Store - Viewing";
presenceData.state = document?.title?.split("|")?.[0];
presenceData.smallImageKey = Assets.Viewing;
} else if (pathname.endsWith("/store")) {
presenceData.details = "Store - browsing";
presenceData.smallImageKey = Assets.Search;
} else if (pathname.includes("/search")) {
presenceData.details = privacy
? "Store - searching for something"
: "Store - searching for";
presenceData.state = `Searching for ${
document.querySelector<HTMLInputElement>('[placeholder="SEARCH"]')?.value
}`;
presenceData.smallImageKey = Assets.Search;
} else if (pathname.endsWith("/download"))
presenceData.details = "Viewing the download page";
else if (pathname.endsWith("/vault"))
presenceData.details = "Vault - viewing their vault";

if (privacy && presenceData.state) delete presenceData.state;
presence.setActivity(presenceData);
});

0 comments on commit 7cad2c7

Please sign in to comment.