mirror of
https://github.com/stevenjoezhang/live2d-widget.git
synced 2024-11-22 12:39:59 +08:00
Refactor welcomeMessage
This commit is contained in:
parent
477be78693
commit
9f4ac1cf5b
@ -67,21 +67,21 @@ function loadWidget(config) {
|
|||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
function welcomeMessage() {
|
function welcomeMessage(time) {
|
||||||
const message = `欢迎阅读<span>「${document.title.split(" - ")[0]}」</span>`;
|
const message = `欢迎阅读<span>「${document.title.split(" - ")[0]}」</span>`;
|
||||||
let text;
|
let text;
|
||||||
if (location.pathname === "/") { // 如果是主页
|
if (location.pathname === "/") { // 如果是主页
|
||||||
const now = new Date().getHours();
|
for (let { hour, text } of time) {
|
||||||
if (now > 5 && now <= 7) text = "早上好!一日之计在于晨,美好的一天就要开始了。";
|
const now = new Date(),
|
||||||
else if (now > 7 && now <= 11) text = "上午好!工作顺利嘛,不要久坐,多起来走动走动哦!";
|
after = hour.split("-")[0],
|
||||||
else if (now > 11 && now <= 13) text = "中午了,工作了一个上午,现在是午餐时间!";
|
before = hour.split("-")[1] || after;
|
||||||
else if (now > 13 && now <= 17) text = "午后很容易犯困呢,今天的运动目标完成了吗?";
|
if (after <= now.getHours() && now.getHours() <= before) {
|
||||||
else if (now > 17 && now <= 19) text = "傍晚了!窗外夕阳的景色很美丽呢,最美不过夕阳红~";
|
text = randomSelection(text);
|
||||||
else if (now > 19 && now <= 21) text = "晚上好,今天过得怎么样?";
|
|
||||||
else if (now > 21 && now <= 23) text = ["已经这么晚了呀,早点休息吧,晚安~", "深夜时要爱护眼睛呀!"];
|
|
||||||
else text = "你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?";
|
|
||||||
return text;
|
return text;
|
||||||
} else if (document.referrer !== "") {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (document.referrer !== "") {
|
||||||
const referrer = new URL(document.referrer),
|
const referrer = new URL(document.referrer),
|
||||||
domain = referrer.hostname.split(".")[1];
|
domain = referrer.hostname.split(".")[1];
|
||||||
const domains = {
|
const domains = {
|
||||||
@ -93,12 +93,10 @@ function loadWidget(config) {
|
|||||||
|
|
||||||
if (domain in domains) text = domains[domain];
|
if (domain in domains) text = domains[domain];
|
||||||
else text = referrer.hostname;
|
else text = referrer.hostname;
|
||||||
return `Hello!来自 <span>${text}</span> 的朋友<br>${message}`;;
|
return `Hello!来自 <span>${text}</span> 的朋友<br>${message}`;
|
||||||
} else {
|
}
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
showMessage(welcomeMessage(), 7000, 8);
|
|
||||||
|
|
||||||
(function initModel() {
|
(function initModel() {
|
||||||
let modelId = localStorage.getItem("modelId"),
|
let modelId = localStorage.getItem("modelId"),
|
||||||
@ -112,6 +110,7 @@ function loadWidget(config) {
|
|||||||
fetch(config.waifuPath)
|
fetch(config.waifuPath)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
showMessage(welcomeMessage(result.time), 7000, 11);
|
||||||
window.addEventListener("mouseover", event => {
|
window.addEventListener("mouseover", event => {
|
||||||
for (let { selector, text } of result.mouseover) {
|
for (let { selector, text } of result.mouseover) {
|
||||||
if (!event.target.matches(selector)) continue;
|
if (!event.target.matches(selector)) continue;
|
||||||
@ -137,7 +136,6 @@ function loadWidget(config) {
|
|||||||
if ((after.split("/")[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split("/")[0]) && (after.split("/")[1] <= now.getDate() && now.getDate() <= before.split("/")[1])) {
|
if ((after.split("/")[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split("/")[0]) && (after.split("/")[1] <= now.getDate() && now.getDate() <= before.split("/")[1])) {
|
||||||
text = randomSelection(text);
|
text = randomSelection(text);
|
||||||
text = text.replace("{year}", now.getFullYear());
|
text = text.replace("{year}", now.getFullYear());
|
||||||
//showMessage(text, 7000, true);
|
|
||||||
messageArray.push(text);
|
messageArray.push(text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -220,5 +220,30 @@
|
|||||||
}, {
|
}, {
|
||||||
"date": "12/20-12/31",
|
"date": "12/20-12/31",
|
||||||
"text": "这几天是<span>圣诞节</span>,主人肯定又去剁手买买买了~"
|
"text": "这几天是<span>圣诞节</span>,主人肯定又去剁手买买买了~"
|
||||||
|
}],
|
||||||
|
"time": [{
|
||||||
|
"hour": "6-7",
|
||||||
|
"text": "早上好!一日之计在于晨,美好的一天就要开始了~"
|
||||||
|
}, {
|
||||||
|
"hour": "8-11",
|
||||||
|
"text": "上午好!工作顺利嘛,不要久坐,多起来走动走动哦!"
|
||||||
|
}, {
|
||||||
|
"hour": "12-13",
|
||||||
|
"text": "中午了,工作了一个上午,现在是午餐时间!"
|
||||||
|
}, {
|
||||||
|
"hour": "14-17",
|
||||||
|
"text": "午后很容易犯困呢,今天的运动目标完成了吗?"
|
||||||
|
}, {
|
||||||
|
"hour": "18-19",
|
||||||
|
"text": "傍晚了!窗外夕阳的景色很美丽呢,最美不过夕阳红~"
|
||||||
|
}, {
|
||||||
|
"hour": "20-21",
|
||||||
|
"text": "晚上好,今天过得怎么样?"
|
||||||
|
}, {
|
||||||
|
"hour": "22-23",
|
||||||
|
"text": ["已经这么晚了呀,早点休息吧,晚安~", "深夜时要爱护眼睛呀!"]
|
||||||
|
}, {
|
||||||
|
"hour": "0-5",
|
||||||
|
"text": "你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user