From ffda09fa1c8d4acfd12b2883a9dc1dbdbefac1ec Mon Sep 17 00:00:00 2001 From: Rintim Date: Sat, 27 Apr 2024 02:41:04 +0800 Subject: [PATCH] pref: nomodule replace. --- game/fallback.js | 1 + game/game.js | 480 +++++++++++++++++++++++------------------------ 2 files changed, 239 insertions(+), 242 deletions(-) create mode 100644 game/fallback.js diff --git a/game/fallback.js b/game/fallback.js new file mode 100644 index 000000000..5596f70f8 --- /dev/null +++ b/game/fallback.js @@ -0,0 +1 @@ +// 空文件,只是用来加载 diff --git a/game/game.js b/game/game.js index 48eb3c44b..9713ff8e7 100644 --- a/game/game.js +++ b/game/game.js @@ -1,41 +1,223 @@ "use strict"; -new Promise((resolve) => { - // 客户端自带core.js的请注意跟进core.js版本 - if ("__core-js_shared__" in window) resolve(null); - else { - const nonameInitialized = localStorage.getItem("noname_inited"); - const assetURL = - location.protocol.startsWith("http") || - typeof nonameInitialized != "string" || - nonameInitialized == "nodejs" - ? "" - : nonameInitialized; - const coreJSBundle = document.createElement("script"); - coreJSBundle.onerror = coreJSBundle.onload = resolve; - coreJSBundle.src = `${assetURL}game/core-js-bundle.js`; - document.head.appendChild(coreJSBundle); - } -}).then(() => { +(async function () { + // 预设定常量 + /** + * 最低要求的Safari版本 + * + * @type {[majorVersion: number, minorVersion: number, patchVersion: number]} + */ + const minSafariVersion = [14, 5, 0]; + + // 基础全局变量 const nonameInitialized = localStorage.getItem("noname_inited"); - const assetURL = - location.protocol.startsWith("http") || - typeof nonameInitialized != "string" || - nonameInitialized == "nodejs" - ? "" - : nonameInitialized; + const assetURL = location.protocol.startsWith("http") || typeof nonameInitialized != "string" || nonameInitialized == "nodejs" ? "" : nonameInitialized; const userAgent = navigator.userAgent.toLowerCase(); - const exit = () => { - const ios = - userAgent.includes("iphone") || - userAgent.includes("ipad") || - userAgent.includes("macintosh"); + // 使用到的文本 + const globalText = { + GPL_ALERT: ["①无名杀是一款基于GPLv3协议的开源软件!", "你可以在遵守GPLv3协议的基础上任意使用,修改并转发《无名杀》,以及所有基于《无名杀》开发的拓展。", "点击“确定”即代表您认可并接受GPLv3协议↓️", "https://www.gnu.org/licenses/gpl-3.0.html", "②无名杀官方发布地址仅有GitHub仓库!", "其他所有的所谓“无名杀”社群(包括但不限于绝大多数“官方”QQ群、QQ频道等)均为玩家自发组织,与无名杀官方无关!"].join("\n"), + LOAD_ENTRY_FAILED: ["您使用的浏览器或《无名杀》客户端加载内容失败!", "请检查是否缺少游戏文件!隔版本更新请下载完整包而不是离线包!", "目前使用的浏览器UA信息为: ", userAgent, "若您使用的客户端为自带内核的旧版“兼容版”,请及时更新客户端版本!", "若您使用的客户端为手机端的非兼容版《无名杀》,请尝试更新手机的WebView内核,或者更换为1.8.2版本及以上的兼容版!", "若您是直接使用浏览器加载index.html进行游戏,请改为运行文件夹内的“noname-server.exe”(或使用VSCode等工具启动Live Server),以动态服务器的方式启动《无名杀》!", "若您使用的是苹果端,请至少将Safari升级至14.5.0!"].join("\n"), + REDIRECT_TIP: ["您使用的浏览器或无名杀客户端内核版本过低,已经无法正常运行无名杀!", "目前使用的浏览器UA信息为: ", userAgent, "点击“确认”以前往GitHub下载最新版无名杀客户端(可能需要科学上网)。", "稍后您的无名杀将自动退出(可能的话)"].join("\n"), + SAFARI_VERSION_NOT_SUPPORT: ["您使用的Safari浏览器无法支持当前无名杀所需的功能,请至少升级至14.5.0!", "当前浏览器的UA为: ", userAgent, "稍后您的无名杀将自动退出(可能的话)"].join("\n"), + }; + + // 检查 window 对象中是否存在 "__core-js_shared__" 属性 + if (!("__core-js_shared__" in window)) { + // 如果不存在,则执行以下操作 + await new Promise(resolve => { + // 创建一个新的