Venas 100% Capa
Venas 100% Capa
Ping: 17
No recoil20%
/ Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: red; icon-glyph: newspaper;
// This script shows articles from MacStories. The script can be used either in the
app, as a widget on your Home Screen or through Shortcuts. The behaviour of the
script will vary slightly depending on where it's used.
let items = await loadItems()
if (config.runsInWidget) {
// Tell the widget on the Home Screen to show our ListWidget instance.
let widget = await createWidget(items)
Script.setWidget(widget)
} else if (config.runsWithSiri) {
// Present a table with a subset of the news.
let firstItems = items.slice(0, 5)
let table = createTable(firstItems)
await QuickLook.present(table)
} else {
// Present the full list of news.
let table = createTable(items)
await QuickLook.present(table)
}
// Calling Script.complete() signals to Scriptable that the script have finished
running.
// This can speed up the execution, in particular when running the script from
Shortcuts or using Siri.
Script.complete()
function createTable(items) {
let table = new UITable()
for (item of items) {
let row = new UITableRow()
let imageURL = extractImageURL(item)
let title = decode(item.title)
let imageCell = row.addImageAtURL(imageURL)
let titleCell = row.addText(title)
imageCell.widthWeight = 20
titleCell.widthWeight = 80
row.height = 60
row.cellSpacing = 10
row.onSelect = (idx) => {
let item = items[idx]
Safari.open(item.url)
}
row.dismissOnSelect = false
table.addRow(row)
}
return table
}
function extractImageURL(item) {
let regex = /<img src="(.*)" alt="/
let html = item["content_html"]
let matches = html.match(regex)
if (matches && matches.length >= 2) {
return matches[1]
} else {
return null
}
}
function decode(str) {
let regex = /&#(\d+);/g
return str.replace(regex, (match, dec) => {
return String.fromCharCode(dec)
})
}