-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathweibo.js
65 lines (60 loc) · 1.68 KB
/
weibo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var url='https://api.weibo.cn/2/!/search/hot_word?sid=v_widget&source=5786724301'
const json=await get({'url':url})
const w = new ListWidget()
const bgColor = new LinearGradient()
bgColor.colors = [new Color("#1c1c1c"), new Color("#29323c")]
bgColor.locations = [0.0, 1.0]
w.backgroundColor = new Color("#222222")
var page=1
// if(args.widgetParameter!=""){
page=args.widgetParameter
// }
const pagesize=8
var i=(page-1)*pagesize
for (var item of json.data){
if(i==page*pagesize){
break
}
const stack = w.addStack()
stack.centerAlignContent()
const ydLine = stack.addText(item.id+' '+item.word)
ydLine.font=Font.systemFont(15)
ydLine.textColor = new Color("#e587ce")
ydLine.textOpacity = 0.7
// ydLine.url=item.app_query_link
ydLine.url='sinaweibo://searchall?q='+encodeURI(item.word)+""
// const num=stack.addText(item.num)
// num.font=Font.systemFont(10)
// num.textColor = new Color("#e587ce")
// num.textOpacity = 0.7
if(item.flag_link.length){
stack.addSpacer(2)
const image = await loadImage(item.flag_link)
const imgWiget=stack.addImage(image)
imgWiget.imageSize=new Size(20, 15)
}
// console.log(ydLine.url)
i++
}
// if (config.runsInWidget) {
let widget = w
Script.setWidget(widget)
Script.complete()
// }else(
w.presentMedium()
async function get(opts) {
const request = new Request(opts.url)
request.headers = {
...opts.headers,
...this.defaultHeaders
}
var result=await request.loadJSON()
console.log(result)
return result
}
async function loadImage(imgUrl) {
let req = new Request(imgUrl)
let image = await req.loadImage()
return image
}
// )