Created
July 22, 2021 19:36
-
-
Save IceBotYT/b10e6a26ac906a60839f7585e2300676 to your computer and use it in GitHub Desktop.
What is my Elevation Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debug = false; | |
let stop = false; | |
function getLocation() { | |
return new Promise((resp, reje) => { | |
Location.current().then(loc => { | |
resp(loc) | |
}) | |
}) | |
} | |
async function main() { | |
return new Promise(async (resp, rej) => { | |
if (stop) resp("stop") | |
const location = await getLocation() | |
const elevationNum = Math.round(location.altitude * 3.2808) | |
const elevation = elevationNum + " ft." | |
resp(elevation) | |
}) | |
} | |
function createWidget(ele) { | |
let widget = new ListWidget() | |
widget.url = "https://whatismyelevation.com" | |
const imageData = Data.fromBase64String("iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABmJLR0QA/wD/AP+gvaeTAAANgElEQVR4nO2ce3hU5bWH37X3JNwvXkBPW7HHowctBRFR7jATwi0QwjUiBURE5CoIqFBEU0SkggJV0UhRRBEZpFwCgZCYhEvw0ghatEi1PdV6TsV6Wo9VkCSzV//ITGYPZwcmyeQC7vd5eB6eX9a3v/XNb/aevb+1ZsDFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxaVmuHyGtrh8hrao7TxigdR2AlWh1TQdi7IQ4RoAlI8QHv70aXmpllOrNOetIVdN0aXA/Y5/FJb+abXMr9mMYsN5aUjrybpYYcHZYkRYfvwZubemcooVRm0nUFGum6SLTIsFHgs8FsRZHI0v4fr4Eq6Pszga0s0Ac39yl/6itvOtKOfVGdJuoqYBD9mkDwMl+D5YJ58D3HC7tgiY5AI/DQWI8tB7a2VRDadaac4bQ268Q+cqLLNJx8XE985z8ld7XLvJ2jKumFyFNiFNYeGRtbK4xpKtAueFITdN0DmiLLdJH8UJ3oLn5X+c4ruO1ZYlHvKAn5SJyoK318mSak61ytR5Q7rdpvcoPGGTPlbF+8Z6+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4LOYE38hREe0lC1NZmPAH524PVZXuN/OMAWND7yAPFMQ3JKlfP/k2ulTqPl1T5VSRRbIJeaF1GpB6cWPWpqWp42uZ8Ad5wlTuNaPcLo3qNDp0td7Q9WM54vQ3VZX8TFaj4c05gUOeAP27p8g/o0vj/CIjQxs2lsjNURVe2P/b8jdHz/Ya2qnS5qKqyv5dPAVMtclvmAH6XahmhMjK0kb1i8kEetrk53sWcqdUYV+u0oaoqhTs5Elgmu1ghy0hsccg56rbhcabmdq0JMBebNVO4NfdBjGpsjWdShmiqnIog1UCM2zyEeJJ7FpOXfpCpdCvzYrqsxcoK1KJsqbz4MpVPStlyFs7zvglHuXdQD16f9/MCFHo12aB+mRDuElDhFU3J8usih6rwoa8vUMfFWWe7QDvBQL07jTMuY3m+8KRrdq8xCQHDfeUAStvSqlY50yFDHlnmz4iws9t0lHLIKFjsnxZkeNcqPxup15UUtqs3cEmP9EhReZEe4yoDXl3qz6MRDz+H4+Lw9tmoHN/7PeVw35tYcRH9iUrLL9hSHS/3RWVIUe36kwif+LiGAa+tinOfbHfd45u18uwzvhOC8xqO1RWnWtsVE/qBrQ3gsEGfBRnkOiaUT5tU+QEBj4Dfm973dpHMzbazUVMBY/Fx55ifNemOH/hxSVM2xQ5YRkkmMqx4GsXFVEZIqX/PrEM+rROPfvPIrmEaZsiJ0ylrwF/jPbDOrrNReHTeiX4rhsa3c8iuYS5Zrh8ZpRevs5ZnIoaLWcn0yV63NfQxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXFxcXF5YLiX8Jc+6viXRrFAAAAAElFTkSuQmCC") | |
widget.addImage(Image.fromData(imageData)) | |
let titleText = widget.addText("Elevation:") | |
let titleTextFont = new Font("ArialMT", 20) | |
titleText.font = titleTextFont | |
let eleText = widget.addText(ele) | |
let eleTextFont = new Font("Arial-BoldMT", 30) | |
eleText.font = eleTextFont | |
widget.backgroundColor = new Color("#4f92e2") | |
let refreshAfterDate = new Date() | |
refreshAfterDate.setSeconds(refreshAfterDate.getSeconds() + 10) | |
widget.refreshAfterDate = refreshAfterDate | |
let updateTime = new Date() | |
let updateHour = updateTime.getHours() < 10 ? "0" + updateTime.getHours() : updateTime.getHours() | |
let updateMinutes = updateTime.getMinutes() < 10 ? "0" + updateTime.getMinutes() : updateTime.getMinutes() | |
let updateSeconds = updateTime.getSeconds() < 10 ? "0" + updateTime.getSeconds() : updateTime.getSeconds() | |
let updateText = widget.addText("Updated " + updateHour + ":" + updateMinutes + ":" + updateSeconds) | |
updateText.font = new Font("ArialMT", 10) | |
return widget | |
} | |
if (!config.runsInWidget && !debug) { | |
stop = true; | |
} | |
main().then(async ele => { | |
if (ele === "stop") { | |
return Safari.openInApp("https://whatismyelevation.com") | |
} | |
if (debug) { | |
let widget = createWidget(ele) | |
await widget.presentSmall() | |
return Script.complete() | |
} | |
let widget = createWidget(ele) | |
Script.setWidget(widget) | |
Script.complete() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment