[Joe]评论正确显示Windows11版本

[Joe]评论正确显示Windows11版本

苏苏
2023-08-10 / 0 评论 / 14 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2023年08月10日,已超过722天没有更新,若内容或图片失效,请留言反馈。

Joe主题的评论支持显示用户的操作系统版本。目前很多用户已将系统升级至Windows11,但是User-Agent并没有更新,依然是Windows NT 10.0。因此,完全靠UA来识别用户操作系统版本不再准确。

通过查询微软知识库( 使用 User-Agent 客户端提示检测Windows 11和 CPU 体系结构 ),发现了解决方案:可以配合js来实现Windows版本识别。

增加js

将以下js添加到Joe的“自定义js”

navigator.userAgentData && navigator.userAgentData.getHighEntropyValues(["platformVersion"])
 .then(ua => {
   if (navigator.userAgentData.platform === "Windows") {
     const majorPlatformVersion = parseInt(ua.platformVersion.split('.')[0]);
     if (majorPlatformVersion >= 13) {
        document.cookie = "win11=true;path=/";
      }
      else if (majorPlatformVersion > 0) {
        document.cookie = "win10=true;path=/";
      }
      else {
        //console.log("Before Windows 10");
      }
   }
   else {
     //console.log("Not running on Windows");
   }
 });

修改php文件

打开/usr/themes/Joe/core/function.php,搜索 _getAgentOS 函数,在判断为Windows10的后面追加一句,用来判断是否是Windows11:

...
} else if (preg_match('/nt 10.0/i', $agent)) {
  $os = 'Windows 10';
  if (isset($_COOKIE['win11']) && $_COOKIE['win11']){
      $os = 'Windows 11';
  }
}
...

至此,便可以正确区分用户使用的Windows版本了。

1

评论 (0)

取消