From 59e3aea68238dd8c4d21b731ebf3f197faaf128d Mon Sep 17 00:00:00 2001 From: Dark_Ville Date: Tue, 29 Oct 2024 13:21:12 +0100 Subject: [PATCH] feat(Bol.Com): rewrite presence & add settings & fixes --- websites/B/bol.com/metadata.json | 36 ++++++- websites/B/bol.com/presence.ts | 158 +++++++++++++++++++------------ 2 files changed, 134 insertions(+), 60 deletions(-) diff --git a/websites/B/bol.com/metadata.json b/websites/B/bol.com/metadata.json index b11f487a4795..87b9b701af91 100644 --- a/websites/B/bol.com/metadata.json +++ b/websites/B/bol.com/metadata.json @@ -5,6 +5,12 @@ "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.", @@ -12,7 +18,7 @@ "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", @@ -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 + } + } ] -} \ No newline at end of file +} diff --git a/websites/B/bol.com/presence.ts b/websites/B/bol.com/presence.ts index 0027aedc8bba..f1c5bd2bc85b 100644 --- a/websites/B/bol.com/presence.ts +++ b/websites/B/bol.com/presence.ts @@ -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("privacy"), + presence.getSetting("buttons"), + presence.getSetting("covers"), + ]), + search = document.querySelector("#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("#searchfor").textContent) { - presenceData.details = "Zoekt voor:"; - presenceData.state = - document.querySelector("#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('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('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();