2017-01-01 02:23:09 +00:00
|
|
|
/**
|
2017-05-18 05:12:27 +00:00
|
|
|
* MISSKEY BOOT LOADER
|
|
|
|
* (ENTRY POINT)
|
2017-01-01 02:23:09 +00:00
|
|
|
*/
|
2016-12-31 11:26:22 +00:00
|
|
|
|
2017-05-18 05:12:27 +00:00
|
|
|
/**
|
|
|
|
* ドメインに基づいて適切なスクリプトを読み込みます。
|
|
|
|
* ユーザーの言語およびモバイル端末か否かも考慮します。
|
2017-05-24 12:06:19 +00:00
|
|
|
* webpackは介さないためrequireやimportは使えません。
|
2017-05-18 05:12:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Get the current url information
|
2017-05-17 20:06:55 +00:00
|
|
|
const Url = new URL(location.href);
|
2017-05-10 19:15:54 +00:00
|
|
|
|
2017-05-18 05:26:38 +00: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-17 20:06:55 +00:00
|
|
|
let app = Url.host.split('.')[0];
|
2016-12-31 11:26:22 +00:00
|
|
|
|
2017-05-18 05:29:55 +00:00
|
|
|
// Detect the user language
|
2017-05-18 05:26:38 +00:00
|
|
|
// Note: The default language is English
|
2017-05-17 20:06:55 +00:00
|
|
|
let lang = navigator.language.split('-')[0];
|
|
|
|
if (!/^(en|ja)$/.test(lang)) lang = 'en';
|
2016-12-31 11:26:22 +00:00
|
|
|
|
2017-05-18 05:29:55 +00:00
|
|
|
// Detect the user agent
|
2017-05-17 20:06:55 +00:00
|
|
|
const ua = navigator.userAgent.toLowerCase();
|
|
|
|
const isMobile = /mobile|iphone|ipad|android/.test(ua);
|
2016-12-31 11:26:22 +00:00
|
|
|
|
2017-05-18 05:12:27 +00:00
|
|
|
// Get the <head> element
|
2017-05-25 07:03:03 +00:00
|
|
|
const head = document.getElementsByTagName('head')[0];
|
2016-12-31 11:26:22 +00:00
|
|
|
|
2017-05-18 05:12:27 +00:00
|
|
|
// If mobile, insert the viewport meta tag
|
2017-05-17 20:06:55 +00:00
|
|
|
if (isMobile) {
|
|
|
|
const meta = document.createElement('meta');
|
|
|
|
meta.setAttribute('name', 'viewport');
|
2017-05-18 05:34:13 +00:00
|
|
|
meta.setAttribute('content', [
|
|
|
|
['width', 'device-width'],
|
|
|
|
['initial-scale', '1'],
|
|
|
|
['minimum-scale', '1'],
|
|
|
|
['maximum-scale', '1'],
|
|
|
|
['user-scalable', 'no']
|
|
|
|
].map(x => x.join('=')).join(','));
|
2017-05-17 20:06:55 +00:00
|
|
|
head.appendChild(meta);
|
2017-03-17 15:02:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 05:12:27 +00:00
|
|
|
// Switch desktop or mobile version
|
2017-05-17 20:06:55 +00:00
|
|
|
if (app == 'misskey') {
|
|
|
|
app = isMobile ? 'mobile' : 'desktop';
|
2016-12-31 11:26:22 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 05:29:55 +00:00
|
|
|
// Load an app script
|
|
|
|
// Note: 'async' makes can load the script asyncly.
|
2017-05-18 05:36:14 +00:00
|
|
|
// 'defer' makes can run the script when the dom loaded.
|
2017-05-17 20:06:55 +00: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);
|