-
-
Save thethtun/2aa03f0b09fa37b2d5756038cd626607 to your computer and use it in GitHub Desktop.
Scriptable- modified script based on existing script called “Time Progress”
This file contains 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
const width=125 | |
const h=5 | |
const w = new ListWidget() | |
w.backgroundColor=new Color("#222222") | |
const keyToday = "Today"; | |
const keyMonth = "This month"; | |
const keyWeek = "This Week"; | |
const keyYear = "This Year"; | |
const colorTitlePrimary = "#FAFAFA"; | |
const colorTitleSecondary = "#C0B3A3"; | |
const now = new Date() | |
const weekday = now.getDay() == 0 ? 6 : now.getDay() - 1 | |
const minutes=now.getMinutes() | |
if(Device.locale() == "zh_CN"){ | |
getwidget(24*60, (now.getHours() + 1)*60+minutes, "今日") | |
getwidget(7, weekday + 1, "本周") | |
getwidget(30, now.getDate() + 1, "本月") | |
getwidget(12, now.getMonth() + 1, "今年") | |
}else{ | |
getwidget(24*60, (now.getHours() + 1)*60+minutes, keyToday) | |
getwidget(7, weekday + 1, keyWeek) | |
getwidget(30, now.getDate() + 1, keyMonth) | |
getwidget(12, now.getMonth() + 1, keyYear) | |
} | |
Script.setWidget(w) | |
Script.complete() | |
w.presentMedium() | |
function getwidget(total, haveGone, str) { | |
const haveGonePercent = parseInt(haveGone/total * 100); | |
// const remainingPercent = 100 - haveGonePercent | |
const strWithPercent = str + " (" + haveGonePercent + "%" + ")"; | |
w.addSpacer(3) | |
const titlew = w.addText(strWithPercent) | |
// titlew.textColor = new Color("#e587ce") | |
// titlew.font = Font.boldSystemFont(13) | |
if(str == keyToday) { | |
titlew.textColor = new Color(colorTitlePrimary); | |
titlew.font = Font.lightRoundedSystemFont(24) | |
} | |
else if(str == keyWeek) { | |
titlew.textColor = new Color(colorTitleSecondary) | |
titlew.font = Font.lightRoundedSystemFont(12) | |
} | |
else if(str == keyMonth) { | |
titlew.textColor = new Color(colorTitleSecondary) | |
titlew.font = Font.lightRoundedSystemFont(12) | |
} | |
else if(str == keyYear) { | |
titlew.textColor = new Color(colorTitleSecondary) | |
titlew.font = Font.lightRoundedSystemFont(12) | |
} | |
else { | |
titlew.textColor = new Color(colorTitleSecondary) | |
titlew.font = Font.lightRoundedSystemFont(13) | |
} | |
// titlew.font = Font.title2(); | |
w.addSpacer(3) | |
// const imgw = w.addImage(creatProgress(total,haveGone)) | |
// imgw.imageSize=new Size(width, h) | |
// w.addSpacer(6) | |
} | |
function creatProgress(total,havegone){ | |
const haveGonePercent = havegone/total * 100; | |
const context =new DrawContext() | |
context.size=new Size(width, h) | |
context.opaque=false | |
context.respectScreenScale=true | |
context.setFillColor(new Color("#48484b")) | |
const path = new Path() | |
path.addRoundedRect(new Rect(0, 0, width, h), 3, 2) | |
context.addPath(path) | |
context.fillPath() | |
haveGonePercent >= 75 ? | |
context.setFillColor(new Color("#AA180E")) : | |
context.setFillColor(new Color("#ffd60a")) | |
const path1 = new Path() | |
path1.addRoundedRect(new Rect(0, 0, width*havegone/total, h), 3, 2) | |
context.addPath(path1) | |
context.fillPath() | |
return context.getImage() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment