-
-
Save brainno722/435ca36ea708fc31d38bed262a865fc6 to your computer and use it in GitHub Desktop.
Code for a widget for the Scriptable-App (iOS) which shows you random wikipedia previews
This file contains hidden or 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 lang = "en" //use the language of your choice "en", "de", "it", "fr", etc. | |
const url = `https://${lang}.wikipedia.org/api/rest_v1/page/random/summary` | |
const req = new Request(url) | |
const res = await req.loadJSON() | |
const i = new Request(res.thumbnail.source); | |
const img = await i.loadImage(); | |
let widget = createWidget(res.title, img, res.content_urls.mobile.page) | |
if (config.runsInWidget) { | |
// create and show widget | |
Script.setWidget(widget) | |
Script.complete() | |
} | |
else { | |
widget.presentSmall() | |
} | |
function createWidget(title, img, widgeturl) { | |
console.log("Title: "+title) | |
let w = new ListWidget() | |
w.backgroundColor = new Color("#1A1A1A") | |
let image = w.addImage(img); | |
image.centerAlignImage(); | |
let titleTxt = w.addText(title) | |
titleTxt.textColor = Color.white() | |
titleTxt.font = Font.systemFont(12) | |
titleTxt.centerAlignText() | |
w.url = widgeturl | |
w.setPadding(0, 5, 0, 0) | |
return w | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment