Merge pull request #937 from nofficalfs/PR-Branch-SafariFix

修复Safari的提示情况
This commit is contained in:
Spmario233 2024-02-13 15:57:27 +08:00 committed by GitHub
commit 311c6c3e67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 21 deletions

View File

@ -56,28 +56,35 @@ new Promise(resolve => {
/**
*
* @returns {["firefox" | "chrome" | "safari" | "other", number]}
* @returns {["firefox" | "chrome" | "safari" | "other", number, number, number]}
*/
function coreInfo() {
const regex = /(firefox|chrome|safari)\/([\d.]+)/;
let result;
if (!(result = userAgent.match(regex))) return ["other", NaN];
const regex = /(firefox|chrome|safari)\/(\d+(?:\.\d+)+)/
let result
if (!(result = userAgent.match(regex))) return ["other", NaN, NaN, NaN]
if (result[1] != "safari") {
const [major, minor, patch] = result[2].split(".")
// @ts-ignore
if (result[1] !== "safari") return [result[1], parseInt(result[2])];
result = userAgent.match(/version\/([\d.]+).*safari/);
return [result[1], parseInt(major), parseInt(minor), parseInt(patch)]
}
result = userAgent.match(/version\/(\d+(?:\.\d+)+).*safari/)
// @ts-ignore
return ["safari", parseInt(result[1])];
const [major, minor, patch] = result[1].split(".")
return ["safari", parseInt(major), parseInt(minor), parseInt(patch)]
}
const [core, version] = coreInfo();
const [core, major, minor, patch] = coreInfo();
const supportMap = {
"firefox": 60,
"chrome": 61,
// 因为coreInfo不考虑子版本故就强行只能以11运行
"safari": 11
"firefox": [60, 0, 0],
"chrome": [61, 0, 0],
"safari": [14, 5, 0]
}
const versions = [major, minor, patch]
if (core in supportMap && supportMap[core] > version) {
const tip = '检测到您的浏览器内核版本无法支持ES Module请立即升级浏览器或手机webview内核';
// current是需求的版本号versions[index]是浏览器环境本身的版本号
// 如果current > versions[index],即当前版本的浏览器版本号达不到要求的版本号,则可判定当前版本无法支持
// 如果versions[index]为NaN必然返回false由于ua信息不可能存在主版本号NaN的情况故不必考虑次版本号/修补版本号并不存在的情况
if (core in supportMap && supportMap[core].some((current, index) => current > versions[index])) {
const tip = '检测到您的浏览器内核版本无法支持当前无名杀所需的功能请立即升级浏览器或手机webview内核';
console.error(tip);
const redirect_tip = `您使用的浏览器或无名杀客户端内核版本过低,已经无法正常运行无名杀!\n目前使用的浏览器UA信息为\n${userAgent}\n点击“确认”以前往GitHub下载最新版无名杀客户端可能需要科学上网\n稍后您的无名杀将自动退出(可能的话)`;
if (confirm(redirect_tip)) {

View File

@ -18,15 +18,19 @@ export class Get extends Uninstantable {
*
* > 其他后续或许会增加`IE`永无可能
*
* @returns {["firefox" | "chrome" | "safari" | "other", number]}
* @returns {["firefox" | "chrome" | "safari" | "other", number, number, number]}
*/
static coreInfo() {
const regex = /(firefox|chrome|safari)\/([\d.]+)/;
let result;
if (!(result = userAgent.match(regex))) return ["other", NaN];
if (result[1] != "safari") return [result[1], parseInt(result[2])];
result = userAgent.match(/version\/([\d.]+).*safari/);
return ["safari", parseInt(result[1])];
const regex = /(firefox|chrome|safari)\/(\d+(?:\.\d+)+)/
let result
if (!(result = userAgent.match(regex))) return ["other", NaN, NaN, NaN]
if (result[1] != "safari") {
const [major, minor, patch] = result[2].split(".")
return [result[1], parseInt(major), parseInt(minor), parseInt(patch)]
}
result = userAgent.match(/version\/(\d+(?:\.\d+)+).*safari/)
const [major, minor, patch] = result[1].split(".")
return ["safari", parseInt(major), parseInt(minor), parseInt(patch)]
}
/**
* 返回 VCard[] 形式的所有牌用于印卡将遍历