rudeshark.net/src/web/app/boot.js

36 lines
953 B
JavaScript
Raw Normal View History

2017-01-01 03:23:09 +01:00
/**
2017-05-17 22:06:55 +02:00
* MISSKEY ENTRY POINT
2017-01-01 03:23:09 +01:00
*/
2016-12-31 12:26:22 +01:00
2017-05-17 22:06:55 +02:00
const Url = new URL(location.href);
2017-05-10 21:15:54 +02:00
2017-05-17 22:06:55 +02:00
let app = Url.host.split('.')[0];
2016-12-31 12:26:22 +01:00
2017-05-17 22:06:55 +02:00
// Detect user language
let lang = navigator.language.split('-')[0];
if (!/^(en|ja)$/.test(lang)) lang = 'en';
2016-12-31 12:26:22 +01:00
2017-05-17 22:06:55 +02:00
// Detect user agent
const ua = navigator.userAgent.toLowerCase();
const isMobile = /mobile|iphone|ipad|android/.test(ua);
2016-12-31 12:26:22 +01:00
2017-05-17 22:06:55 +02:00
const head = document.getElementsByTagName('head')[0];
2016-12-31 12:26:22 +01:00
2017-05-17 22:06:55 +02: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-17 16:02:41 +01:00
}
2017-05-17 22:06:55 +02:00
if (app == 'misskey') {
app = isMobile ? 'mobile' : 'desktop';
2016-12-31 12:26:22 +01:00
}
2017-05-17 22:06:55 +02:00
// Load app script
const script = document.createElement('script');
script.setAttribute('src', `/assets/${app}.${VERSION}.${lang}.js`);
script.setAttribute('async', 'true');
script.setAttribute('defer', 'true');
head.appendChild(script);