Last active
February 27, 2021 06:34
-
-
Save julio-kim/26d64d6241fe17970884675ec314bf55 to your computer and use it in GitHub Desktop.
[Scriptable] 코로나 확진자 현황
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 source = 'http://ncov.mohw.go.kr' | |
let webView = new WebView() | |
await webView.loadURL(source) | |
let covid = await webView.evaluateJavaScript(` | |
const baseSelector = 'div.mainlive_container div.liveboard_layout ' | |
let date = document.querySelector(baseSelector + 'h2 span.livedate').innerText | |
let count = document.querySelector(baseSelector + 'div.liveNum_today_new ul li:nth-child(1) span.data').innerText | |
completion({date, count}) | |
`, true) | |
let count = parseInt(covid.count) | |
let date = covid.date.replace(/\(|\)/g, '').split(',')[0] | |
const getCountSize = (count) => { | |
if (count >= 1000) { | |
return Device.isPhone() ? 45 : 55 | |
} else { | |
return Device.isPhone() ? 55 : 70 | |
} | |
} | |
const getLevelColor = (count) => { | |
if (count >= 300) return '#dc143c' | |
else if (count < 300 && count >= 100) return '#f05454' | |
else return '#0099ff' | |
} | |
if (config.runsInWidget) { | |
let widget = new ListWidget() | |
widget.backgroundColor = new Color(getLevelColor(count)) | |
widget.refreshAfterDate = new Date(Date.now() + 1000 * 30) // 30 Second | |
let titleTxt = widget.addText('코로나-19') | |
titleTxt.centerAlignText() | |
titleTxt.textColor = Color.white() | |
titleTxt.font = Font.boldRoundedSystemFont(20) | |
let countTxt = widget.addText(count.toString()) | |
countTxt.url = source | |
countTxt.centerAlignText() | |
countTxt.textColor = Color.white() | |
countTxt.font = Font.thinSystemFont(getCountSize(count)) | |
let dateTxt = widget.addText(date) | |
dateTxt.centerAlignText() | |
dateTxt.textColor = Color.white() | |
dateTxt.font = Font.thinSystemFont(15) | |
Script.setWidget(widget) | |
Script.complete() | |
} else { | |
// for Test | |
let table = new UITable() | |
let row = new UITableRow() | |
row.isHeader = true | |
row.addText(`코로나 확진자 현황 (${date})`) | |
table.addRow(row) | |
row = new UITableRow() | |
row.addText('확진자수') | |
row.addText(count.toString()).rightAligned() | |
table.addRow(row) | |
table.present() | |
} |
위젯 등록시 When Interacting
을 Run Script
로 설정할 경우, 위젯 클릭시 해당 사이트로 이동처리 추가
위젯 타이틀에 아이콘 추가
아이폰용 타이틀 사이즈 조정
- Test 코드 방식 변경
- small widget의 사이즈가 달라서 medium 사이즈로 설정
500명 이상인 경우 그레이 색상 추가
- 1000명 이상일 경우 오류 수정
- widget padding 조정
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
기존 국내만 보여주던 현황에서 국내 + 해외유입을 포함한 현황으로 변경했습니다.