在js文件夹下面新建grayscale.js文件

image-20231207154811805


injecthexo里面(该步骤后续不再赘述)

image-20231207154633197


编写grayscale.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
/*
* @Description: 网站置灰
* @Author: 5t5
* @Time: 2023/12/7 15:37
*/

function PublicSacrificeDay() {
// 你想要置灰的特殊日子的日期
let PSFarr = ["0403", "0512", "0707", "0918", "0930", "1213"];
let currentDate = new Date();
let mm = currentDate.getMonth() + 1;
let dd = currentDate.getDate();

let str = `${mm < 10 ? '0' : ''}${mm}${dd < 10 ? '0' : ''}${dd}`;

return PSFarr.includes(str) ? 1 : 0;
}

function setGrayStyle() {
document.getElementsByTagName("html")[0].setAttribute(
"style",
"filter: gray !important; filter: grayscale(100%); -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); -ms-filter: grayscale(100%); -o-filter: grayscale(100%);"
)
}

if (PublicSacrificeDay()) {
setGrayStyle()
}