This commit is contained in:
syuilo 2017-06-07 02:02:56 +09:00
parent 0bf4f358ab
commit 8b245ab2ec

View file

@ -11,31 +11,32 @@
'use strict'; 'use strict';
// Get the current url information {
const url = new URL(location.href); // Get the current url information
const url = new URL(location.href);
// Extarct the (sub) domain part of the current url // Extarct the (sub) domain part of the current url
// //
// e.g. // e.g.
// misskey.alice => misskey // misskey.alice => misskey
// misskey.strawberry.pasta => misskey // misskey.strawberry.pasta => misskey
// dev.misskey.alice.tachibana => dev // dev.misskey.alice.tachibana => dev
let app = url.host.split('.')[0]; let app = url.host.split('.')[0];
// Detect the user language // Detect the user language
// Note: The default language is English // Note: The default language is English
let lang = navigator.language.split('-')[0]; let lang = navigator.language.split('-')[0];
if (!/^(en|ja)$/.test(lang)) lang = 'en'; if (!/^(en|ja)$/.test(lang)) lang = 'en';
// Detect the user agent // Detect the user agent
const ua = navigator.userAgent.toLowerCase(); const ua = navigator.userAgent.toLowerCase();
const isMobile = /mobile|iphone|ipad|android/.test(ua); const isMobile = /mobile|iphone|ipad|android/.test(ua);
// Get the <head> element // Get the <head> element
const head = document.getElementsByTagName('head')[0]; const head = document.getElementsByTagName('head')[0];
// If mobile, insert the viewport meta tag // If mobile, insert the viewport meta tag
if (isMobile) { if (isMobile) {
const meta = document.createElement('meta'); const meta = document.createElement('meta');
meta.setAttribute('name', 'viewport'); meta.setAttribute('name', 'viewport');
meta.setAttribute('content', [ meta.setAttribute('content', [
@ -46,18 +47,19 @@ if (isMobile) {
['user-scalable', 'no'] ['user-scalable', 'no']
].map(x => x.join('=')).join(',')); ].map(x => x.join('=')).join(','));
head.appendChild(meta); head.appendChild(meta);
} }
// Switch desktop or mobile version // Switch desktop or mobile version
if (app == 'misskey') { if (app == 'misskey') {
app = isMobile ? 'mobile' : 'desktop'; app = isMobile ? 'mobile' : 'desktop';
} }
// Load an app script // Load an app script
// Note: 'async' make it possible to load the script asyncly. // Note: 'async' make it possible to load the script asyncly.
// 'defer' make it possible to run the script when the dom loaded. // 'defer' make it possible to run the script when the dom loaded.
const script = document.createElement('script'); const script = document.createElement('script');
script.setAttribute('src', `/assets/${app}.${VERSION}.${lang}.js`); script.setAttribute('src', `/assets/${app}.${VERSION}.${lang}.js`);
script.setAttribute('async', 'true'); script.setAttribute('async', 'true');
script.setAttribute('defer', 'true'); script.setAttribute('defer', 'true');
head.appendChild(script); head.appendChild(script);
}