Skip to content

Commit

Permalink
feat(store): add custom labels for links
Browse files Browse the repository at this point in the history
Fixes #1132
Fixes #1163
  • Loading branch information
jef committed Dec 5, 2020
1 parent 9bf33ec commit 790d277
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/store/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
16 changes: 14 additions & 2 deletions src/store/model/amazon-de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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',
Expand All @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions src/store/model/otto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,41 @@ export const Otto: Store = {
},
{
brand: 'sony',
labels: {
inStock: {
container:
'.js_shortInfo__variationName.prd_shortInfo__variationName',
text: ['konsole']
}
},
model: 'ps5 console',
series: 'sonyps5c',
url:
'https://www.otto.de/p/playstation-5-1136008456/#variationId=1136008459'
},
{
brand: 'sony',
labels: {
inStock: {
container:
'.js_shortInfo__variationName.prd_shortInfo__variationName',
text: ['konsole']
}
},
model: 'ps5 console',
series: 'sonyps5c',
url:
'https://www.otto.de/p/playstation-5-1154028000#variationId=1154028001'
},
{
brand: 'sony',
labels: {
inStock: {
container:
'.js_shortInfo__variationName.prd_shortInfo__variationName',
text: ['konsole']
}
},
model: 'ps5 digital',
series: 'sonyps5de',
url:
Expand Down
7 changes: 4 additions & 3 deletions src/store/model/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
series: Series;
screenshot?: string;
url: string;
};

export type LabelQuery = Element[] | Element | string[];
Expand Down

0 comments on commit 790d277

Please sign in to comment.