mirror of
https://github.com/caojiezi2003/live2d-widget.git
synced 2024-11-22 23:29:45 +00:00
Code style update
This commit is contained in:
parent
1471992608
commit
215b74a1e0
@ -24,7 +24,7 @@ Add Live2D widget to web page. Compatible with PJAX.
|
|||||||
jQuery and font-awesome is required for this plugin. You can add this to `<head>`:
|
jQuery and font-awesome is required for this plugin. You can add this to `<head>`:
|
||||||
```xml
|
```xml
|
||||||
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
|
||||||
```
|
```
|
||||||
否则无法正常显示。(如果你的网页已经加载了jQuery,就不要重复加载了)
|
否则无法正常显示。(如果你的网页已经加载了jQuery,就不要重复加载了)
|
||||||
|
|
||||||
|
@ -72,27 +72,24 @@ function loadWidget(waifuPath, apiPath) {
|
|||||||
var SiteIndexUrl = location.port ? `${location.protocol}//${location.hostname}:${location.port}/` : `${location.protocol}//${location.hostname}/`, text; //自动获取主页
|
var SiteIndexUrl = location.port ? `${location.protocol}//${location.hostname}:${location.port}/` : `${location.protocol}//${location.hostname}/`, text; //自动获取主页
|
||||||
if (location.href == SiteIndexUrl) { //如果是主页
|
if (location.href == SiteIndexUrl) { //如果是主页
|
||||||
var now = new Date().getHours();
|
var now = new Date().getHours();
|
||||||
if (now > 23 || now <= 5) text = "你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?";
|
if (now > 5 && now <= 7) text = "早上好!一日之计在于晨,美好的一天就要开始了。";
|
||||||
else if (now > 5 && now <= 7) text = "早上好!一日之计在于晨,美好的一天就要开始了。";
|
|
||||||
else if (now > 7 && now <= 11) text = "上午好!工作顺利嘛,不要久坐,多起来走动走动哦!";
|
else if (now > 7 && now <= 11) text = "上午好!工作顺利嘛,不要久坐,多起来走动走动哦!";
|
||||||
else if (now > 11 && now <= 14) text = "中午了,工作了一个上午,现在是午餐时间!";
|
else if (now > 11 && now <= 14) text = "中午了,工作了一个上午,现在是午餐时间!";
|
||||||
else if (now > 14 && now <= 17) text = "午后很容易犯困呢,今天的运动目标完成了吗?";
|
else if (now > 14 && now <= 17) text = "午后很容易犯困呢,今天的运动目标完成了吗?";
|
||||||
else if (now > 17 && now <= 19) text = "傍晚了!窗外夕阳的景色很美丽呢,最美不过夕阳红~";
|
else if (now > 17 && now <= 19) text = "傍晚了!窗外夕阳的景色很美丽呢,最美不过夕阳红~";
|
||||||
else if (now > 19 && now <= 21) text = "晚上好,今天过得怎么样?";
|
else if (now > 19 && now <= 21) text = "晚上好,今天过得怎么样?";
|
||||||
else if (now > 21 && now <= 23) text = ["已经这么晚了呀,早点休息吧,晚安~", "深夜时要爱护眼睛呀!"];
|
else if (now > 21 && now <= 23) text = ["已经这么晚了呀,早点休息吧,晚安~", "深夜时要爱护眼睛呀!"];
|
||||||
else text = "好久不见,日子过得好快呢……";
|
else text = "你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?";
|
||||||
}
|
} else if (document.referrer !== "") {
|
||||||
else if (document.referrer !== "") {
|
|
||||||
var referrer = document.createElement("a");
|
var referrer = document.createElement("a");
|
||||||
referrer.href = document.referrer;
|
referrer.href = document.referrer;
|
||||||
var domain = referrer.hostname.split(".")[1];
|
var domain = referrer.hostname.split(".")[1];
|
||||||
if (location.hostname == referrer.hostname) text = `欢迎阅读<span style="color:#0099cc;">『${document.title.split(" - ")[0]}』</span>`;
|
if (location.hostname == referrer.hostname) text = `欢迎阅读<span style="color:#0099cc;">『${document.title.split(" - ")[0]}』</span>`;
|
||||||
else if (domain == "baidu") text = `Hello!来自 百度搜索 的朋友<br/>你是搜索 <span style="color:#0099cc;">${referrer.search.split("&wd=")[1].split("&")[0]}</span> 找到的我吗?`;
|
else if (domain == "baidu") text = `Hello!来自 百度搜索 的朋友<br>你是搜索 <span style="color:#0099cc;">${referrer.search.split("&wd=")[1].split("&")[0]}</span> 找到的我吗?`;
|
||||||
else if (domain == "so") text = `Hello!来自 360搜索 的朋友<br/>你是搜索 <span style="color:#0099cc;">${referrer.search.split("&q=")[1].split("&")[0]}</span> 找到的我吗?`;
|
else if (domain == "so") text = `Hello!来自 360搜索 的朋友<br>你是搜索 <span style="color:#0099cc;">${referrer.search.split("&q=")[1].split("&")[0]}</span> 找到的我吗?`;
|
||||||
else if (domain == "google") text = `Hello!来自 谷歌搜索 的朋友<br/>欢迎阅读<span style="color:#0099cc;">『${document.title.split(" - ")[0]}』</span>`;
|
else if (domain == "google") text = `Hello!来自 谷歌搜索 的朋友<br>欢迎阅读<span style="color:#0099cc;">『${document.title.split(" - ")[0]}』</span>`;
|
||||||
else text = `Hello!来自 <span style="color:#0099cc;">${referrer.hostname}</span> 的朋友`;
|
else text = `Hello!来自 <span style="color:#0099cc;">${referrer.hostname}</span> 的朋友`;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
text = `欢迎阅读<span style="color:#0099cc;">『${document.title.split(" - ")[0]}』</span>`;
|
text = `欢迎阅读<span style="color:#0099cc;">『${document.title.split(" - ")[0]}』</span>`;
|
||||||
}
|
}
|
||||||
showMessage(text, 7000, 8);
|
showMessage(text, 7000, 8);
|
||||||
@ -102,7 +99,7 @@ function loadWidget(waifuPath, apiPath) {
|
|||||||
var userAction = false,
|
var userAction = false,
|
||||||
hitokotoTimer = null,
|
hitokotoTimer = null,
|
||||||
messageTimer = null,
|
messageTimer = null,
|
||||||
messageArray = ["已经过了这么久了呀……", "大坏蛋!你都多久没碰人家了呀,嘤嘤嘤~", "嗨~快来逗我玩吧!", "拿小拳拳锤你胸口!"];
|
messageArray = ["好久不见,日子过得好快呢……", "大坏蛋!你都多久没碰人家了呀,嘤嘤嘤~", "嗨~快来逗我玩吧!", "拿小拳拳锤你胸口!"];
|
||||||
if ($(".fa-share-alt").is(":hidden")) messageArray.push("记得把小家加入Adblock白名单哦!");
|
if ($(".fa-share-alt").is(":hidden")) messageArray.push("记得把小家加入Adblock白名单哦!");
|
||||||
$(document).mousemove(() => {
|
$(document).mousemove(() => {
|
||||||
userAction = true;
|
userAction = true;
|
||||||
@ -112,8 +109,7 @@ function loadWidget(waifuPath, apiPath) {
|
|||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (!userAction) {
|
if (!userAction) {
|
||||||
if (!hitokotoTimer) hitokotoTimer = setInterval(showHitokoto, 25000);
|
if (!hitokotoTimer) hitokotoTimer = setInterval(showHitokoto, 25000);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
userAction = false;
|
userAction = false;
|
||||||
clearInterval(hitokotoTimer);
|
clearInterval(hitokotoTimer);
|
||||||
hitokotoTimer = null;
|
hitokotoTimer = null;
|
||||||
@ -241,16 +237,14 @@ function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") {
|
|||||||
if ($("#waifu-toggle").attr("first-time")) {
|
if ($("#waifu-toggle").attr("first-time")) {
|
||||||
loadWidget(waifuPath, apiPath);
|
loadWidget(waifuPath, apiPath);
|
||||||
$("#waifu-toggle").attr("first-time", false);
|
$("#waifu-toggle").attr("first-time", false);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
localStorage.removeItem("waifu-display");
|
localStorage.removeItem("waifu-display");
|
||||||
$("#waifu").show().animate({ bottom: 0 }, 3000);
|
$("#waifu").show().animate({ bottom: 0 }, 3000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (localStorage.getItem("waifu-display") && new Date().getTime() - localStorage.getItem("waifu-display") <= 86400000) {
|
if (localStorage.getItem("waifu-display") && new Date().getTime() - localStorage.getItem("waifu-display") <= 86400000) {
|
||||||
$("#waifu-toggle").attr("first-time", true).css({ "margin-left": -50 });
|
$("#waifu-toggle").attr("first-time", true).css({ "margin-left": -50 });
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
loadWidget(waifuPath, apiPath);
|
loadWidget(waifuPath, apiPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user