Last active
June 12, 2022 14:10
-
-
Save JLuetzen/4682350fd2f7cfa3c1f6a1eab448ef61 to your computer and use it in GitHub Desktop.
Webcams CSML-Edition: Diese Seite gehört zur Homepage der WebCamWidgetsSylt: https://wwsylt.live. Dieses iPhone Widget zeigt Webcams in Sankt Peter-Ording, Büsum und Greetsiel. Was genau zu tun ist, steht ganz unten.
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; | |
// 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 Jens Luetzen: <[email protected]> | |
// | |
// | |
// assigning parameters from scriptable callup | |
// | |
{ | |
let param = args.widgetParameter; | |
// | |
// Initialization of variables | |
// | |
let campic; //number of cam being handed over to Widget | |
let errParam; | |
let url; | |
let widget; | |
let helpwidget; | |
const logoImg = await getImage('WWS-Logo.png'); | |
CamFamily = "CSML-Edition" | |
// | |
// assignment of callup parameters to variables | |
// | |
if (param != null && param.length > 0) { | |
campic = param-1; //Correction by -1 as arrays begin at Zero | |
errParam = "Parameter received. "; | |
} else { | |
errParam = "No Parameter received"; | |
} | |
// | |
// creating JSON for Cam location, preview jpg URL and livestream URL | |
// | |
let myWebCams = { | |
"Spotlocation" : [ | |
"SPO Badestelle Ording" , | |
"SPO Erlebnispromenade" , | |
"SPO Küstenpanorama" , | |
"Büsum I" , | |
"Büsum II" , | |
"Büsumer Deichhausen" , | |
"Greetsiel Hafen" ], | |
"imgURL" : [ | |
"https://wtvpict.feratel.com/picture/38/3240.jpeg?design=noxdesign" , | |
"https://wtvpict.feratel.com/picture/38/3242.jpeg?design=noxdesign" , | |
"https://cdn.livespotting.com/vpu/b43p0ebl/324j8hxo.jpg" , | |
"https://cdn.livespotting.com/vpu/tw0xvqm0/bc49630p.jpg" , | |
"https://cdn.livespotting.com/vpu/tw0xvqm0/8wxtwuru.jpg" , | |
"https://cdn.livespotting.com/vpu/9dvhd3wf/aetm7sg6.jpg" , | |
"https://cdn.livespotting.com/vpu/cfibaxwe/v4z1vtoe.jpg"] , | |
"LiveStreamURL" : [ | |
"http://webtv.feratel.com/webtv/?design=v4&cam=3240" , | |
"http://webtv.feratel.com/webtv/?cam=3242&design=v3" , | |
"https://player.livespotting.com?alias=w5l40qk4&ch=LS_10bae" , | |
"https://player.livespotting.com?alias=w5l40qk4&ch=LS_9a44c" , | |
"https://player.livespotting.com?alias=w5l40qk4&ch=LS_e0b60" , | |
"https://player.livespotting.com?alias=w5l40qk4&ch=aetm7sg6" , | |
"https://player.livespotting.com?alias=w5l40qk4&ch=LS_78664" ] | |
}; | |
// | |
// Creating value for date and time | |
// | |
let actualdate = new Date(); | |
let lastrefresh = new DateFormatter(); | |
lastrefresh.useShortDateStyle(); | |
lastrefresh.useShortTimeStyle(); | |
timestamp = lastrefresh.string(actualdate); | |
// | |
// Main: display preview pics with information or helpwidget, if parameters are missing | |
// | |
switch (errParam) { | |
case "Parameter received. ": | |
camLocation = myWebCams.Spotlocation[campic]; | |
camSubtitle = timestamp; | |
url = myWebCams.LiveStreamURL[campic]; | |
let imgReq = await new Request(myWebCams.imgURL[campic]); | |
let img = await imgReq.loadImage(); | |
let widget = createWidget(img,camLocation,camSubtitle,url,logoImg); | |
if (!config.runsInWidget) { | |
await widget.presentLarge(); | |
} else { | |
await Script.setWidget(widget); | |
} | |
break; | |
case "No Parameter received": | |
let helpwidget = createHelpWidget(); | |
if (!config.runsInWidget) { | |
await helpwidget.presentLarge(); | |
} else { | |
await Script.setWidget(helpwidget); | |
} | |
break; | |
} | |
Script.complete() | |
} | |
// | |
// end Main | |
// | |
// | |
// Here come the functions | |
// | |
// | |
// Creating Widget with parameters img, camLocation cLoc and camSubtitle cSub | |
// | |
function createWidget(prv_img,prv_Loc,prv_Subt,prv_URL,prvlogoImg) { | |
const widget = new ListWidget(); | |
sourceURL = "https://wwsylt.live"; | |
widget.backgroundColor = Color.black(); | |
widget.url = prv_URL; | |
widget.backgroundImage = prv_img; | |
widget.setPadding(3,15,15,3); | |
const logoStack = widget.addStack(); | |
logoStack.addSpacer(); | |
const logoImageStack = logoStack.addStack(); | |
logoImageStack.addSpacer(); | |
const wimg = logoImageStack.addImage(prvlogoImg); | |
wimg.imageSize = new Size(80, 80); | |
wimg.rightAlignImage(); | |
widget.addStack; | |
widget.addSpacer(); | |
const CamFamilyText = widget.addText(CamFamily) | |
CamFamilyText.font = Font.boldSystemFont(12); | |
CamFamilyText.textColor = Color.white(); | |
CamFamilyText.shadowRadius = 3; | |
CamFamilyText.shadowColor = Color.black(); | |
const titleText = widget.addText(prv_Loc); | |
titleText.font = Font.boldSystemFont(12); | |
titleText.textColor = Color.white(); | |
titleText.shadowRadius = 3; | |
titleText.shadowColor = Color.black(); | |
widget.addSpacer(2); | |
const subtitleText = widget.addText(prv_Subt); | |
subtitleText.font = Font.systemFont(8); | |
subtitleText.textColor = Color.white(); | |
subtitleText.textOpacity = 0.8; | |
subtitleText.shadowRadius = 3; | |
subtitleText.shadowColor = Color.black(); | |
const sourceURLText = widget.addText(sourceURL); | |
sourceURLText.font = Font.systemFont(8); | |
sourceURLText.textColor = Color.white(); | |
sourceURLText.textOpacity = 0.8; | |
sourceURLText.shadowRadius = 3; | |
sourceURLText.shadowColor = Color.black(); | |
return widget; | |
} | |
// | |
// Creating HELP-Widget without parameters | |
// | |
function createHelpWidget() { | |
const helpwidget = new ListWidget; | |
helpwidget.backgroundColor = Color.blue(); | |
const titleText = helpwidget.addText("To Do's to configure the Widget"); | |
titleText.leftAlignText(); | |
titleText.font = Font.boldSystemFont(12); | |
titleText.textColor = Color.white(); | |
myText = addLine(helpwidget,"==============================="); | |
helpwidget.addSpacer(1); | |
myText = addLine(helpwidget,"1. Widget lange drücken für den Config Mode"); | |
helpwidget.addSpacer(1); | |
myText = addLine(helpwidget,"2. Option Scripts: dieses Script wählen"); | |
helpwidget.addSpacer(1); | |
myText = addLine(helpwidget,"3. Option When interacting: 'Open URL'"); | |
helpwidget.addSpacer(1); | |
myText = addLine(helpwidget,"4. Option Parameter: Zahl zwischen 1 und 7"); | |
helpwidget.addSpacer(1); | |
myText = addLine(helpwidget,"5. Fertig mit einzelnem Widget, wiederholen für restl. 6 Cams"); | |
helpwidget.addSpacer(1); | |
myText = addLine(helpwidget,"6. Widges aufeinander ziehen für scrollbaren Smart Stack"); | |
helpwidget.addSpacer(2); | |
myText = addThankyouLine(helpwidget,"Special thanks an Livespotting.com und Feratel"); | |
return helpwidget; | |
} | |
// | |
// Adds single line to the widget, parameter: text to be displayed; | |
// same for Thankyou line, only smaller | |
// | |
function addLine(prvHW,prvTXT) { | |
var TextLine = prvHW.addText(prvTXT); | |
TextLine.leftAlignText(); | |
TextLine.font = Font.boldSystemFont(10); | |
TextLine.textColor = Color.white(); | |
} | |
function addThankyouLine(prvHW,prvTXT) { | |
var TextLine = prvHW.addText(prvTXT); | |
TextLine.leftAlignText(); | |
TextLine.font = Font.boldSystemFont(7); | |
TextLine.textColor = Color.white(); | |
} | |
// get images from local filestore or download them once | |
async function getImage(image) { | |
let fm = FileManager.local(); | |
let dir = fm.documentsDirectory(); | |
let path = fm.joinPath(dir, image); | |
if (fm.fileExists(path)) { | |
return fm.readImage(path); | |
} else { | |
// download once | |
let logoUrl; | |
switch (image) { | |
case 'WWS-Logo.png': | |
logoUrl = "https://wwsylt.live/images/WWS_Logo.png"; | |
console.log("set URL: " + logoUrl); | |
break | |
default: | |
console.log(`Sorry, couldn't find ${image}.`); | |
} | |
console.log("passing URL: " + logoUrl); | |
let iconImage = await loadImage(logoUrl); | |
fm.writeImage(path, iconImage); | |
return iconImage; | |
} | |
} | |
// helper function to download an image from a given url | |
async function loadImage(prvlogoUrl) { | |
console.log(`passed URL: ${prvlogoUrl}.`); | |
const req = new Request(prvlogoUrl); | |
return await req.loadImage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Webcams CSML-Edition: Alles im Norden
Diese Seite gehört zur Homepage der WebCamWidgetsSylt: https://wwsylt.live
Das Script auf dieser Seite zeigt die Webcams in
direkt auf dem HomeScreen vom iPhone.
Wenn man das Bild antippt, öffnet sich das Bild im Browser in großer Darstellung bzw der Livestream vom Spot.
HowTo: (Einfach) (nach unten scrollen für die detaillierte Anleitung)
Auf dem iPhone:
Bitte Folgendes berücksichtigen:
Dieses und andere Widgets teilen:
Ihr wollt vielleicht die Links zu diesem und anderen Widgets teilen:
Auf YouTube:
Präsentation der Widgets
https://youtu.be/YtO87t9DvtA
Demo aller Widgets
https://youtu.be/En-h2LZYh1w
Demo Autozug / Sylt-Shuttle
https://youtu.be/okgi-ZKg_PY
Erklärung Script Laden am Beispiel Westerland Kurpromenade
https://youtu.be/tRHFpwIr_l0
Erklärung Widget Einrichten auf dem Homescreen am Beispiel Westerland Kurpromenade
https://youtu.be/LnrikIM3T0U
Erklärung Widget Einrichten auf dem Homescreen am Beispiel Autozug / Sylt-Shuttle
https://youtu.be/vTvw9BsSmVY
2,99 € für die Kaffeedose:
Die hier zur Verfügung gestellten Widgets sind kostenlos und "as-is".
Wenn sie Euch gefallen, würde ich mich freuen, wenn Ihr mir einen Kaffee ausgebt.
HowTo: (detaillierte Schritt für Schritt Anleitung)
Wenn die Icons wackeln, das neue Widget auf das vorherige ziehen, um einen Smart Stapel zu erzeugen, mit dem man durch die Cams mit dem Daumen durchscrollen kann. Das ist ein Smart Stack
Anmerkung:
Wenn Ihr vergesst, bei "Parameter" eine Zahl einzugeben, zeigt das Widget einen blauen Hilfetext, der auch kommt, wenn man in Scriptable auf das Script tippt.
Anmerkung:
Wenn Ihr vergesst, bei "Parameter" eine Zahl einzugeben, zeigt das Widget einen blauen Hilfetext, der auch kommt, wenn man in Scriptable auf das Script tippt.