0% found this document useful (0 votes)
7 views1 page

Time Progress

This script creates a customizable widget that displays progress for various time periods (today, this week, this month, and this year) based on the current date and time. It adjusts the language of the labels based on the device's locale, supporting both English and Chinese. The widget features a progress bar visual representation for each time period, updating dynamically as time passes.

Uploaded by

carollepin26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Time Progress

This script creates a customizable widget that displays progress for various time periods (today, this week, this month, and this year) based on the current date and time. It adjusts the language of the labels based on the device's locale, supporting both English and Chinese. The widget features a progress bar visual representation for each time period, updating dynamically as time passes.

Uploaded by

carollepin26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Variables used by Scriptable.

// These must be at the very top of the file. Do not edit.


// icon-color: yellow; icon-glyph: hourglass-half;
const width=125
const h=5
const w = new ListWidget()
w.backgroundColor=new Color("#222222")

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, "Today")


getwidget(7, weekday + 1, "This week")
getwidget(30, now.getDate() + 1, "This month")
getwidget(12, now.getMonth() + 1, "This year")
}
Script.setWidget(w)
Script.complete()
w.presentMedium()

function getwidget(total, haveGone, str) {


const titlew = w.addText(str)
titlew.textColor = new Color("#e587ce")
titlew.font = Font.boldSystemFont(13)
w.addSpacer(6)
const imgw = w.addImage(creatProgress(total,haveGone))
imgw.imageSize=new Size(width, h)
w.addSpacer(6)
}

function creatProgress(total,havegone){
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()
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()
}

You might also like