From 010b48bcedd23638df79c4b27c2d70133d195b54 Mon Sep 17 00:00:00 2001 From: Ioannis Tsiakkas Date: Sun, 3 Dec 2023 10:39:39 +0200 Subject: [PATCH] Fix BTS price checker to bypass skroutz.gr error (#25) --- src/decorators/BTSIndicator.ts | 30 ++++++++++++------------------ src/manifest_chrome.json | 2 +- src/manifest_firefox.json | 2 +- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/decorators/BTSIndicator.ts b/src/decorators/BTSIndicator.ts index f4ac8ba..8a1b715 100644 --- a/src/decorators/BTSIndicator.ts +++ b/src/decorators/BTSIndicator.ts @@ -56,23 +56,16 @@ export class BTSIndicator { // - private getProductCode(): string | null { - const element = document.querySelector("span.sku-code"); - if (element) { - const text = element.textContent; - if (text) { - const parts = text.split(": "); - return parts[1]; - } - } - return null; + private getSKU(): string | null { + const metaTag = document.querySelector("meta[itemprop=\"sku\"]") as HTMLMetaElement | null; + return metaTag ? metaTag.content : null; } private async fetchMarketData() { try { - const productCode = this.getProductCode(); + const productCode = this.getSKU(); if (!productCode) { - throw new Error("Failed to fetch product code"); + throw new Error("Failed to fetch product SKU"); } const response = await fetch( @@ -84,17 +77,18 @@ export class BTSIndicator { }, } ); + if (!response.ok) { - throw new Error("Network response was not ok"); + throw new Error(`Failed to fetch (HTTP: ${response.status}) price data for product with SKU ${productCode}`); } const responseJSON = await response.json(); const productCards = responseJSON.product_cards as { - raw_price: number, - shipping_cost: number, - final_price_formatted?: string, - price: number, - }[]; + raw_price: number, + shipping_cost: number, + final_price_formatted?: string, + price: number, + }[]; const currency = responseJSON.price_min.trim().slice(-1); let lowestPrice = Number.MAX_VALUE; diff --git a/src/manifest_chrome.json b/src/manifest_chrome.json index 72cc59f..22d151e 100644 --- a/src/manifest_chrome.json +++ b/src/manifest_chrome.json @@ -1,7 +1,7 @@ { "name": "Skroutz Sponsored Flagger", "description": "Flags sponsored products on Skroutz.gr", - "version": "1.5.7", + "version": "1.5.8", "manifest_version": 3, "permissions": [], "host_permissions": [ diff --git a/src/manifest_firefox.json b/src/manifest_firefox.json index 57980bb..983212d 100644 --- a/src/manifest_firefox.json +++ b/src/manifest_firefox.json @@ -1,7 +1,7 @@ { "name": "Skroutz Sponsored Flagger", "description": "Flags sponsored products on Skroutz.gr", - "version": "1.5.7", + "version": "1.5.8", "manifest_version": 3, "permissions": [], "host_permissions": [