Last active
November 6, 2020 06:47
-
-
Save 0507spc/6edacda021eb6e92fc02b423d317d268 to your computer and use it in GitHub Desktop.
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
// Shows latest news from MacStories in a table. | |
// The table shows an image from the article, if available, and the title of the article. | |
// let rReddit = "scriptable" | |
let inputStr = args.widgetParameter | |
// if exclude itrms, this meeds to be higger than vLimit | |
// logError(inputStr) | |
if ( inputStr == null ) { inputStr = "apollo@scriptable@1" } | |
let vRedditLimit = 15 | |
let vLimit = 4 | |
let vItemCount = 1 | |
var res = inputStr.split("@") | |
let rReddit = res[1] | |
let baseURL = "www.reddit.com/r/" | |
let url = "https://" + baseURL + rReddit + "/new.json?limit=" + vRedditLimit + "&show=all" | |
let req = new Request(url) | |
let json = await req.loadJSON() | |
let items = json.data.children | |
let appURL = res[0] + "://" + baseURL + rReddit | |
let widget = createWidget(items) | |
if (config.runsInWidget) { | |
Script.setWidget(widget) | |
Script.complete() | |
} else { | |
// QuickLook.present(createWidget(items)); | |
widget.presentMedium() | |
if ( res[2] != 1 ) { | |
Safari.open(appURL) | |
} | |
} | |
function createWidget(items) { | |
// let item = items[0] | |
let w = new ListWidget() | |
// w.backgroundColor = new Color("#47761E") | |
w.backgroundColor = new Color("#000000") | |
// const bgColor = new LinearGradient() | |
// bgColor.colors = [new Color("#1c1c1c"), new Color("#29323c")] | |
// bgColor.locations = [0.0, 1.0] | |
// w.backgroundGradient = bgColor | |
// w.centerAlignContent() | |
// w.addSpacer() | |
let simpleEmoji = new Font("Menlo-Regular", 10) | |
let mainText = new Font("GillSans-SemiBold", 14) | |
let header = w.addText("r/" + rReddit) | |
header.textColor = new Color("#33ff00") | |
header.textSize = 10 | |
header.centerAlignText() | |
for (item of items) { | |
if (! item.data.title.includes("Questions Thread ") && vItemCount <= vLimit ) { | |
vItemCount = vItemCount + 1 | |
var myDate = new Date(item.data.created_utc * 1000) | |
var myFormDate = addZero(myDate.getHours()) + ":" + addZero(myDate.getMinutes()) | |
let linkToPost = item.data.permalink | |
let titleTxt = w.addText("• " + item.data.title) | |
// titleTxt.applyHeadlineTextStyling() | |
titleTxt.textColor = Color.white() | |
// titleTxt.textSize = 12 | |
titleTxt.font = mainText | |
let subTitle = w.addText("✾ " + item.data.author + " ↑ " + ("0000" + item.data.score).slice (-3) + " ✐ " + ("0000" + item.data.num_comments).slice (-3) + " ◔ " + myFormDate) | |
subTitle.font = simpleEmoji | |
subTitle.textColor = Color.gray() | |
subTitle.rightAlignText() | |
} | |
// score | |
// num_comments | |
// 💬 🗨 ✐ | |
// ⬆️ ↑ ⇧ ▲ | |
// | |
} | |
// this is for the footer update time (not needed) | |
// var nowDate = new Date() | |
// var nowFormDate = addZero(nowDate.getHours()) + ":" + addZero(nowDate.getMinutes()) | |
// let footer = w.addText("Last Updated: " + nowFormDate) | |
// footer.textColor = Color.gray() | |
// footer.rightAlignText() | |
return w | |
} | |
function addZero(i) { | |
if (i < 10) { | |
i = "0" + i; | |
} | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment