-
Notifications
You must be signed in to change notification settings - Fork 0
/
mourning.js
75 lines (74 loc) · 2.96 KB
/
mourning.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
!function () {
"use strict";
var scriptElement = document.currentScript;
var days = scriptElement.getAttribute("days").split(',');
var customText = scriptElement.getAttribute("text");
var duration = parseInt(scriptElement.getAttribute("duration"));
var nolog = scriptElement.getAttribute("nolog");
/* 哀悼日网站变灰 */
document.addEventListener("DOMContentLoaded", function () {
if (aidaori()) {
var htmlElement = document.querySelector("html");
htmlElement.style.filter = "gray !important";
htmlElement.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
htmlElement.style.filter = "grayscale(100%)";
htmlElement.style.webkitFilter = "grayscale(100%)";
htmlElement.style.MozFilter = "grayscale(100%)";
htmlElement.style.msFilter = "grayscale(100%)";
htmlElement.style.oFilter = "grayscale(100%)";
createCandleText(customText);
// 打印仓库地址
if (nolog !== "true") {
console.log(customText + " mourning哀悼日 Github仓库: https://github.com/byteforgecn/mourning");
}
}
// 判断日期
function aidaori() {
var aidaoriarr = days;
var mydate = new Date();
var str = "";
var mm = mydate.getMonth() + 1;
if (mydate.getMonth() > 8) {
str += mm;
} else {
str += "0" + mm;
}
if (mydate.getDate() > 9) {
str += mydate.getDate();
} else {
str += "0" + mydate.getDate();
}
if (aidaoriarr.indexOf(str) > -1) {
return 1;
} else {
return 0;
}
}
// 创建蜡烛文字的函数
function createCandleText(text) {
var candleTextElement = document.createElement("div");
candleTextElement.id = "candleText";
candleTextElement.textContent = text;
var style = candleTextElement.style;
style.position = "fixed";
style.top = "50%";
style.left = "50%";
style.transform = "translate(-50%, -50%)";
style.fontSize = "24px";
style.fontWeight = "bold";
style.color = "#000";
style.opacity = 0;
style.transition = "opacity 1s";
document.body.appendChild(candleTextElement);
setTimeout(function () {
candleTextElement.style.opacity = 1;
setTimeout(function () {
candleTextElement.style.opacity = 0;
setTimeout(function () {
document.body.removeChild(candleTextElement);
}, 1000);
}, duration);
}, 100);
}
})
}()