Skip to content

Commit

Permalink
feat(Bol.Com): rewrite presence & add settings & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
darkvillager2 committed Oct 29, 2024
1 parent ca37397 commit 59e3aea
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 60 deletions.
36 changes: 34 additions & 2 deletions websites/B/bol.com/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
"name": "QkeleQ10",
"id": "807917674477649943"
},
"contributors": [
{
"id": "638080361179512853",
"name": "Dark_Ville"
}
],
"service": "bol.com",
"description": {
"en": "Bol.com is a webshop in the Netherlands and Belgium offering over 20 million products.",
"nl": "Bol.com is een webwinkel in Nederland en België met meer dan 20 miljoen artikelen.",
"vi_VN": "Bol.com là cửa hàng trực tuyến của Hà Lan và Bỉ cung cấp hơn 20 triệu sản phẩm."
},
"url": "www.bol.com",
"version": "1.1.11",
"version": "1.2.0",
"logo": "https://cdn.rcd.gg/PreMiD/websites/B/bol.com/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/B/bol.com/assets/thumbnail.png",
"color": "#0000a4",
Expand All @@ -26,5 +32,31 @@
"nederland",
"belgium",
"belgië"
],
"settings": [
{
"id": "privacy",
"title": "Privacy Mode",
"icon": "fas fa-user-secret",
"value": false
},
{
"id": "buttons",
"title": "Show Buttons",
"icon": "fas fa-compress-arrows-alt",
"value": true,
"if": {
"privacy": false
}
},
{
"id": "covers",
"title": "Show Cover",
"icon": "fad fa-images",
"value": false,
"if": {
"privacy": false
}
}
]
}
}
158 changes: 100 additions & 58 deletions websites/B/bol.com/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,109 @@ const presence = new Presence({
clientId: "813110347165728849",
});

const enum Assets {
Logo = "https://cdn.rcd.gg/PreMiD/websites/B/bol.com/assets/logo.png",
}

function lowerCase(str: string, capitalFirstLetter?: boolean) {
if (!str) return;
if (!capitalFirstLetter) return str.trim().toLowerCase();
else return str.trim().charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey:
"https://cdn.rcd.gg/PreMiD/websites/B/bol.com/assets/logo.png",
buttons: [{ label: "Pagina bekijken", url: document.location.href }],
};
largeImageKey: Assets.Logo,
buttons: [{ label: "Pagina bekijken", url: document.location.href }],
},
{ pathname, href } = document.location,
[privacy, buttons, covers] = await Promise.all([
presence.getSetting<boolean>("privacy"),
presence.getSetting<boolean>("buttons"),
presence.getSetting<boolean>("covers"),
]),
search = document.querySelector<HTMLInputElement>("#searchfor")?.value,
product = {
title: document.querySelector("#product_title")?.textContent,
edition: document.querySelector(".feature-list__text")?.textContent,
},
zoekCategorie = document.querySelector(".h1.bol_header")?.textContent;
presenceData.details = "Bladert op bol.com";
presenceData.state = `Pagina '${
document.title.replace("| ", "|").replace(" |", "|").split("|")[1]
}'`;
if (document.querySelector<HTMLInputElement>("#searchfor").textContent) {
presenceData.details = "Zoekt voor:";
presenceData.state =
document.querySelector<HTMLInputElement>("#searchfor").textContent;
presenceData.smallImageKey = Assets.Search;
} else if (
document.location.pathname === "/" ||
document.location.pathname === "/nl/"
)
presenceData.state = "Startpagina";
else if (
document.querySelector(
"#mainContent > div > div.constrain.u-pb--m > div.pdp-header.slot.slot--pdp-header.js_slot-title > h1 > span"
)
) {
presenceData.largeImageKey =
document.querySelector<HTMLMetaElement>('meta[property="og:image"]')
?.content ?? "bol";
presenceData.details = `Bekijkt '${
document.querySelector(
"#mainContent > div > div.constrain.u-pb--m > div.pdp-header.slot.slot--pdp-header.js_slot-title > h1 > span"
).textContent
}'`;
presenceData.state = `In ${
document.querySelector("#option_block_4").lastElementChild
.lastElementChild.textContent
}`;
presenceData.buttons = [
{ label: "Product bekijken", url: document.location.href },
];
} else if (
document.querySelector("h1[class*=bol_header][data-test*=page-title]")
) {
presenceData.details = `Bekijkt ${
document.querySelector("h1[class*=bol_header][data-test*=page-title]")
.textContent
}`;
delete presenceData.state;
presenceData.buttons = [
{ label: "Categorie bekijken", url: document.location.href },
];
} else if (document.location.pathname.toLowerCase().includes("basket"))
presenceData.details = "Bekijkt winkelwagentje";
else if (document.location.pathname.toLowerCase().includes("lijstje"))
presenceData.details = "Bekijkt verlanglijstje";
else if (document.location.pathname.toLowerCase().includes("order"))
presenceData.details = "Bestelt iets";
else if (document.location.pathname.toLowerCase().includes("bestellingen"))
presenceData.details = "Bekijkt bestellingen";
else if (document.location.pathname.toLowerCase().includes("account"))
presenceData.details = "Beheert account";

switch (true) {
case !!search: {
presenceData.details = privacy ? "Zoekt voor een product" : "Zoekt voor:";
presenceData.state = search;
presenceData.smallImageKey = Assets.Search;
break;
}
case !!product?.title: {
const categorie = document.querySelectorAll(".breadcrumbs__item");
presenceData.largeImageKey =
document.querySelector<HTMLMetaElement>('meta[property="og:image"]')
?.content ?? Assets.Logo;
presenceData.details = privacy
? "Bekijkt een product"
: `Bekijkt '${lowerCase(product?.title)}'`;
presenceData.state = !product?.edition
? `In ${lowerCase(
categorie[categorie.length - 1]?.textContent ??
"een onbekende categorie"
)}`
: lowerCase(
`Editie ${product.edition} | In ${
categorie[categorie.length - 1]?.textContent ??
"een onbekende categorie"
}`,
true
);
presenceData.buttons = [{ label: "Product bekijken", url: href }];

break;
}
case pathname.includes("/l/") && !!zoekCategorie: {
presenceData.details = privacy
? "Bekijkt producten in een categorie"
: `Bekijkt ${lowerCase(zoekCategorie)}`;
presenceData.buttons = [{ label: "Categorie bekijken", url: href }];
break;
}
case pathname === "/":
case pathname === "/nl/": {
presenceData.state = "Startpagina";
break;
}
case pathname.includes("/bestellingen/"): {
presenceData.details = "Bekijkt hun bestellingen";
break;
}
case pathname.includes("/order_details/"): {
const bestelDetails = JSON.parse(
document.querySelector("wsp-review-modal-application > script")
?.textContent
);
presenceData.details = privacy
? "Bekijkt een bestelling"
: "Bekijkst bestel details van";
presenceData.state = bestelDetails?.productTitle;
break;
}
case pathname.includes("/account/"): {
presenceData.details = "Bekijkt hun account";
break;
}
default: {
presenceData.state = `Pagina '${
document.title.replace("| ", "|").replace(" |", "|").split("|")[1]
}'`;
}
}

if ((!buttons || privacy) && presenceData.buttons)
delete presenceData.buttons;
if (privacy && presenceData.state) delete presenceData.state;
if (!covers && presenceData.largeImageKey !== Assets.Logo)
presenceData.largeImageKey = Assets.Logo;

if (presenceData.details) presence.setActivity(presenceData);
else presence.setActivity();
Expand Down

0 comments on commit 59e3aea

Please sign in to comment.