1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-18 00:28:16 +09:00
hotomoe/src/web/app/boot.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-01-01 11:23:09 +09:00
/**
2017-05-18 14:12:27 +09:00
* MISSKEY BOOT LOADER
* (ENTRY POINT)
2017-01-01 11:23:09 +09:00
*/
2016-12-31 20:26:22 +09:00
2017-05-18 14:12:27 +09:00
/**
* ドメインに基づいて適切なスクリプトを読み込みます
* ユーザーの言語およびモバイル端末か否かも考慮します
*/
'use strict';
// Get the current url information
2017-05-18 05:06:55 +09:00
const Url = new URL(location.href);
2017-05-11 04:15:54 +09:00
2017-05-18 14:26:38 +09:00
// Extarct the (sub) domain part of the current url
//
// e.g.
// misskey.alice => misskey
// misskey.strawberry.pasta => misskey
// dev.misskey.alice.tachibana => dev
2017-05-18 05:06:55 +09:00
let app = Url.host.split('.')[0];
2016-12-31 20:26:22 +09:00
2017-05-18 05:06:55 +09:00
// Detect user language
2017-05-18 14:26:38 +09:00
// Note: The default language is English
2017-05-18 05:06:55 +09:00
let lang = navigator.language.split('-')[0];
if (!/^(en|ja)$/.test(lang)) lang = 'en';
2016-12-31 20:26:22 +09:00
2017-05-18 05:06:55 +09:00
// Detect user agent
const ua = navigator.userAgent.toLowerCase();
const isMobile = /mobile|iphone|ipad|android/.test(ua);
2016-12-31 20:26:22 +09:00
2017-05-18 14:12:27 +09:00
// Get the <head> element
const [head] = document.getElementsByTagName('head');
2016-12-31 20:26:22 +09:00
2017-05-18 14:12:27 +09:00
// If mobile, insert the viewport meta tag
2017-05-18 05:06:55 +09:00
if (isMobile) {
const meta = document.createElement('meta');
meta.setAttribute('name', 'viewport');
meta.setAttribute('content', 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no');
head.appendChild(meta);
2017-03-18 00:02:41 +09:00
}
2017-05-18 14:12:27 +09:00
// Switch desktop or mobile version
2017-05-18 05:06:55 +09:00
if (app == 'misskey') {
app = isMobile ? 'mobile' : 'desktop';
2016-12-31 20:26:22 +09:00
}
2017-05-18 05:06:55 +09:00
// Load app script
2017-05-18 14:26:38 +09:00
// Note: 'async' makes can load the script async.
// 'defer' makes can run script when the dom loaded.
2017-05-18 05:06:55 +09:00
const script = document.createElement('script');
script.setAttribute('src', `/assets/${app}.${VERSION}.${lang}.js`);
script.setAttribute('async', 'true');
script.setAttribute('defer', 'true');
head.appendChild(script);