-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPickIcon.ts
More file actions
160 lines (142 loc) · 4.52 KB
/
PickIcon.ts
File metadata and controls
160 lines (142 loc) · 4.52 KB
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
import { ConfigProtocol } from "./common/ProxyConfig";
export default function pickIcon(protocol: ConfigProtocol, userAgent?: string): string {
let iconClass = '';
switch (protocol) {
case 'http:':
case 'https:':
iconClass = 'fa fa-paper-plane';
break;
case 'browser:':
iconClass = browserIcon(userAgent);
break;
case 'mysql:':
iconClass = 'fa fa-database';
break;
case 'mongo:':
iconClass = 'fa fa-leaf';
break;
case 'redis:':
iconClass = 'fa fa-cube';
break;
case 'grpc:':
iconClass = 'fa fa-bahai';
break;
case 'log:':
iconClass = 'fa fa-file';
break;
default:
iconClass = 'fa fa-arrows-alt-h';
}
return iconClass;
}
declare global {
interface Window {
opr: any | undefined;
opera: any | undefined;
chrome: any | undefined;
HTMLElement: any | undefined;
StyleMedia: any | undefined;
}
interface Document {
documentMode: string;
}
}
declare const InstallTrigger: any;
export function getBrowserIconColor(userAgent: string): string | undefined {
const icon = pickIcon('browser:', userAgent);
if (icon.indexOf('chrome') !== -1) return '#4DCE5B';
if (icon.indexOf('chromium') !== -1) return '#4DCE5B';
if (icon.indexOf('opera') !== -1) return '#F76464';
if (icon.indexOf('firefox') !== -1) return 'orangered';
if (icon.indexOf('edge') !== -1) return '#007bff';
if (icon.indexOf('safari') !== -1) return '#007bff';
if (icon.indexOf('explorer') !== -1) return '#007bff';
return undefined;
}
export function getBrowserIconColorClass(userAgent: string): string | undefined {
const icon = pickIcon('browser:', userAgent);
if (icon.indexOf('chrome') !== -1) return 'icon-color-chrome';
if (icon.indexOf('chromium') !== -1) return 'icon-color-chromium';
if (icon.indexOf('opera') !== -1) return 'icon-color-opera';
if (icon.indexOf('firefox') !== -1) return 'icon-color-firefox';
if (icon.indexOf('edge') !== -1) return 'icon-color-edge';
if (icon.indexOf('safari') !== -1) return 'icon-color-safari';
if (icon.indexOf('explorer') !== -1) return 'icon-color-explorer';
return undefined;
}
export function getDisplayableUserAgent(userAgent: string): string {
const icon = pickIcon('browser:', userAgent);
if (icon.indexOf('chrome') !== -1) return 'Chrome';
if (icon.indexOf('chromium') !== -1) return 'Chromium';
if (icon.indexOf('opera') !== -1) return 'Opera';
if (icon.indexOf('firefox') !== -1) return 'Firefox';
if (icon.indexOf('edge') !== -1) return 'Edge';
if (icon.indexOf('safari') !== -1) return 'Safari';
if (icon.indexOf('explorer') !== -1) return 'Explorer';
const out = userAgent.split(' ')[0];
return out.split('/')[0];
}
function browserIcon(userAgent?: string): string {
let icon = 'fa fa-keyboard-maximize';
if (userAgent) {
userAgent = userAgent.toLowerCase();
if (userAgent.includes('firefox')) {
return 'fab fa-firefox';
}
if (userAgent.includes('edge')) {
return 'fab fa-edge';
}
if (userAgent.includes('opera')) {
return 'fab fa-opera';
}
if (userAgent.includes('chrome') || userAgent.includes('chromium')) {
return 'fab fa-chrome';
}
if (userAgent.includes('safari')) {
return 'fab fa-safari';
}
if (userAgent.includes('explorer')) {
return 'fab fa-internet-explorer';
}
return 'fas fa-keyboard';
// return 'fas fa-keyboard';
}
// Opera 8.0+
const isOpera = (!!window.opr && !!window.opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
if (isOpera) {
icon = 'fab fa-opera';
}
// Firefox 1.0+
const isFirefox = typeof InstallTrigger !== 'undefined';
if (isFirefox) {
icon = 'fab fa-firefox';
}
// Safari 3.0+ "[object HTMLElementConstructor]"
// const isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && window['safari'].pushNotification));
// if (isSafari) {
// icon = 'fa-safari';
// }
// Internet Explorer 6-11
const isIE = /*@cc_on!@*/false || !!document.documentMode;
if (isIE) {
icon = 'fab fa-edge-legacy';
}
// Edge 20+
const isEdge = !isIE && !!window.StyleMedia;
if (isEdge) {
icon = 'fab fa-edge';
}
// Chrome 1 - 79
const isChrome = !!window.chrome /*&& (!!window.chrome.webstore || !!window.chrome.runtime)*/;
if (isChrome) {
icon = 'fab fa-chrome';
}
// Edge (based on chromium) detection
const isEdgeChromium = isChrome && (navigator.userAgent.indexOf("Edg") !== -1);
if (isEdgeChromium) {
icon = 'fab fa-edge';
}
// Blink engine detection
// const isBlink = (isChrome || isOpera) && !!window.CSS;
return icon;
}