Skip to content

Commit

Permalink
feat(Uwowocosplay): add presence (#8168)
Browse files Browse the repository at this point in the history
* feat(Uwowocosplay): add Uwowocosplay

* chore(Uwowocosplay): formatting

* feat(chore): no clue why it removed the brackets

* feat(update): add image of cosplay

* chore(uwowocosplay): fix ci test

* Update websites/U/uwowocosplay/metadata.json

Co-authored-by: Dark_Ville <[email protected]>
Signed-off-by: Sarah Engel <[email protected]>

* Update websites/U/uwowocosplay/presence.ts

Co-authored-by: Dark_Ville <[email protected]>
Signed-off-by: Sarah Engel <[email protected]>

* Update websites/U/uwowocosplay/presence.ts

Co-authored-by: Dark_Ville <[email protected]>
Signed-off-by: Sarah Engel <[email protected]>

* Update websites/U/uwowocosplay/presence.ts

Co-authored-by: Dark_Ville <[email protected]>
Signed-off-by: Sarah Engel <[email protected]>

* Update websites/U/uwowocosplay/presence.ts

Co-authored-by: Dark_Ville <[email protected]>
Signed-off-by: Sarah Engel <[email protected]>

* Update websites/U/uwowocosplay/metadata.json

Co-authored-by: Dark_Ville <[email protected]>
Signed-off-by: Sarah Engel <[email protected]>

* Update websites/U/uwowocosplay/metadata.json

Co-authored-by: Dark_Ville <[email protected]>
Signed-off-by: Sarah Engel <[email protected]>

* Update websites/U/uwowocosplay/presence.ts

Co-authored-by: Dark_Ville <[email protected]>
Signed-off-by: Sarah Engel <[email protected]>

* chore(Update): fix the code c:

* chore(update): change regex

---------

Signed-off-by: Sarah Engel <[email protected]>
Co-authored-by: Dark_Ville <[email protected]>
  • Loading branch information
HerXayah and Dark_Ville authored Mar 14, 2024
1 parent 64a5d93 commit 65dd5b8
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
26 changes: 26 additions & 0 deletions websites/U/uwowocosplay/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://schemas.premid.app/metadata/1.10",
"author": {
"id": "202740603790819328",
"name": "aimslut"
},
"service": "Uwowocosplay",
"description": {
"en": "Uwowo is a professional cosplay costume brand focusing on the high quality anime and game costumes and wigs with affordable price."
},
"url": "uwowocosplay.com",
"matches": [
"*://uwowocosplay.com/*"
],
"version": "1.0.0",
"logo": "https://i.imgur.com/U2EMMgC.jpeg",
"thumbnail": "https://i.imgur.com/6091d7r.png",
"color": "#f17174",
"category": "other",
"tags": [
"cosplay",
"cosplaying",
"costumes",
"anime"
]
}
87 changes: 87 additions & 0 deletions websites/U/uwowocosplay/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const presence = new Presence({
clientId: "1216150866122244096",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);
const enum Assets {
Logo = "https://i.imgur.com/U2EMMgC.jpeg",
}
presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
details: "Uwowo Cosplay Homepage",
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
},
{ pathname, href } = document.location;
switch (pathname.replace("/en-de", "").trim()) {
case "/": {
presenceData.details = "Browsing the Homepage";
break;
}
case "/en-de": {
presenceData.details = "Browsing the Homepage";
break;
}
case "/collections/shop-all": {
presenceData.details = "Browsing the shop";
break;
}
case "/cart": {
presenceData.details = "Viewing their cart";
break;
}
case "/account": {
presenceData.details = "Viewing their account";
break;
}
default: {
presenceData.details = getStyle(pathname);
break;
}
}
if (pathname.startsWith("/products/")) setProduct(presenceData, href);

presence.setActivity(presenceData);
});

function getStyle(pathname: string) {
const path = pathname.split("/collections/")[1];
if (path !== null) {
return `Browsing the ${path} Collection`
.split("-")
.join(" ")
.replace("Collections", "")
.trim();
} else return "Unknown Page";
}

function setProduct(presenceData: PresenceData, href: string) {
const product = document
// replace everything before Uwowo and remove the word "Costume" in regex
.querySelector(".h2.product-single__title")
?.textContent?.replace(/.*Uwowo/, "")
?.replace(/Costume/g, "");
presenceData.details = `Viewing ${
product
?.split(" ")
?.slice(0, product?.split(" ").length / 2)
?.join(" ") ?? "Unknown product"
}`;
presenceData.state =
product
?.split(" ")
?.slice(product?.split(" ")?.length / 2)
?.join(" ") ?? "";
presenceData.buttons = [
{
label: "View Cosplay",
url: href,
},
];

presenceData.largeImageKey =
document
.querySelector<HTMLMetaElement>('[property="og:image"]')
?.content?.split("?")?.[0] ?? Assets.Logo;
if (presenceData.largeImageKey !== Assets.Logo)
presenceData.smallImageKey = Assets.Logo;
}

0 comments on commit 65dd5b8

Please sign in to comment.