-
-
Save Limeliz/937c2795c08776ce3c24363f0ce15242 to your computer and use it in GitHub Desktop.
An iPhone widget, that shows you a live webcam image from foto-webcam.eu on your homescreen
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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: blue; icon-glyph: camera-retro; | |
// Script by Andreas Redeker <[email protected]> | |
let param = args.widgetParameter | |
let url | |
if (param != null && param.length > 0) { | |
url = param | |
} else { | |
url = "https://www.foto-webcam.eu/webcam/zugspitze-sued/" | |
} | |
const imgUrl = url + "current/400.jpg" | |
const imgReq = await new Request(imgUrl) | |
const img = await imgReq.loadImage() | |
if (config.runsInWidget) { | |
let widget = createWidget(img) | |
Script.setWidget(widget) | |
Script.complete() | |
} else { | |
let widget = createWidget(img) | |
await widget.presentMedium() | |
} | |
function createWidget(img) { | |
const widget = new ListWidget() | |
widget.backgroundColor = Color.black() | |
widget.url = url | |
widget.backgroundImage = img | |
widget.addSpacer() | |
const titleText = widget.addText(getWcNameFromUrl()) | |
titleText.font = Font.boldSystemFont(12) | |
titleText.textColor = Color.white() | |
titleText.shadowRadius = 3 | |
titleText.shadowColor = Color.black() | |
widget.addSpacer(2) | |
const subtitleText = widget.addText('foto-webcam.eu') | |
subtitleText.font = Font.systemFont(8) | |
subtitleText.textColor = Color.white() | |
subtitleText.textOpacity = 0.8 | |
subtitleText.shadowRadius = 3 | |
subtitleText.shadowColor = Color.black() | |
return widget | |
} | |
function getWcNameFromUrl() { | |
let wcName = url.split('/') | |
wcName = wcName[wcName.length - 2].replace('-', ' ').replace(/\b\w/g, function(c) { | |
return c.toUpperCase(); | |
}) | |
return wcName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment