2024-04-10更新:使用原生JavaScript,去除对jQuery库的依赖。
添加特殊日子自动开启全局黑白模式:昭昭前事,惕惕后人,勿忘历史,吾辈自强!
- 新建
[blog]\themes\butterfly\source\js\custom\MemorialDayMode.js
文件,并添加如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate();
const dateList = [ '7/7', '9/18', '12/13', ]; const toMonthDay = `${month}/${day}`;
var beginDate = new Date("2022-11-30 12:13:00"); var endDate = new Date("2022-12-07 00:00:01"); var today = day;
if (dateList.some((day) => day === toMonthDay)) { document.documentElement.style.filter = "grayscale(100%)"; console.log("昭昭前事,惕惕后人,勿忘历史,吾辈自强!"); }
else if (today >= beginDate && today <= endDate) { document.documentElement.style.filter = "grayscale(100%)"; console.log("昭昭前事,惕惕后人,勿忘历史,吾辈自强!"); }
|
- 文件
[blog]\_config.butterfly.yml
添加如下两行:
1 2 3 4
| inject: bottom: - <script defer src="/js/custom/MemorialDayMode.js"></script>
|
大功告成!
隶属于文章hexo 博客 butterfly 主题安装及魔改笔记