iceshrimp/src/web/app/client/script.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-03-18 00:02:41 +09:00
/**
2017-03-18 20:05:11 +09:00
* MISSKEY CLIENT ENTRY POINT
2017-03-18 00:02:41 +09:00
*/
2017-02-22 03:13:19 +09:00
(() => {
const head = document.getElementsByTagName('head')[0];
2017-03-18 00:02:41 +09:00
2017-03-23 05:53:09 +09:00
// Detect user language
let lang = (navigator.languages && navigator.languages[0]) || navigator.language;
if (!/en|en\-US|ja/.test(lang)) lang = 'en';
2017-03-18 00:02:41 +09:00
// Detect user agent
2017-02-22 03:13:19 +09:00
const ua = navigator.userAgent.toLowerCase();
const isMobile = /mobile|iphone|ipad|android/.test(ua);
2016-12-29 07:49:51 +09:00
2017-02-22 03:13:19 +09:00
isMobile ? mountMobile() : mountDesktop();
2016-12-29 07:49:51 +09:00
2017-03-18 00:02:41 +09:00
/**
* Mount the desktop app
*/
2017-02-22 03:13:19 +09:00
function mountDesktop() {
const script = document.createElement('script');
2017-03-23 05:53:09 +09:00
script.setAttribute('src', `/assets/desktop/script.${VERSION}.${lang}.js`);
2017-02-22 03:13:19 +09:00
script.setAttribute('async', 'true');
script.setAttribute('defer', 'true');
head.appendChild(script);
}
2016-12-29 07:49:51 +09:00
2017-03-18 00:02:41 +09:00
/**
* Mount the mobile app
*/
2017-02-22 03:13:19 +09:00
function mountMobile() {
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);
2016-12-29 07:49:51 +09:00
2017-02-22 03:13:19 +09:00
const script = document.createElement('script');
2017-03-23 05:53:09 +09:00
script.setAttribute('src', `/assets/mobile/script.${VERSION}.${lang}.js`);
2017-02-22 03:13:19 +09:00
script.setAttribute('async', 'true');
script.setAttribute('defer', 'true');
head.appendChild(script);
}
})();