Skip to main content

max / goingson

1.1 KB · 31 lines History Blame Raw
1 /* UI-mode bootstrap. Runs before the stylesheet so the ui-mode class is on
2 <html> when CSS evaluates. Externalized from an inline <script> so the CSP
3 script-src can drop 'unsafe-inline'. */
4 (function () {
5 var mode;
6 try {
7 var p = new URLSearchParams(location.search).get('ui');
8 if (p === 'mobile' || p === 'desktop') mode = p;
9 } catch (e) {}
10 if (!mode) {
11 try {
12 var ls = localStorage.getItem('goingson.uiMode');
13 if (ls === 'mobile' || ls === 'desktop') mode = ls;
14 } catch (e) {}
15 }
16 if (!mode) {
17 var uad = navigator.userAgentData;
18 if (uad && typeof uad.mobile === 'boolean') {
19 mode = uad.mobile ? 'mobile' : 'desktop';
20 }
21 }
22 if (!mode) {
23 var ua = navigator.userAgent;
24 var isMobileUA = /iPhone OS|iPad|Android/.test(ua);
25 var isIPadAsMac = /Mac/.test(navigator.platform || '') && navigator.maxTouchPoints > 1;
26 mode = (isMobileUA || isIPadAsMac) ? 'mobile' : 'desktop';
27 }
28 document.documentElement.classList.add('ui-mode-' + mode);
29 window.__GO_UI_MODE__ = mode;
30 })();
31