Skip to content

Commit

Permalink
[ext] fix Tchibo
Browse files Browse the repository at this point in the history
  • Loading branch information
salax committed Feb 16, 2023
1 parent 9d1468d commit c9a327a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion extension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2020
"ecmaVersion": 2022
},
"env": {
"es6": true,
Expand Down
3 changes: 2 additions & 1 deletion extension/shops/shop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
31 changes: 9 additions & 22 deletions extension/shops/tchibo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c9a327a

Please sign in to comment.