From c9a327ad5cff74798484752fda7757f367e0edd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Du=C5=A1ek?= Date: Thu, 16 Feb 2023 14:32:08 +0100 Subject: [PATCH] [ext] fix Tchibo --- extension/.eslintrc.json | 2 +- extension/shops/shop.mjs | 3 ++- extension/shops/tchibo.mjs | 31 +++++++++---------------------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/extension/.eslintrc.json b/extension/.eslintrc.json index 45eda6098..e19484384 100644 --- a/extension/.eslintrc.json +++ b/extension/.eslintrc.json @@ -1,7 +1,7 @@ { "parserOptions": { "sourceType": "module", - "ecmaVersion": 2020 + "ecmaVersion": 2022 }, "env": { "es6": true, diff --git a/extension/shops/shop.mjs b/extension/shops/shop.mjs index 26eb65baf..c06db7a90 100644 --- a/extension/shops/shop.mjs +++ b/extension/shops/shop.mjs @@ -10,7 +10,8 @@ export class Shop { inject(renderMarkup) { const [position, selector, extraStyles] = this.injectionPoint; const elem = document.querySelector(selector); - if (!elem) throw new Error(`Element to add chart not found; selector: ${selector}`); + if (!elem) + throw new Error(`Element to add chart not found; selector: ${selector}`); elem.insertAdjacentElement(position, renderMarkup(extraStyles)); return elem; } diff --git a/extension/shops/tchibo.mjs b/extension/shops/tchibo.mjs index f3142c224..b71fa923e 100644 --- a/extension/shops/tchibo.mjs +++ b/extension/shops/tchibo.mjs @@ -3,37 +3,24 @@ import { Shop } from "./shop.mjs"; export class Tchibo extends Shop { async scrape() { - const elem = document.querySelector(".c-tp-simplebutton--order"); + const elem = document.querySelector(".pdp-buybox__add-to-cart-container"); if (!elem) return; const itemUrl = document.location.href; - const itemId = itemUrl.match(/-p(\d+)\.html/)?.[1]; - const title = document.querySelector("h1").textContent.trim(); - const currentPrice = cleanPrice(".c-tp-price-currentprice"); - const originalPrice = cleanPrice(".c-tp-price-oldprice .c-tp-price-output"); + const itemId = itemUrl.split("/").at(-2); + const title = document + .querySelector(".pdp-buybox__title") + .textContent.trim(); + const currentPrice = cleanPrice(".tp-price-current"); + const originalPrice = cleanPrice(".tp-price-previous .tp-price-value"); const imageUrl = document.querySelector( - ".m-tp-productimagegallery-preview-wrapper > a > img" + ".tp-imagegallery-main-container img" )?.src; return { itemId, title, currentPrice, originalPrice, imageUrl }; } inject(renderMarkup) { - let elem = document.querySelector( - ".m-tp-base-column--leftaligned .c-tp-simplebutton--order" - ); - console.log(elem); - if (elem) { - const markup = renderMarkup(); - elem.insertAdjacentElement("afterend", markup); - return elem; - } - - // eng variant - elem = document.querySelector("#carButtons .testdrive-bonus"); - if (!elem) throw new Error("Element to add chart not found"); - - const table = document.querySelector("#carButtons table"); - table.style.position = "relative"; + const elem = document.querySelector(".crosschannel-panel"); const markup = renderMarkup(); elem.insertAdjacentElement("afterend", markup); return elem;