You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

browser-compatibility.js 3.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const unsupportFeatures = (()=>{
  2. const features = [
  3. {name: "Optional chaining (?.) / 可选链操作符(?.)", url: "https://caniuse.com/mdn-javascript_operators_optional_chaining", test: ()=>!Boolean(eval("undefined?.undefined || true"))},
  4. {name: "Nullish coalescing operator (??) / 空值合并操作符(??)", url: "https://caniuse.com/mdn-javascript_operators_nullish_coalescing", test: ()=>!Boolean(eval("undefined ?? true"))},
  5. {name: "BigInt value (1n) / BigInt 数据类型(1n)", url: "https://caniuse.com/bigint", test: ()=>!Boolean(eval("1n"))},
  6. //{name: "Private class fields (#name) / 类私有域(#name)", url: "https://caniuse.com/mdn-javascript_classes_private_class_fields", test: ()=>!Boolean(eval("class test {#v = 0;}; true;"))},
  7. ]
  8. return features.filter(feature=>{
  9. try {
  10. return feature.test();
  11. } catch (e) {
  12. if (e.name !== 'SyntaxError') throw e // Throw the error if it is not a SyntaxError
  13. return true;
  14. }
  15. })
  16. })();
  17. if (unsupportFeatures.length) {
  18. const browserVersion = ((UA)=>{
  19. let regRes;
  20. if (regRes = /\b(Firefox|Chrome)\/([\d\.]+)/ig.exec(UA)) {
  21. return `${regRes[1]} ${regRes[2]}`;
  22. } else if (regRes = /\bVersion\/([\d\.]+)\s+.*\b(Safari)\//ig.exec(UA)) {
  23. return `${regRes[2]} ${regRes[1]}`;
  24. } else {
  25. UA;
  26. }
  27. })(navigator.userAgent);
  28. let alertStr;
  29. if (/^zh-(?:han(?:s|t)-)?/.test(navigator.language)) {
  30. alertStr =
  31. `🙁浏览器内核版本太老<br>
  32. 您的浏览器版本为: ${browserVersion}<br>
  33. 您的浏览器内核不支持本程序使用的以下技术
  34. <ol>
  35. ${unsupportFeatures.map(feature=>`<li><a href="${feature.url}">${feature.name}</a></li>`).join('')}
  36. </ol>
  37. 请更新您的浏览器内核到 Firefox(火狐) ≥ 90 或 Chrome(谷歌) ≥ 80 或 Safari ≥ 14.5。`;
  38. } else {
  39. alertStr =
  40. `🙁Browser kernel is too old<br>
  41. Your browser is: ${browserVersion}<br>
  42. Your browser kernel does not support the following technologies used by this program:
  43. <ol>
  44. ${unsupportFeatures.map(feature=>`<li><a href="${feature.url}">${feature.name}</a></li>`).join('')}
  45. </ol>
  46. Please update your browser core to Firefox ≥ 90 or Chrome ≥ 80 or Safari ≥ 14.5`;
  47. }
  48. //alert(alertStr);
  49. document.write(alertStr);
  50. }
  51. let denied = ((UA)=>{
  52. return /\b(?:MicroMessenger|WeChat|Weixin|QQ|AliApp)\b/.test(UA);
  53. })(navigator.userAgent);
  54. if (denied) {
  55. const mask = document.createElement("div");
  56. mask.id = "denied-mask";
  57. const css = `
  58. #denied-mask {
  59. position: fixed;
  60. height: 100%;
  61. width: 100%;
  62. top: 0;
  63. left: 0;
  64. background-color: #000A;
  65. }
  66. .alert {
  67. font-size: 2em;
  68. font-weight: bold;
  69. color: white;
  70. text-align: center;
  71. }
  72. `;
  73. const style = mask.appendChild(document.createElement("style"));
  74. style.appendChild(document.createTextNode(css));
  75. const alertDiv = mask.appendChild(document.createElement("div"));
  76. alertDiv.className = "alert"
  77. alertDiv.appendChild(document.createTextNode("请勿使用内置浏览"));
  78. alertDiv.appendChild(document.createElement("br"));
  79. alertDiv.appendChild(document.createTextNode("点击菜单使用正常浏览器打开↗"));
  80. window.addEventListener("load", ()=>{
  81. document.body.appendChild(mask);
  82. });
  83. }

智龙迷城队伍图制作工具