-
-
Save Envl/f2a6da0969b80da1c3a2da2bfc89ad3d to your computer and use it in GitHub Desktop.
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
let progress, multi | |
// progress = true //注释这行将关闭今日进度 | |
// multi = true // 注释这行则只展示最新一条动态 | |
function splice(txt, start, delCount, newSubStr) { | |
return ( | |
txt.slice(0, start) + | |
(newSubStr ? newSubStr : '') + | |
txt.slice(start + Math.abs(delCount)) | |
) | |
} | |
let widget = new ListWidget() | |
const dark = [new Color('#333', 0.7), new Color('#555')] | |
const light = [new Color('#fafafa'), new Color('#ffe411')] | |
const lg = new LinearGradient() | |
const hh = new Date().getHours() | |
const isDark = hh > 19 || hh < 6 | |
// console.log(isDark) | |
lg.colors = isDark ? dark : light | |
lg.locations = [0, 1] | |
widget.backgroundGradient = lg | |
const tc = isDark ? new Color('cdcdcd') : new Color('#333') | |
let list = [] | |
let jkJson | |
let link = args.widgetParameter | |
? args.widgetParameter | |
: 'https://m.okjike.com/originalPosts/5f8e1b284fc0e60018d7cf05?s=ewoidSI6ICI1NjE3ODc3YTU3MzM3ODEwMDBmYzIxMzMiCn0=' | |
const start = link.indexOf('.okjike.com/') | |
console.log(start + '@@' + link) | |
if (!(start >= 0)) { | |
return | |
} | |
link = splice(link, start + 12, 0, 'api/') | |
console.log('new link' + start + link) | |
jkJson = await new Request( | |
'https://m.okjike.com/api/users/' + | |
(await new Request(link).loadJSON()).user.username, | |
).loadJSON() | |
console.log('rsp' + jkJson) | |
list = jkJson.posts.map( | |
(p) => | |
(multi ? '*' : '') + | |
(p.content || (p.type === 'REPOST' && '转发「' + p.target.content + '」')), | |
) | |
console.log('got' + list) | |
if(!multi) | |
list = [list[0]] | |
list.forEach((v) => { | |
let li = widget.addText('' + v) | |
li.font = new Font('courier', 11) | |
li.textColor = tc | |
li.leftAlignText() | |
}) | |
// const new Date.day | |
const bgn = new Date() | |
bgn.setHours(0) | |
bgn.setMinutes(0) | |
bgn.setSeconds(0) | |
const prog = (Date.now() - bgn) / (1000 * 3600 * 24) | |
const rec = new Rect(0, 0, Math.floor(400 * prog), 20) | |
const bg = new Rect(0, 0, 400, 20) | |
const ctx = new DrawContext() | |
ctx.size = new Size(400, 10) | |
ctx.setFillColor(new Color('#888')) | |
ctx.fill(bg) | |
ctx.setFillColor(new Color('#fafafa', 0.6)) | |
ctx.fill(rec) | |
const img = ctx.getImage() | |
if (progress) { | |
widget.addImage(img) | |
} | |
Script.setWidget(widget) | |
Script.complete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment