Skip to content

Commit

Permalink
Fix BTS price checker to bypass skroutz.gr error (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
keybraker committed Dec 3, 2023
1 parent 6b8bd28 commit 010b48b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
30 changes: 12 additions & 18 deletions src/decorators/BTSIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/manifest_chrome.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion src/manifest_firefox.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit 010b48b

Please sign in to comment.