Skip to content

Instantly share code, notes, and snippets.

View hi94740's full-sized avatar

hi94740 hi94740

View GitHub Profile
@hi94740
hi94740 / Scriptable-chainWidget.js
Last active February 17, 2024 11:04
Chainable widget API for Scriptable App.
// Copy the function below to use in your scripts.
function createWidget() {
const widget = new ListWidget()
const wrap = (view, isWidget) => {
let wrapped
const wrapWith = (key, exec) => [key, (...args) => (exec(...args), wrapped)]
wrapped = Object.fromEntries(Object.keys(view).map(key => {
if (typeof view[key] === "function") {
if (key.startsWith("add")) return wrapWith(key, (...args) => {
let cb