forked from Juniorchen2012/scriptable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrankingsGoals.js
156 lines (141 loc) · 4.34 KB
/
rankingsGoals.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
var id="9"
var s="39301"
var local="en"
//You can find more ids and s value here:https://github.com/Juniorchen2012/scriptable/blob/master/footballLeagueData
if(Device.locale() == "zh_CN"){
local="zh"
}
if (args.widgetParameter == "laliga") {
//laliga
id = 10
s=39319
}else if (args.widgetParameter == "bl") {
//bundesliga
id=1
s=39285
} else if (args.widgetParameter == "sa") {
//serie A
id=13
s=39325
}else if (args.widgetParameter == "lue") {
//ligue1 uber eats
id=23
s=39245
}else if (args.widgetParameter == "efl") {
//ligue1 uber eats
id=41
s=39296
}
formatDate()
var iconUrl=`https://images.onefootball.com/icons/leagueColoredCompetition/64/${id}.png`
const bg = await drawBg(iconUrl)
var url=`https://feedmonster.onefootball.com/feeds/il/en/competitions/${id}/${s}/league_statistics.json`
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.backgroundGradient = bgColor
w.backgroundColor = new Color("#222222")
w.backgroundImage=bg
var matchDate=""
var count=0
for (var item of json.scorers) {
if(count>4){
break
}
count++
const stack = w.addStack()
// stack.backgroundColor= new Color("#25282a")
w.addSpacer(2)
stack.layoutHorizontally()
stack.centerAlignContent()
stack.setPadding(0, 0, 0, 0)
const img = await loadImage(item.thumbnailSrc)
// stack.addSpacer(20)
// const indexImg=stack.addImage(SFSymbol.named("0.circle").image)
// indexImg.imageSize=new Size(20, 20)
createTextStack(stack, ` ${item.index} `, 30)
const imagew = stack.addImage(img)
imagew.imageSize=new Size(25, 25)
const nameText = createTextStack(stack, ` ${item.name} `, 130)
nameText.leftAlignText()
const awayText = createTextStack(stack, `${item.seasonGoals}⚽️`, 30)
// awayText.rightAlignText()
stack.addSpacer(5)
const teamimg = await loadImage(`https://images.onefootball.com/icons/teams/56/${item.internalTeamId}.png`)
const teamimagew = stack.addImage(teamimg)
teamimagew.imageSize=new Size(25, 25)
// stack.addSpacer(40)
w.addSpacer(3)
}
w.presentMedium()
if (config.runsInWidget) {
let widget = w
Script.setWidget(widget)
Script.complete()
}
function createTextStack(stack, text, width) {
const tmpStack = stack.addStack()
tmpStack.size = new Size(width, 20)
const widgetText = tmpStack.addText(text)
widgetText.font = Font.systemFont(13)
// homeText.textColor = new Color("#e587ce")
widgetText.textColor = Color.white()
widgetText.textOpacity = 0.6
return widgetText
}
// QuickLook.present(table)
async function loadImage(imgUrl) {
let req = new Request(imgUrl)
let image = await req.loadImage()
return image
}
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
}
function formatDate() {
Date.prototype.format = function(fmt) {
var o = {
"M+" : this.getMonth()+1, //月份
"d+" : this.getDate(), //日
"h+" : this.getHours(), //小时
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth()+3)/3), //季度
"S" : this.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
}
}
return fmt;
}
}
async function drawBg(iconUrl){
const image = await loadImage(iconUrl)
const context =new DrawContext()
context.size=new Size(300, 200)
context.opaque=false
context.respectScreenScale=true
context.setFillColor(new Color("#36033B"))
context.fill(new Rect(0,0,300,200))
context.drawImageInRect(image, new Rect(255, 80, 40, 40))
return context.getImage()
}