Typecho 博客文章评论添加显示 UserAgent(UA)的功能

news2024/9/25 19:19:58
  • 本篇文章实现了为 Typecho 博客文章评论添加显示 UserAgent(UA)的功能
  • 本功能可替代 UserAgent 插件,更美观、简洁且好看

效果显示

  • 大概就是这样了,实际效果请看我的评论!
    TIM截图20200226131837.png
  • 目前可以识别的操作系统以及浏览器
    3404854218.png

食用方法

  • 这里以 Mirages主题为例,其他主题操作方法类似。

首先
将下面这段 css 全部加入到 Mirages/css/7.10.0/Mirages.min.css 末尾。

.ua-icon{display:inline-block;width:1pc;height:1pc;background-size:cover;background-repeat:no-repeat;vertical-align:text-top}.icon-360{background-image:url(https://img.jichun29.cn/img/20200226125429.png)}.icon-android{background-image:url(https://img.jichun29.cn/img/20200226125423.png);height:19px}.icon-apple{background-image:url(https://img.jichun29.cn/img/20200226125422.png)}.icon-baidu{background-image:url(https://img.jichun29.cn/img/20200226125424.png)}.icon-chrome{background-image:url(https://img.jichun29.cn/img/20200226125427.png)}.icon-edge{background-image:url(https://img.jichun29.cn/img/20200226125425.png)}.icon-firefox{background-image:url(https://img.jichun29.cn/img/20200226125426.png)}.icon-google{background-image:url(https://img.jichun29.cn/img/20200226125428.png)}.icon-ie{background-image:url(https://img.jichun29.cn/img/20200226125431.png)}.icon-liebao{background-image:url(https://img.jichun29.cn/img/20200226125430.png)}.icon-linux{background-image:url(https://img.jichun29.cn/img/20200226125433.png)}.icon-mac{background-image:url(https://img.jichun29.cn/img/20200226125432.png)}.icon-opera{background-image:url(https://img.jichun29.cn/img/20200226125434.png)}.icon-qq{background-image:url(https://img.jichun29.cn/img/20200226125435.png)}.icon-quark{background-image:url(https://img.jichun29.cn/img/20200226125437.png)}.icon-safari{background-image:url(https://img.jichun29.cn/img/20200226125438.png)}.icon-ubuntu{background-image:url(https://img.jichun29.cn/img/20200226125436.png)}.icon-uc{background-image:url(https://img.jichun29.cn/img/20200226125439.png)}.icon-win1{background-image:url(https://img.jichun29.cn/img/20200226125440.png)}.icon-win2{background-image:url(https://img.jichun29.cn/img/20200226125421.png)}
  • 也可后台加入自定义 css 或是直接在 header.php 中引入

然后
找到 Mirages/functions.php,将下面代码完整复制,加到 functions.php 文件的最末尾

    // 获取浏览器信息
    function getBrowser($agent)
    {
        if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) {
            $outputer = '<i class="ua-icon icon-ie"></i>&nbsp;&nbsp;Internet Explore';
        } else if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) {
          $str1 = explode('Firefox/', $regs[0]);
    $FireFox_vern = explode('.', $str1[1]);
            $outputer = '<i class="ua-icon icon-firefox"></i>&nbsp;&nbsp;FireFox';
        } else if (preg_match('/Maxthon([\d]*)\/([^\s]+)/i', $agent, $regs)) {
          $str1 = explode('Maxthon/', $agent);
    $Maxthon_vern = explode('.', $str1[1]);
            $outputer = '<i class="ua-icon icon-edge"></i>&nbsp;&nbsp;MicroSoft Edge';
        } else if (preg_match('#360([a-zA-Z0-9.]+)#i', $agent, $regs)) {
    $outputer = '<i class="ua-icon icon-360"></i>&nbsp;&nbsp;360极速浏览器';
        } else if (preg_match('/Edge([\d]*)\/([^\s]+)/i', $agent, $regs)) {
            $str1 = explode('Edge/', $regs[0]);
    $Edge_vern = explode('.', $str1[1]);
            $outputer = '<i class="ua-icon icon-edge"></i>&nbsp;&nbsp;MicroSoft Edge';
        } else if (preg_match('/UC/i', $agent)) {
                  $str1 = explode('rowser/',  $agent);
    $UCBrowser_vern = explode('.', $str1[1]);
            $outputer = '<i class="ua-icon icon-uc"></i>&nbsp;&nbsp;UC浏览器';
        }  else if (preg_match('/QQ/i', $agent, $regs)||preg_match('/QQBrowser\/([^\s]+)/i', $agent, $regs)) {
                      $str1 = explode('rowser/',  $agent);
    $QQ_vern = explode('.', $str1[1]);
            $outputer = '<i class= "ua-icon icon-qq"></i>&nbsp;&nbsp;QQ浏览器';
        } else if (preg_match('/UBrowser/i', $agent, $regs)) {
                  $str1 = explode('rowser/',  $agent);
    $UCBrowser_vern = explode('.', $str1[1]);
            $outputer = '<i class="ua-icon icon-uc"></i>&nbsp;&nbsp;UC浏览器';
        }  else if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) {
            $outputer = '<i class= "ua-icon icon-opera"></i>&nbsp;&nbsp;Opera';
        } else if (preg_match('/Chrome([\d]*)\/([^\s]+)/i', $agent, $regs)) {
    $str1 = explode('Chrome/', $agent);
    $chrome_vern = explode('.', $str1[1]);
            $outputer = '<i class="ua-icon icon-chrome""></i>&nbsp;&nbsp;Google Chrome';
        } else if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) {
             $str1 = explode('Version/',  $agent);
    $safari_vern = explode('.', $str1[1]);
            $outputer = '<i class="ua-icon icon-safari"></i>&nbsp;&nbsp;Safari';
        } else{
            $outputer = '<i class="ua-icon icon-chrome"></i>&nbsp;&nbsp;Google Chrome';
        }
        echo $outputer;
    }
    // 获取操作系统信息
    function getOs($agent)
    {
        $os = false;
     
        if (preg_match('/win/i', $agent)) {
            if (preg_match('/nt 6.0/i', $agent)) {
                $os = '&nbsp;&nbsp;<i class= "ua-icon icon-win1"></i>&nbsp;&nbsp;Windows Vista&nbsp;/&nbsp;';
            } else if (preg_match('/nt 6.1/i', $agent)) {
                $os = '&nbsp;&nbsp;<i class= "ua-icon icon-win1"></i>&nbsp;&nbsp;Windows 7&nbsp;/&nbsp;';
            } else if (preg_match('/nt 6.2/i', $agent)) {
                $os = '&nbsp;&nbsp;<i class="ua-icon icon-win2"></i>&nbsp;&nbsp;Windows 8&nbsp;/&nbsp;';
            } else if(preg_match('/nt 6.3/i', $agent)) {
                $os = '&nbsp;&nbsp;<i class= "ua-icon icon-win2"></i>&nbsp;&nbsp;Windows 8.1&nbsp;/&nbsp;';
            } else if(preg_match('/nt 5.1/i', $agent)) {
                $os = '&nbsp;&nbsp;<i class="ua-icon icon-win1"></i>&nbsp;&nbsp;Windows XP&nbsp;/&nbsp;';
            } else if (preg_match('/nt 10.0/i', $agent)) {
                $os = '&nbsp;&nbsp;<i class="ua-icon icon-win2"></i>&nbsp;&nbsp;Windows 10&nbsp;/&nbsp;';
            } else{
                $os = '&nbsp;&nbsp;<i class="ua-icon icon-win2"></i>&nbsp;&nbsp;Windows X64&nbsp;/&nbsp;';
            }
        } else if (preg_match('/android/i', $agent)) {
        if (preg_match('/android 9/i', $agent)) {
                $os = '&nbsp;&nbsp;<i class="ua-icon icon-android"></i>&nbsp;&nbsp;Android Pie&nbsp;/&nbsp;';
            }
        else if (preg_match('/android 8/i', $agent)) {
                $os = '&nbsp;&nbsp;<i class="ua-icon icon-android"></i>&nbsp;&nbsp;Android Oreo&nbsp;/&nbsp;';
            }
        else{
                $os = '&nbsp;&nbsp;<i class="ua-icon icon-android"></i>&nbsp;&nbsp;Android&nbsp;/&nbsp;';
        }
        }
        else if (preg_match('/ubuntu/i', $agent)) {
            $os = '&nbsp;&nbsp;<i class="ua-icon icon-ubuntu"></i>&nbsp;&nbsp;Ubuntu&nbsp;/&nbsp;';
        } else if (preg_match('/linux/i', $agent)) {
            $os = '&nbsp;&nbsp;<i class= "ua-icon icon-linux"></i>&nbsp;&nbsp;Linux&nbsp;/&nbsp;';
        } else if (preg_match('/iPhone/i', $agent)) {
            $os = '&nbsp;&nbsp;<i class="ua-icon icon-apple"></i>&nbsp;&nbsp;iPhone&nbsp;/&nbsp;';
        } else if (preg_match('/mac/i', $agent)) {
            $os = '&nbsp;&nbsp;<i class="ua-icon icon-mac"></i>&nbsp;&nbsp;MacOS&nbsp;/&nbsp;';
        }else if (preg_match('/fusion/i', $agent)) {
            $os = '&nbsp;&nbsp;<i class="ua-icon icon-android"></i>&nbsp;&nbsp;Android&nbsp;/&nbsp;';
        } else {
            $os = '&nbsp;&nbsp;<i class="ua-icon icon-linux"></i>&nbsp;&nbsp;Linux&nbsp;/&nbsp;';
        }
        echo $os;
    }

最后

在 Mirages/lib/comments.php 中找到合适位置添加以下代码:

<span class="comment-ua">
    <?php getOs($comments->agent); ?>
    <?php getBrowser($comments->agent); ?></span>

TIM截图20200226131539.png

如果修改完都显示 Linux 的话,需要将上面的 $comments 替换成 $this 即可,注意代码缩进
修改完后刷新浏览器缓存,现在你的评论 UA 已经变得很漂亮啦!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1539174.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

AI智能分析网关V4在养老院视频智能监控场景中的应用

随着科技的快速发展&#xff0c;智能监控技术已经广泛应用于各个领域&#xff0c;尤其在养老院这一特定场景中&#xff0c;智能监控方案更是发挥着不可或缺的作用。尤其是伴随着社会老龄化趋势的加剧&#xff0c;养老院的安全管理问题也日益凸显。为了确保老人的生活安全&#…

day16-环形链表

问题描述&#xff1a; 给定一个链表的头节点 head &#xff0c;返回链表开始入环的第一个节点。 如果链表无环&#xff0c;则返回 null。如果链表中有某个节点&#xff0c;可以通过连续跟踪 next 指针再次到达&#xff0c;则链表中存在环。 为了表示给定链表中的环&#xff0…

canvas跟随鼠标移动画带透明度的线

提示&#xff1a;canvas画线 文章目录 前言一、带透明度的线二、试错&#xff0c;只有lineTo的时候画&#xff0c;只有最后地方是透明度的三、试错&#xff0c;只存上一次的点&#xff0c;线会出现断裂的情况总结 前言 一、带透明度的线 test.html <!DOCTYPE html> &l…

@ohos.router (页面路由)实现页面间跳转与数据传递

一、描述 本模块提供通过不同的url访问不同的页面&#xff0c;包括跳转到应用内的指定页面、用应用内的某个页面替换当前页面、返回上一页面或指定的页面等。 二、导入模块 import router from ohos.router 三、router.pushUrl 1、描述 跳转到应用内的指定页面。 router.pu…

OpenAI GPT商店面临质量与合规问题;黄仁勋预测:十年内AI将实时生成游戏画面

&#x1f989; AI新闻 &#x1f680; OpenAI GPT商店面临质量与合规问题 摘要&#xff1a;OpenAI旗下的GPT商店因存在大量涉嫌侵权内容、助长学术不诚实行为及违规内容等问题而引起关注。其中包括未经授权使用迪士尼、漫威角色生成内容的GPT模型&#xff0c;以及声称能绕过剽…

Wireshark TS | DNS 案例分析之外的思考

前言 承接之前一篇《Packet Challenge 之 DNS 案例分析》&#xff0c;在数据包跟踪文件 dnsing.pcapng 中&#xff0c;关于第 4 题&#xff08;What is the largest DNS response time seen in this trace file? &#xff09;的分析过程中曾经碰到一个小问题&#xff0c;主要…

vue-quill-editor和vue-ueditor-wrap富文本编辑器应用

目录 一、vue-quill-editor 1.1、界面展示 1.2、代码介绍 1.2.1、安装 1.2.2、配置 1.2.3、代码应用 1.2.4、提取内容 二、vue-ueditor-wrap 2.1、界面展示 2.2、代码介绍 2.2.1、安装 2.2.2、配置 2.2.3、代码应用 一、vue-quill-editor 1.1、界面展示 文本输出…

极简自建web视频会议,私有云,rtmp/rtsp/webrtc一键参会直播会议互动方案

随着视频互动深入工作日常&#xff0c;很多客户需要自建一个会议&#xff0c;监控的交互平台&#xff0c;目前外面不管是开源还是非开源的平台&#xff0c;都是极为复杂&#xff0c;一般linux安装库关联部署复杂&#xff0c;非技术人员根本没办法使用&#xff0c;不方便集成部署…

C#基于SMTP的邮件发送

准备工作 注册邮箱 首先我们需要注册一个作为发送邮件的邮箱&#xff0c;这一步可以直接进入网易邮箱官网进行注册&#xff0c; 注册地址&#xff1a;https://mail.163.com/ 这里我们可以选择【快速注册】和【普通注册】&#xff0c;如图1-1所示&#xff0c;这里我选择的普…

vue3初步学习

vue3初步学习 vue模版 练习代码如下 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>实验4</ti…

BAAI 北京智源研究院

文章目录 关于 BAAI产品悟道大模型FlagOpen 大模型技术天演 生物智能九鼎 智算平台 关于 BAAI BAAI : Beijing Academy of Artificial Intelligence 北京智源研究院 官网&#xff1a;https://www.baai.ac.cnhf : https://huggingface.co/BAAI百度百科 https://baike.baidu.co…

翻看去年录的幼儿园选择的视频,我被打脸了,真疼

去年 7 月份发了一个幼儿园选择的视频&#xff0c;如今回头看&#xff0c;我被打脸了&#xff0c;真疼呀 去年的选择 省流版&#xff1a;当时我列了三种选择&#xff1a; 普惠公立幼儿园普惠私立或民办有政府补贴的幼儿园私立幼儿园 以下讨论是基于我个人情况&#xff0c;在北京…

使用POI以OLE对象的形式向excel中插入附件(pdf为例)

前言&#xff1a; 最近在使用easyExcel操作excel文件时&#xff0c;一直想找到一个方法可以往excel中填充附件&#xff0c;但是目前只发现POI可以插入附件&#xff0c;于是将方法记录如下&#xff1a; 实现&#xff1a; 这个方法主要是使用 Apache POI 的 HSSFWorkbook 类来…

算法公式汇总

文章目录 三角函数定义式诱导公式平方关系两角和与差的三角函数积化和差公式和差化积公式倍角公式半角公式万能公式其他公式反三角函数恒等式 三角函数定义式 三角函数 定义式 余切&#xff1a; c o t A 1 t a n A \text { 余切&#xff1a;} \ cotA \frac{1}{tanA} 余切&a…

javaWeb项目-高校社团活动管理平台功能介绍

开发工具&#xff1a;IDEA 、Eclipse 编程语言: Java 数据库: MySQL5.7 框架&#xff1a;ssm、Springboot 前端&#xff1a;Vue、ElementUI 关键技术&#xff1a;springboot、SSM、vue、MYSQL、MAVEN 数据库工具&#xff1a;Navicat、SQLyog 大学生社团活动平台&#xff1b;Ja…

第十一届蓝桥杯大赛第二场省赛试题 CC++ 研究生组-子串分值和

solution1&#xff08;通过40%&#xff09; 依次求子串并统计出现过的字母个数 #include<iostream> #include<string> #include<set> using namespace std; int main(){string s, subs;cin >> s;int len s.size(), ans 0;for(int j 1; j < len…

AI开源概览及工具使用

一、前言 随着ChatGPT热度的攀升&#xff0c;越来越多的公司也相继推出了自己的AI大模型&#xff0c;如文心一言、通义千问等。各大应用也开始内置AI玩法&#xff0c;如抖音的AI特效&#xff1b; 关联资源&#xff1a;代码 GitHub、相关论文、项目Demo、产品文档、Grok Ai、gr…

国内git最新版本下载链接2.44

git官网地址:Git - Downloading Package (git-scm.com) 蓝奏云: ​​​​​​gGit-2.44.0-64-bit.exe - 蓝奏云 git仓库地址:git/git: Git Source Code Mirror - This is a publish-only repository but pull requests can be turned into patches to the mailing list via …

机器学习:智能时代的核心引擎

目录 一、什么是机器学习 二、监督学习 三、无监督学习 四、半监督学习 五、强化学习 一、什么是机器学习 机器学习是人工智能的一个分支&#xff0c;它主要基于计算机科学&#xff0c;旨在使计算机系统能够自动地从经验和数据中进行学习并改进&#xff0c;而无需进行明确…

LeetCode刷题【树状数组、并查集、二叉树】

目录 树状数组307. 区域和检索 - 数组可修改406. 根据身高重建队列673. 最长递增子序列的个数1409. 查询带键的排列 并查集128. 最长连续序列130. 被围绕的区域 二叉树94. 二叉树的中序遍历104. 二叉树的最大深度101. 对称二叉树543. 二叉树的直径108. 将有序数组转换为二叉搜索…