diff --git a/index.html b/index.html index 45f31e3..6661d56 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,8 @@ + + diff --git a/js/app.js b/js/app.js index 8167bfb..629584f 100644 --- a/js/app.js +++ b/js/app.js @@ -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() @@ -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` diff --git a/manifest.json b/manifest.json index 484e3b8..2d54eb6 100644 --- a/manifest.json +++ b/manifest.json @@ -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", diff --git a/sw.js b/sw.js new file mode 100644 index 0000000..0b0203c --- /dev/null +++ b/sw.js @@ -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) + }) + ) +})