|
159 | 159 | <div id="html-body__panic-overlay"></div> |
160 | 160 | <!-- 应用挂载点 --> |
161 | 161 | <div id="root"></div> |
162 | | - <!-- 在窗口大小改变时进行强制缩放 --> |
163 | 162 | <script> |
164 | 163 | (() => { |
165 | | - const userAgent = navigator.userAgent; |
166 | | - const platform = navigator.platform; |
| 164 | + const userAgent = navigator.userAgent || ''; |
| 165 | + const platform = navigator.userAgentData?.platform || navigator.platform || ''; |
167 | 166 | const maxTouchPoints = navigator.maxTouchPoints || 0; |
168 | | - const isIPhoneLike = /iPhone|iPod/i.test(userAgent); |
169 | | - const isIPadLike = /iPad/i.test(userAgent) || (platform === 'MacIntel' && maxTouchPoints > 1); |
170 | | - const isIOS = isIPhoneLike || isIPadLike; |
171 | | - const isIOSPhone = isIOS && isIPhoneLike; |
| 167 | + const isIOSPhone = /iPhone|iPod/i.test(userAgent); |
| 168 | + const isIPad = /iPad/i.test(userAgent) || (/Mac/i.test(platform) && maxTouchPoints > 1); |
| 169 | + |
| 170 | + window.__WEBGAL_DEVICE_INFO__ = { |
| 171 | + isIOS: isIOSPhone || isIPad, |
| 172 | + isIOSPhone, |
| 173 | + isIPad, |
| 174 | + }; |
| 175 | + })(); |
| 176 | + </script> |
| 177 | + <!-- 在窗口大小改变时进行强制缩放 --> |
| 178 | + <script> |
| 179 | + (() => { |
| 180 | + const deviceInfo = window.__WEBGAL_DEVICE_INFO__ ?? { isIOS: false }; |
| 181 | + const isIOS = deviceInfo.isIOS; |
| 182 | + const layoutConfig = isIOS |
| 183 | + ? { |
| 184 | + bottomInset: 15, |
| 185 | + resizeDelay: 500, |
| 186 | + viewport: |
| 187 | + 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover', |
| 188 | + hideEffectBackground: true, |
| 189 | + } |
| 190 | + : { |
| 191 | + bottomInset: 0, |
| 192 | + resizeDelay: 0, |
| 193 | + viewport: 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no', |
| 194 | + hideEffectBackground: false, |
| 195 | + }; |
172 | 196 | const root = document.querySelector('#root'); |
173 | 197 | const titleEnter = document.querySelector('.html-body__title-enter'); |
174 | 198 | const effectBackground = document.querySelector('.html-body__effect-background'); |
175 | 199 | let viewportMeta = document.querySelector('meta[name="viewport"]'); |
176 | 200 |
|
177 | | - window.__WEBGAL_DEVICE_INFO__ = { isIOS, isIOSPhone }; |
178 | | - |
179 | 201 | const ensureViewportMeta = () => { |
180 | 202 | if (!viewportMeta) { |
181 | 203 | viewportMeta = document.createElement('meta'); |
|
190 | 212 | const targetWidth = 2560; // 目标宽度 |
191 | 213 | const h = window.innerHeight; // 窗口高度 |
192 | 214 | const w = window.innerWidth; // 窗口宽度 |
193 | | - const iosBottomInset = isIOS ? 15 : 0; |
194 | | - const layoutHeight = Math.max(h - iosBottomInset, 1); |
| 215 | + const layoutHeight = Math.max(h - layoutConfig.bottomInset, 1); |
195 | 216 | const zoomH = layoutHeight / targetHeight; // 以窗口高度为基准的变换比 |
196 | 217 | const zoomW = w / targetWidth; // 以窗口宽度为基准的变换比 |
197 | 218 | const zoomH2 = w / targetHeight; // 竖屏时以窗口高度为基础的变换比 |
|
256 | 277 | }; |
257 | 278 | let iosResizeTimer = null; |
258 | 279 | const scheduleResize = () => { |
259 | | - if (isIOS) { |
| 280 | + if (layoutConfig.resizeDelay > 0) { |
260 | 281 | if (iosResizeTimer) { |
261 | 282 | window.clearTimeout(iosResizeTimer); |
262 | 283 | } |
263 | 284 | iosResizeTimer = window.setTimeout(() => { |
264 | 285 | resize(); |
265 | 286 | iosResizeTimer = null; |
266 | | - }, 500); |
| 287 | + }, layoutConfig.resizeDelay); |
267 | 288 | return; |
268 | 289 | } |
269 | 290 | resize(); |
270 | 291 | }; |
271 | 292 | if (isIOS) { |
272 | 293 | const styleTag = document.createElement('style'); |
273 | | - styleTag.textContent = ` |
274 | | - * { font-synthesis: none !important; } |
275 | | - #ebg, |
276 | | - #ebgOverlay { |
277 | | - display: none !important; |
278 | | - } |
279 | | - `; |
| 294 | + styleTag.textContent = `* { font-synthesis: none !important; }`; |
| 295 | + if (layoutConfig.hideEffectBackground) { |
| 296 | + styleTag.textContent += ` |
| 297 | + #ebg, |
| 298 | + #ebgOverlay { |
| 299 | + display: none !important; |
| 300 | + } |
| 301 | + `; |
| 302 | + } |
280 | 303 | document.head.appendChild(styleTag); |
281 | | - ensureViewportMeta().content = |
282 | | - 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover'; |
283 | | - } else { |
284 | | - ensureViewportMeta().content = 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no'; |
285 | 304 | } |
| 305 | + ensureViewportMeta().content = layoutConfig.viewport; |
286 | 306 | scheduleResize(); |
287 | 307 | window.onload = scheduleResize; |
288 | 308 | window.onresize = scheduleResize; |
|
299 | 319 | <!-- 注册 Service Worker --> |
300 | 320 | <script> |
301 | 321 | (() => { |
302 | | - const isIOS = window.__WEBGAL_DEVICE_INFO__?.isIOS ?? !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); |
| 322 | + const isIOS = window.__WEBGAL_DEVICE_INFO__?.isIOS ?? false; |
303 | 323 | if ('serviceWorker' in navigator && !isIOS) { |
304 | 324 | navigator.serviceWorker |
305 | 325 | .register('./webgal-serviceworker.js') |
|
315 | 335 | <!-- 首屏加载 --> |
316 | 336 | <script> |
317 | 337 | (() => { |
318 | | - const isIOS = window.__WEBGAL_DEVICE_INFO__?.isIOS ?? !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); |
| 338 | + const isIOS = window.__WEBGAL_DEVICE_INFO__?.isIOS ?? false; |
| 339 | + const enterConfig = isIOS |
| 340 | + ? { skipAnimation: true, hideDelay: 0 } |
| 341 | + : { skipAnimation: false, hideDelay: 2000 }; |
319 | 342 | let enterPromiseResolve; |
320 | 343 | const enterPromise = new Promise((res) => { |
321 | 344 | enterPromiseResolve = res; |
|
341 | 364 | /** 点击屏幕,进入引擎主界面 */ |
342 | 365 | const enter = () => { |
343 | 366 | const titleEnter = document.querySelector('.html-body__title-enter'); |
344 | | - if (isIOS) { |
| 367 | + if (enterConfig.skipAnimation) { |
345 | 368 | if (titleEnter) { |
346 | 369 | titleEnter.style.pointerEvents = 'none'; |
347 | 370 | titleEnter.style.transition = 'none'; |
|
376 | 399 | if (titleEnter) { |
377 | 400 | titleEnter.style.display = 'none'; |
378 | 401 | } |
379 | | - }, 2000); // 将落地页设置为不显示 |
| 402 | + }, enterConfig.hideDelay); // 将落地页设置为不显示 |
380 | 403 | enterPromiseResolve(); |
381 | 404 | }; |
382 | 405 | const titleEnter = document.querySelector('.html-body__title-enter'); |
|
0 commit comments