From 790d277af0fe178cf92a77191e4913629e85aa82 Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Fri, 4 Dec 2020 19:53:59 -0500 Subject: [PATCH] feat(store): add custom labels for links Fixes #1132 Fixes #1163 --- src/store/lookup.ts | 13 +++++++++++++ src/store/model/amazon-de.ts | 16 ++++++++++++++-- src/store/model/otto.ts | 21 +++++++++++++++++++++ src/store/model/store.ts | 7 ++++--- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/store/lookup.ts b/src/store/lookup.ts index 8454a50102..275557a609 100644 --- a/src/store/lookup.ts +++ b/src/store/lookup.ts @@ -316,6 +316,19 @@ async function lookupCardInStock(store: Store, page: Page, link: Link) { } } + if (link.labels?.inStock) { + const options = { + ...baseOptions, + requireVisible: true, + type: 'outerHTML' as const + }; + + if (!(await pageIncludesLabels(page, link.labels.inStock, options))) { + logger.info(Print.outOfStock(link, store, true)); + return false; + } + } + if (store.labels.outOfStock) { if (await pageIncludesLabels(page, store.labels.outOfStock, baseOptions)) { logger.info(Print.outOfStock(link, store, true)); diff --git a/src/store/model/amazon-de.ts b/src/store/model/amazon-de.ts index cc28c8fb66..0dd90a7739 100644 --- a/src/store/model/amazon-de.ts +++ b/src/store/model/amazon-de.ts @@ -510,6 +510,12 @@ export const AmazonDe: Store = { brand: 'sony', cartUrl: 'https://www.amazon.de/gp/aws/cart/add.html?ASIN.1=B08H93ZRK9&Quantity.1=1', + labels: { + inStock: { + container: '#productTitle', + text: ['sony playstation 5'] + } + }, model: 'ps5 console', series: 'sonyps5c', url: 'https://www.amazon.de/dp/B08H93ZRK9' @@ -518,13 +524,19 @@ export const AmazonDe: Store = { brand: 'sony', cartUrl: 'https://www.amazon.de/gp/aws/cart/add.html?ASIN.1=B08H98GVK8&Quantity.1=1', + labels: { + inStock: { + container: '#productTitle', + text: ['sony playstation 5'] + } + }, model: 'ps5 digital', series: 'sonyps5de', url: 'https://www.amazon.de/dp/B08H98GVK8' }, { brand: 'microsoft', - // Disabled because of #1095 + // Fixme: disabled because of #1095, enable when working again // cartUrl: // 'https://www.amazon.de/gp/aws/cart/add.html?ASIN.1=B08H93ZRLL&Quantity.1=1', model: 'xbox series x', @@ -533,7 +545,7 @@ export const AmazonDe: Store = { }, { brand: 'microsoft', - // Disabled because of #1095 + // Fixme: disabled because of #1095, enable when working again // cartUrl: // 'https://www.amazon.de/gp/aws/cart/add.html?ASIN.1=B087VM5XC6&Quantity.1=1', model: 'xbox series s', diff --git a/src/store/model/otto.ts b/src/store/model/otto.ts index 283a02e61c..0ac00d2124 100644 --- a/src/store/model/otto.ts +++ b/src/store/model/otto.ts @@ -28,6 +28,13 @@ export const Otto: Store = { }, { brand: 'sony', + labels: { + inStock: { + container: + '.js_shortInfo__variationName.prd_shortInfo__variationName', + text: ['konsole'] + } + }, model: 'ps5 console', series: 'sonyps5c', url: @@ -35,6 +42,13 @@ export const Otto: Store = { }, { brand: 'sony', + labels: { + inStock: { + container: + '.js_shortInfo__variationName.prd_shortInfo__variationName', + text: ['konsole'] + } + }, model: 'ps5 console', series: 'sonyps5c', url: @@ -42,6 +56,13 @@ export const Otto: Store = { }, { brand: 'sony', + labels: { + inStock: { + container: + '.js_shortInfo__variationName.prd_shortInfo__variationName', + text: ['konsole'] + } + }, model: 'ps5 digital', series: 'sonyps5de', url: diff --git a/src/store/model/store.ts b/src/store/model/store.ts index 859b1f6def..00e38524da 100644 --- a/src/store/model/store.ts +++ b/src/store/model/store.ts @@ -132,13 +132,14 @@ export type Model = export type Link = { brand: Brand; + cartUrl?: string; itemNumber?: string; - series: Series; + labels?: Labels; model: Model; - url: string; - cartUrl?: string; openCartAction?: (browser: Browser) => Promise; + series: Series; screenshot?: string; + url: string; }; export type LabelQuery = Element[] | Element | string[];