Skip to content

Instantly share code, notes, and snippets.

@devatrox
Last active August 21, 2022 05:13
Show Gist options
  • Save devatrox/bd060dac5e911a89edc2c4187b3f548a to your computer and use it in GitHub Desktop.
Save devatrox/bd060dac5e911a89edc2c4187b3f548a to your computer and use it in GitHub Desktop.
Scriptable Store Availability Checker

Scriptable Store Availability Checker

This Scriptable Widget checks regularly if a product in different stores is available and displays it in the Widget

Change productName, urls and search strings in the array below to fit your needs. The searchString is the text to look for if the product is NOT available! Unfortunately this doesn't work if the searched element is dynamically generated on load because the script does not execute Javascript

// 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment