aboutsummaryrefslogtreecommitdiff
path: root/static/js/vendored/ua.ts
blob: e26b919d6450787231ed4f2f4c4e6bfd1204ca24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Venodred Platform Detection
// Upstream: https://github.com/leondejong/platform-detection

export default class Platform {
  public static readonly desktop: string = 'desktop';
  public static readonly tablet: string = 'tablet';
  public static readonly mobile: string = 'mobile';

  public static readonly android: string = 'android';
  public static readonly ios: string = 'ios';
  public static readonly linux: string = 'linux';
  public static readonly osx: string = 'osx';
  public static readonly windows: string = 'windows';

  public static readonly chrome: string = 'chrome';
  public static readonly firefox: string = 'firefox';
  public static readonly opera: string = 'opera';
  public static readonly edge: string = 'edge';
  public static readonly safari: string = 'safari';
  public static readonly explorer: string = 'explorer';

  public static device: string = Platform.mobile;
  public static os: string = Platform.android;
  public static browser: string = Platform.firefox;

  public static initialize(): void {
    Platform.setDevice();
    Platform.setOs();
    Platform.setBrowser();

    if (Platform.device) document.body.classList.add(Platform.device);
    if (Platform.os) document.body.classList.add(Platform.os);
    if (Platform.browser) document.body.classList.add(Platform.browser);
  }

  public static compareDevice(device: string): boolean {
    return Platform.device === device;
  }

  public static compareOs(os: string): boolean {
    return Platform.os === os;
  }

  public static compareBrowser(browser: string): boolean {
    return Platform.browser === browser;
  }

  public static isDesktop(): boolean {
    return Platform.compareDevice(Platform.desktop);
  }

  public static isTablet(): boolean {
    return Platform.compareDevice(Platform.tablet);
  }

  public static isMobile(): boolean {
    return Platform.compareDevice(Platform.mobile);
  }

  public static detectDesktop(): boolean {
    return !Platform.detectMobile() && !Platform.detectTablet();
  }

  public static detectTablet(): boolean {
    return /tablet|ipad/i.test(navigator.userAgent);
  }

  public static detectMobile(): boolean {
    return /mobile|iphone|ipod|android|windows *phone/i.test(
      navigator.userAgent,
    );
  }

  public static detectAndroid(): boolean {
    return /android/i.test(navigator.userAgent);
  }

  public static detectIos(): boolean {
    return /ipad|iphone|ipod/i.test(navigator.userAgent);
  }

  public static detectLinux(): boolean {
    return /linux/i.test(navigator.userAgent);
  }

  public static detectOsx(): boolean {
    return /macintosh|os *x/i.test(navigator.userAgent);
  }

  public static detectWindows(): boolean {
    return /windows|win64|win32/i.test(navigator.userAgent);
  }

  public static detectChrome(): boolean {
    return (
      /chrome/i.test(navigator.userAgent) &&
      !Platform.detectOpera() &&
      !Platform.detectEdge()
    );
  }

  public static detectFirefox(): boolean {
    return /firefox/i.test(navigator.userAgent);
  }

  public static detectOpera(): boolean {
    return /opr/i.test(navigator.userAgent);
  }

  public static detectEdge(): boolean {
    return /edge/i.test(navigator.userAgent);
  }

  public static detectSafari(): boolean {
    return (
      /safari/i.test(navigator.userAgent) &&
      !Platform.detectChrome() &&
      !Platform.detectOpera() &&
      !Platform.detectEdge()
    );
  }

  public static detectExplorer(): boolean {
    return /msie|trident/i.test(navigator.userAgent);
  }

  public static setDevice(): void {
    switch (true) {
      case Platform.detectTablet():
        Platform.device = Platform.tablet;
        break;
      case Platform.detectMobile():
        Platform.device = Platform.mobile;
        break;
      case Platform.detectDesktop():
        Platform.device = Platform.desktop;
        break;
      default:
        Platform.device = '';
    }
  }

  public static setOs(): void {
    switch (true) {
      case Platform.detectAndroid():
        Platform.os = Platform.android;
        break;
      case Platform.detectIos():
        Platform.os = Platform.ios;
        break;
      case Platform.detectLinux():
        Platform.os = Platform.linux;
        break;
      case Platform.detectOsx():
        Platform.os = Platform.osx;
        break;
      case Platform.detectWindows():
        Platform.os = Platform.windows;
        break;
      default:
        Platform.os = '';
    }
  }

  public static setBrowser(): void {
    switch (true) {
      case Platform.detectChrome():
        Platform.browser = Platform.chrome;
        break;
      case Platform.detectFirefox():
        Platform.browser = Platform.firefox;
        break;
      case Platform.detectOpera():
        Platform.browser = Platform.opera;
        break;
      case Platform.detectEdge():
        Platform.browser = Platform.edge;
        break;
      case Platform.detectSafari():
        Platform.browser = Platform.safari;
        break;
      case Platform.detectExplorer():
        Platform.browser = Platform.explorer;
        break;
      default:
        Platform.browser = '';
    }
  }
}