Skip to content

Commit

Permalink
[extension] - fixed hornbach shop cz/sk
Browse files Browse the repository at this point in the history
  • Loading branch information
janfiedler committed Jun 17, 2022
1 parent 0c8202a commit ed58f1e
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions extension/shops/hornbach.mjs
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
import { cleanPrice, registerShop } from "../helpers.mjs";
import { registerShop } from "../helpers.mjs";
import { Shop } from "./shop.mjs";

export class Hornbach extends Shop {
get injectionPoint() {
return ["afterend", "#product-information"];
return ["afterend", `section[data-testid="product-informations"]`];
}

async scrape() {
const elems = document.querySelectorAll(
'script[type="application/ld+json"]'
);
if (!elems) return;
const itemUrl = document.location.href;
const itemId = itemUrl.match(/(\d+)\/artik[e]?l.html/)?.[1];
const scripts = document.querySelectorAll("script");
const scripts = document.querySelectorAll('script[type="application/ld+json"]');
for (const script of scripts) {
if (script.textContent.includes("window.__ARTICLE_DETAIL_STATE__")) {
const start =
script.textContent.indexOf("window.__ARTICLE_DETAIL_STATE__ = ") +
"window.__ARTICLE_DETAIL_STATE__ = ".length;
const end = script.textContent.indexOf("window.pushTrackingInfo");
const rawJson = script.textContent.substring(start, end).trim();
const { article } = JSON.parse(rawJson);
if (script.textContent.includes(`"@type":"Product"`)) {
const article = JSON.parse(script.textContent);
return {
itemId,
title: article.title,
currentPrice: article.displayPrice?.price,
originalPrice: article.guidingPrice?.price,
imageUrl: article.metaImage.url
itemId: article.sku,
title: article.name,
currentPrice: parseFloat(article.offers[0]?.price),
originalPrice: null,
imageUrl: article.image[0].url
};
}
}
Expand Down

0 comments on commit ed58f1e

Please sign in to comment.