diff --git a/Apple-Order-Status/Apple-Store-Order-Status.js b/Apple-Order-Status/Apple-Store-Order-Status.js new file mode 100644 index 0000000..9e9c3b2 --- /dev/null +++ b/Apple-Order-Status/Apple-Store-Order-Status.js @@ -0,0 +1,224 @@ +// Variables used by Scriptable. +// These must be at the very top of the file. Do not edit. +// icon-color: deep-blue; icon-glyph: shopping-cart; + +const cacheMinutes = 60 * 2 +const today = new Date() +let width +const h = 5 +const debug = false + +if (config.widgetFamily === 'small') { + width = 100 +} else { + width = 200 +} + +//////////////////////////////////////////////////////////// +let widgetInputRAW = args.widgetParameter; +let widgetInput; +if (widgetInputRAW !== null) { + widgetInput = widgetInputRAW.toString().trim().split(';') + + if (widgetInput[2] && !/^[\d]+$/.test(widgetInput[2])) { + throw new Error('Third parameter has to be a number') + } +} else { + throw new Error('No Ordernumber and E-Mail address set') +} +//////////////////////////////////////////////////////////// +const files = FileManager.local() + +const path = files.joinPath(files.cacheDirectory(), "widget-apple-store-order") + +const cacheExists = files.fileExists(path) + +const cacheDate = cacheExists ? files.modificationDate(path) : 0 +//////////////////////////////////////////////////////////// +const parseDate = (stringDate) => { + const months = { + 'Januar': 0, + 'Februar': 1, + 'März': 2, + 'April': 3, + 'Mai': 4, + 'Juni': 5, + 'Juli': 6, + 'August': 7, + 'September': 8, + 'Oktober': 9, + 'November': 10, + 'Dezember': 11 + } + const m = stringDate.match(/([\d]{1,2})[.\s]+([\w]+)[\s]?([0-9]{4})?/) + const monthKey = Object.keys(months).find((key) => { + return key === m[2] || key.substring(0,3) == m[2] + }) + if (!m[3]) { + m[3] = new Date().getFullYear() + } + return new Date(m[3], months[monthKey], m[1]) +} +//////////////////////////////////////////////////////////// +function creatProgress(total,havegone){ + const context = new DrawContext() + context.size= new Size(width, h) + context.opaque = false + context.respectScreenScale = true + context.setFillColor(new Color('#d2d2d7')) + const path = new Path() + path.addRoundedRect(new Rect(0, 0, width, h), 3, 2) + context.addPath(path) + context.fillPath() + context.setFillColor(new Color('#008009')) + const path1 = new Path() + const path1width = (width*havegone/total > width) ? width : width*havegone/total + path1.addRoundedRect(new Rect(0, 0, path1width, h), 3, 2) + context.addPath(path1) + context.fillPath() + return context.getImage() +} +//////////////////////////////////////////////////////////// +const getTimeRemaining = function (endtime){ + const total = Date.parse(endtime) - Date.parse(new Date()); + const seconds = Math.floor( (total/1000) % 60 ); + const minutes = Math.floor( (total/1000/60) % 60 ); + const hours = Math.floor( (total/(1000*60*60)) % 24 ); + const days = Math.floor( total/(1000*60*60*24) ); + + return { + total, + days, + hours, + minutes, + seconds + }; +} +//////////////////////////////////////////////////////////// +const getOrderdetails = async (ordernumber, email) => { + const req = new Request(`https://store.apple.com/xc/de/vieworder/${ordernumber}/${email}`) + const res = await req.loadString() + const rawJSON = res.match(/