Skip to content

Instantly share code, notes, and snippets.

@rsalzer
rsalzer / test.md
Created December 8, 2022 11:27
Test

Dhdhshsbsbd

@rsalzer
rsalzer / RandomWikimediaPicture.js
Created November 2, 2020 21:49
Scriptable-Script to show a random featured picture on Wikimedia Commons as a Widget
//Showing random wikimedia-commons-featured-picture
const url = `https://randomincategory.toolforge.org/Featured_pictures_on_Wikimedia_Commons?server=commons.wikimedia.org&type=file&debug=1`
const req = new Request(url)
const res = await req.loadString()
let titleRegExp = new RegExp("Location: https://commons.wikimedia.org/wiki/(.*)")
let titleMatch = res.match(titleRegExp)
let title = titleMatch[1].replace("<br>", "");
let titleEncoded = encodeURI(title)
let url2 = `https://commons.wikimedia.org/w/api.php?action=query&titles=${titleEncoded}&prop=pageimages&format=json&pithumbsize=500`
const req2 = new Request(url2)
@rsalzer
rsalzer / WikipediaWiget.js
Created September 25, 2020 10:14
Code for a widget for the Scriptable-App (iOS) which shows you random wikipedia previews
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
@rsalzer
rsalzer / Paintings.js
Last active January 9, 2023 10:06
Scriptable to show a random painting from the Metropolitan Museum of Art
//Fetches Random Images from the metmuseum-api ; Stores the ids in the keychain in order to prevent multiple calls
//Department ID = 11 is paintings ; use other if you wish
var keychainkey = "paintingIDs"
var res
if(!Keychain.contains(keychainkey)) {
console.log("Keychainentry does not exist... create it");
const url = 'https://collectionapi.metmuseum.org/public/collection/v1/search?hasImages=true&medium=Paintings&departmentId=11&q=Painting'
const req = new Request(url)
res = await req.loadJSON()
let stringified = JSON.stringify(res)
@rsalzer
rsalzer / Coronavirus.js
Last active May 25, 2021 16:12 — forked from planecore/Coronavirus.js
Coronavirus Scriptable Widget
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
const canton = "ZH"
const url = `https://covid19-rest.herokuapp.com/api/openzh/v1/country/CH/area/${canton}`
const req = new Request(url)
const res = await req.loadJSON()
const today = res.records[res.records.length-1]
const yesterday = res.records[res.records.length-2]
const twodaysago = res.records[res.records.length-3]