Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BTS price checker to bypass skroutz.gr error #25

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading