-
Notifications
You must be signed in to change notification settings - Fork 9
/
plugin.ts
253 lines (222 loc) · 11.1 KB
/
plugin.ts
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//@ts-ignore
import { IApi } from 'umi';
export default (api: IApi) => {
api.modifyHTML(($) => {
$('head').append([
`<script>
(function () {
// match true to render BrowserUpdate popup
function matchBrowser() {
var uaExp = /((CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS)[ +]+(10[_.]0|10[_.]([1-9]|\\d{2,})|10[_.]2|10[_.]([3-9]|\\d{2,})|(1[1-9]|[2-9]\\d|\\d{3,})[_.]\\d+|11[_.]0|11[_.]([1-9]|\\d{2,})|11[_.]2|11[_.]([3-9]|\\d{2,})|(1[2-9]|[2-9]\\d|\\d{3,})[_.]\\d+|12[_.]0|12[_.]([1-9]|\\d{2,})|12[_.]4|12[_.]([5-9]|\\d{2,})|(1[3-9]|[2-9]\\d|\\d{3,})[_.]\\d+|13[_.]0|13[_.]([1-9]|\\d{2,})|13[_.]7|13[_.]([8-9]|\\d{2,})|(1[4-9]|[2-9]\\d|\\d{3,})[_.]\\d+|14[_.]0|14[_.]([1-9]|\\d{2,})|14[_.]4|14[_.]([5-9]|\\d{2,})|(1[5-9]|[2-9]\\d|\\d{3,})[_.]\\d+)(?:[_.]\\d+)?)|(CFNetwork\\/808\\.(\\d))|(CFNetwork\\/8.* Darwin\\/16\\.5\\.\\d+)|(CFNetwork\\/8.* Darwin\\/16\\.6\\.\\d+)|(CFNetwork\\/8.* Darwin\\/16\\.7\\.\\d+)|(CFNetwork\\/8.* Darwin\\/16\\.\\d+)|(CFNetwork\\/8.* Darwin\\/17\\.0\\.\\d+)|(CFNetwork\\/8.* Darwin\\/17\\.2\\.\\d+)|(CFNetwork\\/8.* Darwin\\/17\\.3\\.\\d+)|(CFNetwork\\/8.* Darwin\\/17\\.\\d+)|(Edge\\/(79(?:\\.0)?|79(?:\\.([1-9]|\\d{2,}))?|([8-9]\\d|\\d{3,})(?:\\.\\d+)?|83(?:\\.0)?|83(?:\\.([1-9]|\\d{2,}))?|(8[4-9]|9\\d|\\d{3,})(?:\\.\\d+)?))|((Chromium|Chrome)\\/(76\\.0|76\\.([1-9]|\\d{2,})|(7[7-9]|[8-9]\\d|\\d{3,})\\.\\d+|83\\.0|83\\.([1-9]|\\d{2,})|(8[4-9]|9\\d|\\d{3,})\\.\\d+)(?:\\.\\d+)?)|(Version\\/(10\\.0|10\\.([1-9]|\\d{2,})|(1[1-9]|[2-9]\\d|\\d{3,})\\.\\d+|11\\.0|11\\.([1-9]|\\d{2,})|(1[2-9]|[2-9]\\d|\\d{3,})\\.\\d+|12\\.0|12\\.([1-9]|\\d{2,})|(1[3-9]|[2-9]\\d|\\d{3,})\\.\\d+|13\\.0|13\\.([1-9]|\\d{2,})|(1[4-9]|[2-9]\\d|\\d{3,})\\.\\d+|14\\.0|14\\.([1-9]|\\d{2,})|(1[5-9]|[2-9]\\d|\\d{3,})\\.\\d+)(?:\\.\\d+)? Safari\\/)|(Firefox\\/(60\\.0|60\\.([1-9]|\\d{2,})|(6[1-9]|[7-9]\\d|\\d{3,})\\.\\d+)\\.\\d+)|(Firefox\\/(60\\.0|60\\.([1-9]|\\d{2,})|(6[1-9]|[7-9]\\d|\\d{3,})\\.\\d+)(pre|[ab]\\d+[a-z]*)?)/;
// ignore crawlers
var botExp = /Pagespeed|pingdom|Preview|ktxn|dynatrace|Ruxit|PhantomJS|Headless|Lighthouse|bot|spider|archiver|transcoder|crawl|checker|monitoring|prerender|screenshot|python-|php|uptime|validator|fetcher|facebook|slurp|google|yahoo|node|mail.ru|github|cloudflare|addthis|thumb|proxy|feed|fetch|favicon|link|http|scrape|seo|page|search console|AOLBuild|Teoma|Expeditor/i;
if (typeof navigator !== "undefined") {
// exclude browsers
if (botExp.test(navigator.userAgent)) {
return false;
}
if (uaExp instanceof RegExp) {
// workaround for UserAgent bug from iOS 15.7
// ref: https://developer.apple.com/forums/thread/715191
// issue: https://github.com/browserslist/browserslist-useragent-regexp/issues/1409
var ua = navigator.userAgent.replace("15.6,2", "15.6.2");
return !uaExp.test(ua);
}
}
// skip if UAExp error
return false;
}
function renderBrowserUpdate() {
var div = document.createElement("div");
var style = document.createElement("style");
style.setAttribute("type", "text/css");
var styleContent =
"html, body { width: 100%; height: 100%; overflow: hidden; }.legacy-warn { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #fff; z-index: 999999; } .legacy-container { position: relative; width: 940px; margin: 150px auto; } .legacy-close { position: absolute; right: -16px; top: -32px; cursor: pointer; } .legacy-img { width: 438px; float: left; margin-right: 16px;}.legacy-tips{float: right;}.legacy-img img {min-width: 100%; max-width: 100%;}.legacy-tips-title { margin-bottom: .5em; color: rgba(0,0,0,.85); font-weight: 600; font-size: 30px;line-height: 1.35;}.legacy-tips-desc { margin: 8px 0 24px;color: rgba(0,0,0,.45);font-size: 16px; line-height: 24px;}.legacy-browsers { margin-top: 40px;}.legacy-browsers li { display: inline-block; text-align: center; width: 44px; margin-right: 32px;}.legacy-browsers a { color: rgba(0, 0, 0, 0.65); text-decoration: none; }.legacy-browsers img { margin-bottom: 8px;}";
// support IE 8
if (style.styleSheet) {
style.styleSheet.cssText = styleContent;
} else {
style.innerHTML = styleContent;
}
div.innerHTML =
'<div class="legacy-warn"><div class="legacy-container"><div class="legacy-close" id="legacy-close">X</div><div class="legacy-img">'
+ '<img src="'+ window.publicPath + 'img/browser_version.png' + '" alt="" width="438" height="238" ></div><div class="legacy-tips"><p class="legacy-tips-title">浏览器版本不兼容</p><p class="legacy-tips-desc">浏览器版本过低,为避免可能存在的安全隐患,推荐升级以下浏览器</p><ul class="legacy-browsers"><li><a target="_blank" rel="noopener noreferrer" href="https://www.google.com/chrome/">'
+ '<img src="'+ window.publicPath + 'img/chrome.png' + '" alt="" width="32" height="32"><span>Chrome</span></a></li><li><a target="_blank" rel="noopener noreferrer" href="https://www.microsoft.com/edge">'
+ '<img src="'+ window.publicPath + 'img/edge.png' + '" alt="" width="32" height="32"><span>Edge</span></a></li><li><a target="_blank" rel="noopener noreferrer" href="https://support.apple.com/downloads/safari">'
+ '<img src="'+ window.publicPath + 'img/safari.png' + '" alt="" width="32" height="32"><span>Safari</span></a></li><li><a target="_blank" rel="noopener noreferrer" href="https://www.mozilla.org/exp/firefox/new/">'
+ '<img src="'+ window.publicPath + 'img/firefox.png' + '" alt="" width="32" height="32"><span>Firefox</span></a></li></div></div></div></div>';
document.body.appendChild(style);
document.body.appendChild(div);
var closeEle = document.getElementById("legacy-close");
if (closeEle) {
closeEle.onclick = function () {
document.body.removeChild(div);
document.body.removeChild(style);
};
}
}
try {
if (matchBrowser()) {
renderBrowserUpdate();
}
} catch (e) {
console.error("[BrowserUpdate ERROR]", navigator.userAgent, e);
}
})();
</script>`,
]);
$('#' + api.config.mountElementId).append([
`<div class="odc-loading">
<style>
.odc-loading {
position: fixed;
height: 100%;
width: 100%;
padding: 0px;
margin: 0px;
left: 0px;
top: 0px;
display: flex;
background: #fff;
justify-content: center;
align-items: center;
font-size: 12px;
font-family: Chinese Quote, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, PingFang SC,
Hiragino Sans GB, Microsoft YaHei, RareWord, Helvetica Neue, Helvetica, Arial, sans-serif,
monospace;
}
.loading-tip {
position: fixed;
left: calc(50% + 20px);
top: calc(50% + 60px);
transform: translateX(-50%);
color: rgba(0, 0, 0, 0.3);
}
#ob-loading-icon {
position: fixed;
bottom: 50px;
margin-left: 50%;
transform: translateX(-50%);
left: 0px;
}
.dot-box {
position: relative;
display: inline-block;
margin-bottom: 10px;
margin-right: 40px;
}
.dot-item {
display: block;
height: 50px;
position: absolute;
}
.dot1 {
-webkit-animation: bouncy1 1.5s infinite;
top: -40px;
animation: bouncy1 1.5s infinite;
}
.dot1 .dot {
background: #076fff;
}
.dot2 {
-webkit-animation: bouncy2 1.5s infinite;
animation: bouncy2 1.5s infinite;
top: 0
}
.dot3 {
-webkit-animation: bouncy3 1.5s infinite;
animation: bouncy3 1.5s infinite;
top: 40px
}
.dot {
height: 12px;
width: 12px;
border-radius: 50%;
background: #050d29;
}
@-webkit-keyframes bouncy1 {
0% {
-webkit-transform: translate(0, 0) rotate(0)
}
50% {
-webkit-transform: translate(0, 0) rotate(180deg)
}
100% {
-webkit-transform: translate(0, 40px) rotate(-180deg)
}
}
@keyframes bouncy1 {
0% {
transform: translate(0, 0) rotate(0)
}
50% {
transform: translate(0, 0) rotate(180deg)
}
100% {
transform: translate(0, 40px) rotate(-180deg)
}
}
@-webkit-keyframes bouncy2 {
0% {
-webkit-transform: translateX(0)
}
50% {
-webkit-transform: translateX(-40px)
}
100% {
-webkit-transform: translateX(-40px)
}
}
@keyframes bouncy2 {
0% {
transform: translateY(0)
}
50% {
transform: translateY(-40px)
}
100% {
transform: translateY(-40px)
}
}
@-webkit-keyframes bouncy3 {
0% {
-webkit-transform: translateY(0)
}
50% {
-webkit-transform: translateY(0)
}
100% {
-webkit-transform: translateY(-40px)
}
}
@keyframes bouncy3 {
0% {
transform: translateY(0)
}
50% {
transform: translateY(0)
}
100% {
transform: translateY(-40px)
}
}
</style>
<div class="dot-box">
<div class="dot-item dot1">
<div class="dot"></div>
</div>
<div class="dot-item dot2">
<div class="dot"></div>
</div>
<div class="dot-item dot3">
<div class="dot"></div>
</div>
</div>
<img src="/img/odc_icon.svg" width="90px" />
<span class='loading-tip'>Downloading</span>
</div>`,
`<img id="ob-loading-icon" src="/img/ob_logo.svg" />`,
]);
return $;
});
};