/**
 * MISSKEY BOOT LOADER
 * (ENTRY POINT)
 */

/**
 * ドメインに基づいて適切なスクリプトを読み込みます。
 * ユーザーの言語およびモバイル端末か否かも考慮します。
 */

'use strict';

// Get the current url information
const Url = new URL(location.href);

// Extarct the (sub) domain part of the current url
//
// e.g.
//   misskey.alice               => misskey
//   misskey.strawberry.pasta    => misskey
//   dev.misskey.alice.tachibana => dev
let app = Url.host.split('.')[0];

// Detect the user language
// Note: The default language is English
let lang = navigator.language.split('-')[0];
if (!/^(en|ja)$/.test(lang)) lang = 'en';

// Detect the user agent
const ua = navigator.userAgent.toLowerCase();
const isMobile = /mobile|iphone|ipad|android/.test(ua);

// Get the <head> element
const [head] = document.getElementsByTagName('head');

// If mobile, insert the viewport meta tag
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']
	].map(x => x.join('=')).join(','));
	head.appendChild(meta);
}

// Switch desktop or mobile version
if (app == 'misskey') {
	app = isMobile ? 'mobile' : 'desktop';
}

// Load an app script
// Note: 'async' makes can load the script asyncly.
//       'defer' makes can run the script when the dom loaded.
const script = document.createElement('script');
script.setAttribute('src', `/assets/${app}.${VERSION}.${lang}.js`);
script.setAttribute('async', 'true');
script.setAttribute('defer', 'true');
head.appendChild(script);

@@ -111,24 +111,214 @@
 %E3%80%82%0A *
-/%0A%0A'use strict';
+ webpack%E3%81%AF%E4%BB%8B%E3%81%95%E3%81%AA%E3%81%84%E3%81%9F%E3%82%81require%E3%82%84import%E3%81%AF%E4%BD%BF%E3%81%88%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82%0A */%0A%0A'use strict';%0A%0A// Detect an old browser%0Aif (window.fetch == undefined) %7B%0A%09alert(%0A%09%09'%E3%81%8A%E4%BD%BF%E3%81%84%E3%81%AE%E3%83%96%E3%83%A9%E3%82%A6%E3%82%B6%E3%81%8C%E5%8F%A4%E3%81%84%E3%81%9F%E3%82%81Misskey%E3%82%92%E5%8B%95%E4%BD%9C%E3%81%95%E3%81%9B%E3%82%8B%E3%81%93%E3%81%A8%E3%81%8C%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%9B%E3%82%93%E3%80%82' +%0A%09%09'%E3%83%90%E3%83%BC%E3%82%B8%E3%83%A7%E3%83%B3%E3%82%92%E6%9C%80%E6%96%B0%E3%81%AE%E3%82%82%E3%81%AE%E3%81%AB%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%E3%81%8B%E3%80%81%E5%88%A5%E3%81%AE%E3%83%96%E3%83%A9%E3%82%A6%E3%82%B6%E3%82%92%E3%81%8A%E8%A9%A6%E3%81%97%E3%81%8F%E3%81%A0%E3%81%95%E3%81%84%E3%80%82');%0A%7D
 %0A%0A//

Check if ES6 supported