6 - fluid主题无侵入式方式添加页面焦点监控文字

本文最后更新于:3 个月前

[√] 步骤


[√] 添加自定义monitortext.ejs文件


blog\source\_inject\文件夹中,新增文件monitortext.ejs,用于向页面中添加焦点监控代码,其内容为:

1
2
3
4
5
6
7
8
<% if(theme.fun_features.monitortext.enable) { %>
<script type="text/javascript">
/*窗口监视*/
var originalTitle = document.title;
window.onblur = function(){document.title = "<%- theme.fun_features.monitortext.text %>"};
window.onfocus = function(){document.title = originalTitle};
</script>
<% } %>

[√] 注入上述代码


在文件blog\scripts\page.js中,添加以下代码:

1
2
// 添加页面焦点监控文字
injects.bodyBegin.file('monitortext', "source/_inject/monitortext.ejs");

快照为:

1
2
3
4
5
6
hexo.extend.filter.register('theme_inject', function(injects) {
injects.bodyBegin.file('default', "source/_inject/bodyBegin.ejs");
injects.header.file('video-banner', 'source/_inject/header.ejs', { key: 'value' }, -1);
// 添加页面焦点监控文字(here)
injects.bodyBegin.file('monitortext', "source/_inject/monitortext.ejs");
});

[√] 编辑主题配置文件


  • 编辑fluid 主题配置文件,在 fun_features 项下添加
1
2
3
monitortext:
enable: true
text: 失去焦点显示该文字
image-20221224113744839

6 - fluid主题无侵入式方式添加页面焦点监控文字
https://alec-97.github.io/posts/3644508848/
作者
Shuai Zhao
发布于
2023年2月5日
许可协议