|
// Variables used by Scriptable. |
|
// These must be at the very top of the file. Do not edit. |
|
// icon-color: purple; icon-glyph: magic; |
|
/* global ListWidget */ |
|
|
|
const productName = 'PlayStation 5' |
|
const stores = [ |
|
{ |
|
name: 'Otto', |
|
url: 'https://www.otto.de/p/playstation-5-1154028000/', |
|
searchString: 'leider ausverkauft' |
|
}, |
|
{ |
|
name: 'Amazon', |
|
url: 'https://www.amazon.de/Playstation-Sony-PlayStation-5/dp/B08H93ZRK9/', |
|
searchString: 'Derzeit nicht verfügbar' |
|
}, |
|
{ |
|
name: 'Saturn', |
|
url: 'https://www.saturn.de/de/product/_sony-playstation%C2%AE5-2661938.html', |
|
searchString: 'Dieser Artikel ist aktuell nicht verfügbar' |
|
}, |
|
{ |
|
name: 'Media Markt', |
|
url: 'https://www.mediamarkt.de/de/product/_sony-playstation%C2%AE5-2661938.html', |
|
searchString: 'Dieser Artikel ist aktuell nicht verfügbar' |
|
}, |
|
{ |
|
name: 'Alternate', |
|
url: 'https://www.alternate.de/Sony-Interactive-Entertainment/PlayStation-5-Spielkonsole/html/product/1651220', |
|
searchString: 'Artikel kann nicht gekauft werden' |
|
}, |
|
{ |
|
name: 'Alternate', |
|
url: 'https://www.alternate.de/Sony-Interactive-Entertainment/PlayStation-5-Spielkonsole/html/product/1676871', |
|
searchString: 'Artikel kann nicht gekauft werden' |
|
}, |
|
{ |
|
name: 'GameStop', |
|
url: 'https://www.gamestop.de/PS5/Games/58665', |
|
searchString: 'Nicht verfügbar' |
|
} |
|
] |
|
|
|
let currentStore |
|
let isAvailable = false |
|
|
|
for (const store of stores) { |
|
const req = new Request(store.url) |
|
req.onRedirect = () => null |
|
const pageString = await req.loadString() |
|
|
|
currentStore = store |
|
|
|
if (req.response.statusCode === 200) { |
|
isAvailable = pageString.indexOf(store.searchString) === -1 |
|
|
|
if (isAvailable) { |
|
break |
|
} |
|
} |
|
} |
|
|
|
if (config.runsInWidget) { |
|
const widget = createWidget(isAvailable) |
|
Script.setWidget(widget) |
|
Script.complete() |
|
} else { |
|
Safari.open(currentStore.url) |
|
} |
|
|
|
function createWidget(isAvailable) { |
|
const widget = new ListWidget() |
|
|
|
widget.addSpacer() |
|
widget.url = currentStore.url |
|
|
|
const title = widget.addText(productName) |
|
title.font = Font.mediumSystemFont(14) |
|
title.centerAlignText() |
|
|
|
const availability = widget.addText(isAvailable ? 'Available' : 'Sold Out') |
|
availability.centerAlignText() |
|
availability.textColor = isAvailable ? Color.green() : Color.red() |
|
availability.font = Font.boldSystemFont(18) |
|
|
|
if (isAvailable) { |
|
const storeName = widget.addText('@ ' + currentStore.name) |
|
storeName.centerAlignText() |
|
} |
|
|
|
widget.addSpacer() |
|
|
|
return widget |
|
} |