本文介绍下如何给Hexo NexT 主题中添加网页标题特效

准备工作

新增tittlecheat.js

在next\source\js\oiyou文件夹下创建tittlecheat.js,添加代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!--崩溃欺骗-->
<!--其中注释部分需要jquery-->
var OriginTitle = document.title;
var titleTime;
document.addEventListener('visibilitychange', function () {
if (document.hidden) {
//$('[rel="icon"]').attr('href', "/img/TEP.ico");
document.title = '╭(°A°`)╮ 页面崩溃啦 ~';
clearTimeout(titleTime);
}
else {
//$('[rel="icon"]').attr('href', "/favicon.ico");
document.title = '(ฅ>ω<*ฅ) 噫又好了~' + OriginTitle;
titleTime = setTimeout(function () {
document.title = OriginTitle;
}, 2000);
}
})
添加引用

在next\layout\_layout.swig文件中,添加引用(注:在swig末尾添加):

1
2
<!--崩溃欺骗-->
<script type="text/javascript" src="/js/oiyou/tittlecheat.js"></script>
引入jquery(可选)

首先下载jquery-3.4.1.min.js保存至next\source\js\jquery(路径可自己选,但是要引用正确)

在next\layout_partials\head\head.swig文件中,添加引用(注:在swig末尾添加):

1
2
<!-- jquery -->
<script src="/js/jquery/jquery-3.4.1.min.js"></script>

参考: https://asdfv1929.github.io/2018/01/25/crash-cheat/