From f7b32e8ac56c29207c6b30b9168c34c021a5e227 Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Sat, 5 Dec 2020 07:50:17 -0500 Subject: [PATCH] feat(store): add custom labels for links (#1183) 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 | 9 +++++---- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/store/lookup.ts b/src/store/lookup.ts index 8454a50..275557a 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 cc28c8f..0dd90a7 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 283a02e..0ac00d2 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 859b1f6..00e3852 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; - itemNumber?: string; - series: Series; - model: Model; - url: string; cartUrl?: string; + itemNumber?: string; + labels?: Labels; + model: Model; openCartAction?: (browser: Browser) => Promise; + series: Series; screenshot?: string; + url: string; }; export type LabelQuery = Element[] | Element | string[];