diff --git a/src/server/web/boot.js b/src/server/web/boot.js index 4921530b2c245edbe1d56597f19152dacb231ee3..5eff81a3ec614103ddd5faab4c3f34ea114c82e0 100644 --- a/src/server/web/boot.js +++ b/src/server/web/boot.js @@ -10,103 +10,107 @@ 'use strict'; -//#region Script - -//#region Detect language -const supportedLangs = LANGS; -let lang = localStorage.getItem('lang'); -if (lang == null || !supportedLangs.includes(lang)) { - if (supportedLangs.includes(navigator.language)) { - lang = navigator.language; - } else { - lang = supportedLangs.find(x => x.split('-')[0] === navigator.language); - - // Fallback - if (lang == null) lang = 'en-US'; - } -} -//#endregion - -const ver = localStorage.getItem('v') || VERSION; - -const salt = localStorage.getItem('salt') - ? `?salt=${localStorage.getItem('salt')}` - : ''; - -const head = document.getElementsByTagName('head')[0]; - -const script = document.createElement('script'); -script.setAttribute('src', `/assets/app.${ver}.${lang}.js${salt}`); -script.setAttribute('async', 'true'); -script.setAttribute('defer', 'true'); -head.appendChild(script); - -// 3秒経ã£ã¦ã‚‚スクリプトãŒãƒãƒ¼ãƒ‰ã•ã‚Œãªã„å ´åˆã¯ãƒãƒ¼ã‚¸ãƒ§ãƒ³ãŒå¤ã㦠-// 404ã«ãªã£ã¦ã„ã‚‹ã›ã„ã‹ã‚‚ã—ã‚Œãªã„ã®ã§ã€ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‚’確èªã—ã¦å¤ã‘ã‚Œã°æ›´æ–°ã™ã‚‹ -// -// èªã¿è¾¼ã¾ã‚ŒãŸã‚¹ã‚¯ãƒªãƒ—トã‹ã‚‰ã“ã®ã‚¿ã‚¤ãƒžãƒ¼ã‚’解除ã§ãるよã†ã«ã€ -// ã‚°ãƒãƒ¼ãƒãƒ«ã«ã‚¿ã‚¤ãƒžãƒ¼IDを代入ã—ã¦ãŠã -window.mkBootTimer = window.setTimeout(async () => { - const res = await fetch('/api/meta', { - method: 'POST', - cache: 'no-cache' - }); - - const meta = await res.json(); - - if (meta.version != ver) { - localStorage.setItem('v', meta.version); - alert( - 'Misskeyã®æ–°ã—ã„ãƒãƒ¼ã‚¸ãƒ§ãƒ³ãŒã‚ã‚Šã¾ã™ã€‚ページをå†åº¦èªã¿è¾¼ã¿ã—ã¾ã™ã€‚' + - '\n\n' + - 'New version of Misskey available. The page will be reloaded.'); - refresh(); +// ブãƒãƒƒã‚¯ã®ä¸ã«å…¥ã‚Œãªã„ã¨ã€å®šç¾©ã—ãŸå¤‰æ•°ãŒãƒ–ラウザã®ã‚°ãƒãƒ¼ãƒãƒ«ã‚¹ã‚³ãƒ¼ãƒ—ã«ç™»éŒ²ã•ã‚Œã¦ã—ã¾ã„é‚ªé” +{ + //#region Script + + //#region Detect language + const supportedLangs = LANGS; + let lang = localStorage.getItem('lang'); + if (lang == null || !supportedLangs.includes(lang)) { + if (supportedLangs.includes(navigator.language)) { + lang = navigator.language; + } else { + lang = supportedLangs.find(x => x.split('-')[0] === navigator.language); + + // Fallback + if (lang == null) lang = 'en-US'; + } } -}, 3000); -//#endregion - -//#region Theme -const theme = localStorage.getItem('theme'); -if (theme) { - for (const [k, v] of Object.entries(JSON.parse(theme))) { - document.documentElement.style.setProperty(`--${k}`, v.toString()); - - // HTMLã® theme-color é©ç”¨ - if (k === 'htmlThemeColor') { - for (const tag of document.head.children) { - if (tag.tagName === 'META' && tag.getAttribute('name') === 'theme-color') { - tag.setAttribute('content', v); - break; + //#endregion + + const ver = localStorage.getItem('v') || VERSION; + + const salt = localStorage.getItem('salt') + ? `?salt=${localStorage.getItem('salt')}` + : ''; + + const head = document.getElementsByTagName('head')[0]; + + const script = document.createElement('script'); + script.setAttribute('src', `/assets/app.${ver}.${lang}.js${salt}`); + script.setAttribute('async', 'true'); + script.setAttribute('defer', 'true'); + head.appendChild(script); + + // 3秒経ã£ã¦ã‚‚スクリプトãŒãƒãƒ¼ãƒ‰ã•ã‚Œãªã„å ´åˆã¯ãƒãƒ¼ã‚¸ãƒ§ãƒ³ãŒå¤ã㦠+ // 404ã«ãªã£ã¦ã„ã‚‹ã›ã„ã‹ã‚‚ã—ã‚Œãªã„ã®ã§ã€ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‚’確èªã—ã¦å¤ã‘ã‚Œã°æ›´æ–°ã™ã‚‹ + // + // èªã¿è¾¼ã¾ã‚ŒãŸã‚¹ã‚¯ãƒªãƒ—トã‹ã‚‰ã“ã®ã‚¿ã‚¤ãƒžãƒ¼ã‚’解除ã§ãるよã†ã«ã€ + // ã‚°ãƒãƒ¼ãƒãƒ«ã«ã‚¿ã‚¤ãƒžãƒ¼IDを代入ã—ã¦ãŠã + window.mkBootTimer = window.setTimeout(async () => { + const res = await fetch('/api/meta', { + method: 'POST', + cache: 'no-cache' + }); + + const meta = await res.json(); + + if (meta.version != ver) { + localStorage.setItem('v', meta.version); + alert( + 'Misskeyã®æ–°ã—ã„ãƒãƒ¼ã‚¸ãƒ§ãƒ³ãŒã‚ã‚Šã¾ã™ã€‚ページをå†åº¦èªã¿è¾¼ã¿ã—ã¾ã™ã€‚' + + '\n\n' + + 'New version of Misskey available. The page will be reloaded.'); + refresh(); + } + }, 3000); + //#endregion + + //#region Theme + const theme = localStorage.getItem('theme'); + if (theme) { + for (const [k, v] of Object.entries(JSON.parse(theme))) { + document.documentElement.style.setProperty(`--${k}`, v.toString()); + + // HTMLã® theme-color é©ç”¨ + if (k === 'htmlThemeColor') { + for (const tag of document.head.children) { + if (tag.tagName === 'META' && tag.getAttribute('name') === 'theme-color') { + tag.setAttribute('content', v); + break; + } } } } } -} -//#endregion + //#endregion -const fontSize = localStorage.getItem('fontSize'); -if (fontSize) { - document.documentElement.classList.add('f-' + fontSize); -} + const fontSize = localStorage.getItem('fontSize'); + if (fontSize) { + document.documentElement.classList.add('f-' + fontSize); + } -const useSystemFont = localStorage.getItem('useSystemFont'); -if (useSystemFont) { - document.documentElement.classList.add('useSystemFont'); -} + const useSystemFont = localStorage.getItem('useSystemFont'); + if (useSystemFont) { + document.documentElement.classList.add('useSystemFont'); + } -function refresh() { - // Random - localStorage.setItem('salt', Math.random().toString().substr(2, 8)); + // eslint-disable-next-line no-inner-declarations + function refresh() { + // Random + localStorage.setItem('salt', Math.random().toString().substr(2, 8)); + + // Clear cache (service worker) + try { + navigator.serviceWorker.controller.postMessage('clear'); + navigator.serviceWorker.getRegistrations().then(registrations => { + registrations.forEach(registration => registration.unregister()); + }); + } catch (e) { + console.error(e); + } - // Clear cache (service worker) - try { - navigator.serviceWorker.controller.postMessage('clear'); - navigator.serviceWorker.getRegistrations().then(registrations => { - registrations.forEach(registration => registration.unregister()); - }); - } catch (e) { - console.error(e); + location.reload(); } - - location.reload(); }