// Variables used by Scriptable. // These must be at the very top of the file. Do not edit. // icon-color: deep-green; icon-glyph: download; // if you move the file, please adjust this, otherwise this script doesn't know where it is and downloads it again const filePath = "lib/moment.js"; const remoteUrl = "https://raw.githubusercontent.com/moment/moment/version/min/moment-with-locales.min.js"; const changelogUrl = "https://github.com/moment/moment/blob/version/CHANGELOG.md"; let momentTags = "https://api.github.com/repos/moment/moment/tags"; let infoJson = "https://raw.githubusercontent.com/schl3ck/scriptable-moment/master/info.json"; const importScriptUrl = "https://raw.githubusercontent.com/schl3ck/scriptable-moment/master/import-moment.js"; const ownVersion = "1.0"; const regexGetVersion = /^\/\/ v([\d.]+)/; let fm; let iCloud = true; try { fm = FileManager.iCloud(); } catch (err) { fm = FileManager.local(); iCloud = false; } let completePath = fm.joinPath(fm.documentsDirectory(), filePath); let req = new Request(infoJson); infoJson = await req.loadJSON(); let newVersion = infoJson.version; if (compVersion(newVersion, ownVersion) > 0) { loop: while (true) { let a = new Alert(); a.title = `New ${Script.name()} version: ${ownVersion} ⇒ ${newVersion}`; a.message = infoJson.history.find(h => h.version === newVersion).notes; a.addCancelAction("Cancel"); a.addAction("Install"); a.addAction("View Changelog"); a.addAction("Ignore"); let res = await a.presentAlert(); switch (res) { case -1: return; case 0: req = new Request(importScriptUrl); res = await req.loadString(); if (req.response.statusCode >= 400 || res.length < 300) { let a = new Alert(); a.title = "There was an error while downloading the script:"; a.message = JSON.stringify(req.response, null, 4); a.addCancelAction("OK"); a.presentAlert(); return; } fm.writeString(fm.joinPath(fm.documentsDirectory(), Script.name() + ".js"), res); let a = new Alert(); a.title = "Installation successful"; a.message = "Please run this script again, to check for updates of moment.js"; a.addCancelAction("OK"); a.presentAlert(); return; case 1: let wv = new WebView(); wv.loadHTML(`
${infoJson.history.map(h => { return `${h.htmlNotes || (h.notes || "").replace(/\n/g, "
")}