Skip to content

Instantly share code, notes, and snippets.

@fayazara
Last active October 19, 2021 00:07
Show Gist options
  • Save fayazara/8852561b3f4ef546bc2301e9ce51ae03 to your computer and use it in GitHub Desktop.
Save fayazara/8852561b3f4ef546bc2301e9ce51ae03 to your computer and use it in GitHub Desktop.
Scriptable widget for displaying a Github repo stars
// Created by Fayaz https://twitter.com/fayazara
let widget = await createWidget();
if (config.runsInWidget) {
Script.setWidget(widget);
} else {
widget.presentSmall();
}
Script.complete();
async function createWidget() {
let listwidget = new ListWidget();
let fontLabel = new Font("AvenirNext-Medium", 12)
// Gradient
let startColor = new Color("2d3748");
let endColor = new Color("1a202c");
let gradient = new LinearGradient();
gradient.colors = [startColor, endColor];
gradient.locations = [0.0, 1];
listwidget.backgroundGradient = gradient;
let heading = listwidget.addText("Github Stars");
heading.font = fontLabel;
heading.textColor = new Color("#ffffff");
listwidget.addSpacer(12);
let response = await getData();
displayData(listwidget, response.name, response.stargazers_count);
return listwidget;
}
async function getData() {
const url = "https://api.github.com/repos/chatwoot/chatwoot";
const request = new Request(url);
const response = await request.loadJSON();
return response;
}
function displayData(stack, repo_name, repo_stars) {
displayRepoName(stack, repo_name);
displayRepoStars(stack, repo_stars);
}
function displayRepoName(stack, text) {
let fontValue = new Font("AvenirNext-Bold", 24)
let nametext = stack.addText(text);
nametext.font = fontValue;
nametext.textColor = new Color("#ffffff");
}
function displayRepoStars(stack, text) {
let fontLabel = new Font("AvenirNext-Medium ", 12)
let starsText = stack.addText(`★ ${text}`);
starsText.font = fontLabel;
starsText.textColor = new Color("#9ae6b4");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment