Skip to content

Commit

Permalink
add sw and change speech script
Browse files Browse the repository at this point in the history
  • Loading branch information
sk5s committed Dec 4, 2021
1 parent f76b659 commit 9647bed
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">

<link rel="manifest" href="manifest.json" />
<meta name="theme-color" content="#effaf5">
<link rel="apple-touch-icon" href="icon/icon.png">

<link rel="stylesheet" href="css/style.css">

Expand Down
15 changes: 14 additions & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ document.addEventListener('DOMContentLoaded', () => {
i18n_init()
})

// service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('sw.js')
.then((registration) => {
console.log('sw registered!')
console.log(registration)
})
.catch((error) => {
console.log('sw error: ' + error)
})
}

// html changed service
function html_changed() {
i18n_refresh()
Expand Down Expand Up @@ -296,7 +309,7 @@ function populateVoiceList() {
function generate_now_weather_speech_script(nowstate) {
speech_script[
'zh-TW'
] = `今天天氣${nowstate.CI}${nowstate.Wx},最高溫度維${nowstate.MaxT}度C,最低溫度維${nowstate.MinT}度C,降雨機率${nowstate.PoP}趴。`
] = `今日${cwb_location_select_value}天氣${nowstate.CI}${nowstate.Wx},最高溫度維${nowstate.MaxT}度C,最低溫度維${nowstate.MinT}度C,降雨機率${nowstate.PoP}趴。`
speech_script[
'en-US'
] = `Today's High Temperature is ${nowstate.MaxT} Celsius, Low Temperature is${nowstate.MinT}Celsius, probability of precipitation is ${nowstate.PoP} percent`
Expand Down
8 changes: 4 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"background_color": "#ffffff",
"dir": "ltr",
"display": "standalone",
"name": "alsoweather",
"orientation": "any",
"scope": "/alsoweather/",
"scope": "./",
"short_name": "alsoweather",
"start_url": "/alsoweather/",
"theme_color": "#ffffff",
"start_url": "./",
"theme_color": "#CCCC99",
"background_color": "#ffffff",
"icons": [
{
"src": "icon/icon.png",
Expand Down
23 changes: 23 additions & 0 deletions sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open('static').then((cache) => {
return cache.addAll([
'./',
'./css/bulma.min.css',
'./css/style.css',
'./js/chart.min.js',
'./js/i18n.js',
'./js/my-chart.js',
'./icon/icon.png',
])
})
)
})

self.addEventListener('fetch', (e) => {
e.respondWith(
caches.match(e.request).then((response) => {
return response || fetch(e.request)
})
)
})

0 comments on commit 9647bed

Please sign in to comment.