const app = new Vue({ el: '#app', data: { config: null, offline: false, filter: '', vlayout: true, isDark: null }, created: async function () { let that = this; this.isDark = 'overrideDark' in localStorage ? JSON.parse(localStorage.overrideDark) : matchMedia("(prefers-color-scheme: dark)").matches; if ('vlayout' in localStorage) { this.vlayout = JSON.parse(localStorage.vlayout) } this.checkOffline(); try { this.config = await this.getConfig(); } catch (error) { this.offline = true; } // Look for a new message if an endpoint is provided. if (this.config.message && this.config.message.url) { this.getMessage(this.config.message.url).then(function(message){ // keep the original config value if no value is provided by the endpoint for (const prop of ['title','style','content']) { if (prop in message && message[prop] !== null) { that.config.message[prop] = message[prop]; } } }); } document.addEventListener('visibilitychange', function () { if (document.visibilityState == "visible") { that.checkOffline(); } }, false); }, methods: { checkOffline: function () { let that = this; return fetch(window.location.href + "?alive", { method: 'HEAD', cache: 'no-store' }).then(function () { that.offline = false; }).catch(function () { that.offline = true; }); }, getConfig: function (event) { return fetch('config.yml').then(function (response) { if (response.status != 200) { return } return response.text().then(function (body) { return jsyaml.load(body); }); }); }, getMessage: function (url) { return fetch(url).then(function (response) { if (response.status != 200) { return; } return response.json(); }); }, toggleTheme: function() { this.isDark = !this.isDark; localStorage.overrideDark = this.isDark; }, toggleLayout: function() { this.vlayout = !this.vlayout; localStorage.vlayout = this.vlayout; }, } }); Vue.component('service', { props: ['item'], template: `

{{ item.name }}

{{ item.subtitle }}

#{{ item.tag }}
` }); if ('serviceWorker' in navigator) { window.addEventListener('load', function () { navigator.serviceWorker.register('worker.js'); }); }