@@ -1,4 +1,4 @@
const unsupportFeatures = (()=>{
(()=>{
function runCodeWithFunction(obj) {
return Function(`"use strict"; return (${obj})`)();
}
@@ -22,8 +22,9 @@
{name: "Private class fields (#name) / 类私有域(#name)", version:{firefox:90,chrome:74,safari:14.5}, url: "https://caniuse.com/mdn-javascript_classes_private_class_fields", test: ()=>Boolean(runCodeWithFunction("class test {#v = 0;}, true"))},
{name: "Dialog element / Dialog 元素", version:{firefox:98,chrome:37,safari:15.4}, url: "https://caniuse.com/dialog", test: ()=>Boolean(window.HTMLDialogElement)},
// {name: "Class static initialization blocks / 静态初始化块", version:{firefox:93,chrome:94,safari:16.4}, url: "https://caniuse.com/mdn-javascript_classes_static_initialization_blocks", test: ()=>supportsPseudoClass(":not(html)")},
]
return features.filter(feature=>{
];
const unsupportFeatures = features.filter(feature=>{
try {
return !feature.test();
} catch (e) {
@@ -31,86 +32,87 @@
console.error(e);
return true;
}
})
})();
if (unsupportFeatures.length) {
const browserVersion = ((UA)=>{
let regRes;
if (regRes = /\b(Firefox|Chrome)\/([\d\.]+)/ig.exec(UA)) {
return `${regRes[1]} ${regRes[2]}`;
} else if (regRes = /\bVersion\/([\d\.]+)\s+.*\b(Safari)\//ig.exec(UA)) {
return `${regRes[2]} ${regRes[1]}`;
} else {
UA;
}
})(navigator.userAgent);
//支持的最低版本
const needBrowserVersion = unsupportFeatures.reduce((pre,{version})=>{
pre.firefox = Math.max(pre.firefox,version.firefox);
pre.chrome = Math.max(pre.chrome,version.chrome);
pre.safari = Math.max(pre.safari,version.safari);
return pre;
}, {firefox:0,chrome:0,safari:0});
});
let alertStr;
if (/^zh-(?:han(?:s|t)-)?/.test(navigator.language)) {
alertStr =
`<div>🙁浏览器内核版本太老<br>
if (unsupportFeatures.length) {
const browserVersion = ((UA)=>{
let regRes;
if (regRes = /\b(Firefox|Chrome)\/([\d\.]+)/ig.exec(UA)) {
return `${regRes[1]} ${regRes[2]}`;
} else if (regRes = /\bVersion\/([\d\.]+)\s+.*\b(Safari)\//ig.exec(UA)) {
return `${regRes[2]} ${regRes[1]}`;
} else {
UA;
}
})(navigator.userAgent);
//支持的最低版本
const needBrowserVersion = unsupportFeatures.reduce((pre,{version})=>{
pre.firefox = Math.max(pre.firefox,version.firefox);
pre.chrome = Math.max(pre.chrome,version.chrome);
pre.safari = Math.max(pre.safari,version.safari);
return pre;
}, {firefox:0,chrome:0,safari:0});
let alertStr;
if (/^zh-(?:han(?:s|t)-)?/.test(navigator.language)) {
alertStr =
`<p lang="zh">🙁浏览器内核版本太老<br>
您的浏览器版本为: ${browserVersion}<br>
您的浏览器内核不支持本程序使用的以下技术
<ol>
${unsupportFeatures.map(feature=>`<li><a href="${feature.url}">${feature.name}</a></li>`).join('')}
</ol>
请更新您的浏览器内核到 Firefox(火狐) ≥ ${needBrowserVersion.firefox} 或 Chrome(谷歌) ≥ ${needBrowserVersion.chrome} 或 Safari ≥ ${needBrowserVersion.safari}。</div>`;
} else {
alertStr =
`<div>🙁Browser kernel is too old<br>
请更新您的浏览器内核到 Firefox(火狐) ≥ ${needBrowserVersion.firefox} 或 Chrome(谷歌) ≥ ${needBrowserVersion.chrome} 或 Safari ≥ ${needBrowserVersion.safari}。</p >`;
} else {
alertStr =
`<p lang="en" >🙁Browser kernel is too old<br>
Your browser is: ${browserVersion}<br>
Your browser kernel does not support the following technologies used by this program:
<ol>
${unsupportFeatures.map(feature=>`<li><a href="${feature.url}">${feature.name}</a></li>`).join('')}
</ol>
Please update your browser core to Firefox ≥ ${needBrowserVersion.firefox} or Chrome ≥ ${needBrowserVersion.chrome} or Safari ≥ ${needBrowserVersion.safari}</div>`;
Please update your browser core to Firefox ≥ ${needBrowserVersion.firefox} or Chrome ≥ ${needBrowserVersion.chrome} or Safari ≥ ${needBrowserVersion.safari}</p>`;
}
//alert(alertStr);
document.write(alertStr);
}
//alert(alertStr);
document.write(alertStr);
}
if (/\b(?:MicroMessenger|WeChat|Weixin|QQ|AliApp)\b/.test(navigator.userAgent)) {
const mask = document.createElement("div");
mask.id = "denied-mask";
const css = `
#denied-mask {
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
background-color: #000A;
}
.alert {
font-size: 2em;
font-weight: bold;
color: white;
text-align: center;
if (/\b(?:MicroMessenger|WeChat|Weixin|QQ|AliApp)\b/.test(navigator.userAgent)) {
const mask = document.createElement("div");
mask.id = "denied-mask";
const css = `
#denied-mask {
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
background-color: #000A;
}
.alert {
font-size: 2em;
font-weight: bold;
color: white;
text-align: center;
}
`;
const style = mask.appendChild(document.createElement("style"));
style.appendChild(document.createTextNode(css));
const alertDiv = mask.appendChild(document.createElement("div"));
alertDiv.className = "alert";
alertDiv.innerHTML = `请勿使用APP内置浏览器,会有功能缺失<br>点击菜单使用正常浏览器打开↗`;
const removeMe = mask.appendChild(document.createElement("button"));
removeMe.append("我知道了");
removeMe.onclick = ()=>{
mask.remove();
delete mask;
};
const event = window.addEventListener("load", ()=>{
document.body.appendChild(mask);
window.removeEventListener(event);
});
}
`;
const style = mask.appendChild(document.createElement("style"));
style.appendChild(document.createTextNode(css));
const alertDiv = mask.appendChild(document.createElement("div"));
alertDiv.className = "alert";
alertDiv.innerHTML = `请勿使用内置浏览<br>点击菜单使用正常浏览器打开↗`;
const removeMe = mask.appendChild(document.createElement("button"));
removeMe.append("我知道了");
removeMe.onclick = ()=>{
mask.remove();
delete mask;
};
})
const event = window.addEventListener("load", ()=>{
document.body.appendChild(mask);
window.removeEventListener(event);
});
}