mirror of
https://github.com/caojiezi2003/live2d-widget.git
synced 2024-11-10 04:49:47 +00:00
update waifu-tips.js
This commit is contained in:
parent
9ae65538e7
commit
8f38cf3bcf
125
waifu-tips.js
125
waifu-tips.js
@ -7,19 +7,19 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
if (screen.width <= 768 || (localStorage.getItem("waifu-display") && new Date().getTime() - localStorage.getItem("waifu-display") <= 86400000)) return;
|
if (screen.width <= 768 || (localStorage.getItem("waifu-display") && new Date().getTime() - localStorage.getItem("waifu-display") <= 86400000)) return;
|
||||||
localStorage.removeItem("waifu-display");
|
localStorage.removeItem("waifu-display");
|
||||||
sessionStorage.removeItem("waifu-text");
|
sessionStorage.removeItem("waifu-text");
|
||||||
$("body").append('<div id="waifu">\
|
$("body").append(`<div id="waifu">
|
||||||
<div id="waifu-tips"></div>\
|
<div id="waifu-tips"></div>
|
||||||
<canvas id="live2d" width="300" height="300"></canvas>\
|
<canvas id="live2d" width="300" height="300"></canvas>
|
||||||
<div id="waifu-tool">\
|
<div id="waifu-tool">
|
||||||
<span class="fa fa-lg fa-comment"></span>\
|
<span class="fa fa-lg fa-comment"></span>
|
||||||
<span class="fa fa-lg fa-paper-plane"></span>\
|
<span class="fa fa-lg fa-paper-plane"></span>
|
||||||
<span class="fa fa-lg fa-user-circle"></span>\
|
<span class="fa fa-lg fa-user-circle"></span>
|
||||||
<span class="fa fa-lg fa-street-view"></span>\
|
<span class="fa fa-lg fa-street-view"></span>
|
||||||
<span class="fa fa-lg fa-camera-retro"></span>\
|
<span class="fa fa-lg fa-camera-retro"></span>
|
||||||
<span class="fa fa-lg fa-info-circle"></span>\
|
<span class="fa fa-lg fa-info-circle"></span>
|
||||||
<span class="fa fa-lg fa-times"></span>\
|
<span class="fa fa-lg fa-times"></span>
|
||||||
</div>\
|
</div>
|
||||||
</div>');
|
</div>`);
|
||||||
var re = /x/,
|
var re = /x/,
|
||||||
OriginTitile = document.title,
|
OriginTitile = document.title,
|
||||||
titleTime = null,
|
titleTime = null,
|
||||||
@ -84,16 +84,15 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
$("#waifu-tool .fa-times").click(function() {
|
$("#waifu-tool .fa-times").click(function() {
|
||||||
localStorage.setItem("waifu-display", new Date().getTime());
|
localStorage.setItem("waifu-display", new Date().getTime());
|
||||||
showMessage("愿你有一天能与重要的人重逢。", 2000, 11);
|
showMessage("愿你有一天能与重要的人重逢。", 2000, 11);
|
||||||
$("#waifu").animate({bottom: -500}, 3000, function() {
|
$("#waifu").animate({ bottom: -500 }, 3000, function() {
|
||||||
$("#waifu").hide();
|
$("#waifu").hide();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
(function() {
|
(function() {
|
||||||
var text,
|
var SiteIndexUrl = location.port ? `${location.protocol}//${location.hostname}:${location.port}/` : `${location.protocol}//${location.hostname}/`, text; //自动获取主页
|
||||||
SiteIndexUrl = location.port ? `${location.protocol}//${location.hostname}:${location.port}/` : `${location.protocol}//${location.hostname}/`; //自动获取主页
|
|
||||||
//var SiteIndexUrl = "https://www.fghrsh.net/"; //手动指定主页
|
//var SiteIndexUrl = "https://www.fghrsh.net/"; //手动指定主页
|
||||||
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 > 23 || now <= 5) text = "你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?";
|
||||||
else 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 = "上午好!工作顺利嘛,不要久坐,多起来走动走动哦!";
|
||||||
@ -104,47 +103,44 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
else if (now > 21 && now <= 23) text = ["已经这么晚了呀,早点休息吧,晚安~", "深夜时要爱护眼睛呀!"];
|
else if (now > 21 && now <= 23) text = ["已经这么晚了呀,早点休息吧,晚安~", "深夜时要爱护眼睛呀!"];
|
||||||
else text = "好久不见,日子过得好快呢……";
|
else text = "好久不见,日子过得好快呢……";
|
||||||
}
|
}
|
||||||
else {
|
else if (document.referrer !== "") {
|
||||||
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 text = '欢迎阅读<span style="color:#0099cc;">『' + document.title.split(' - ')[0] + '』</span>';
|
|
||||||
}
|
}
|
||||||
|
else text = '欢迎阅读<span style="color:#0099cc;">『' + document.title.split(' - ')[0] + '』</span>';
|
||||||
showMessage(text, 7000, 8);
|
showMessage(text, 7000, 8);
|
||||||
})();
|
})();
|
||||||
//检测用户活动状态,并在空闲时 定时显示一言
|
//检测用户活动状态,并在空闲时定时显示一言
|
||||||
var getActed = false,
|
var userAction = false,
|
||||||
hitokotoTimer = null,
|
hitokotoTimer = null,
|
||||||
messageTimer = null,
|
messageTimer = null,
|
||||||
messageArray = ["已经过了这么久了呀,日子过得好快呢……", "使用Chrome可以获得最佳浏览体验哦!", "嗨~快来逗我玩吧!", "拿小拳拳锤你胸口!"],
|
messageArray = ["已经过了这么久了呀,日子过得好快呢……", "使用Chrome可以获得最佳浏览体验哦!", "嗨~快来逗我玩吧!", "拿小拳拳锤你胸口!"],
|
||||||
apiURL = "";
|
apiURL = "";
|
||||||
if ($(".fa-share-alt").is(":hidden")) messageArray.push("记得把小家加入Adblock白名单哦!");
|
if ($(".fa-share-alt").is(":hidden")) messageArray.push("记得把小家加入Adblock白名单哦!");
|
||||||
$(document).mousemove(function() {
|
$(document).mousemove(function() {
|
||||||
getActed = true;
|
userAction = true;
|
||||||
}).keydown(function() {
|
}).keydown(function() {
|
||||||
getActed = true;
|
userAction = true;
|
||||||
});
|
});
|
||||||
//hitokotoTimer = setInterval(showHitokoto, 30000);
|
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
if (!getActed) {
|
if (!userAction) {
|
||||||
if (!hitokotoTimer) hitokotoTimer = setInterval(showHitokoto, 25000);
|
if (!hitokotoTimer) hitokotoTimer = setInterval(showHitokoto, 25000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getActed = false;
|
userAction = false;
|
||||||
clearInterval(hitokotoTimer);
|
clearInterval(hitokotoTimer);
|
||||||
hitokotoTimer = null;
|
hitokotoTimer = null;
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
function showHitokoto() {
|
function showHitokoto() {
|
||||||
//增加 hitokoto.cn API
|
//增加 hitokoto.cn 的 API
|
||||||
if (Math.random() < 0.6 && messageArray.length > 0) showMessage(messageArray[Math.floor(Math.random() * messageArray.length)], 6000, 9);
|
if (Math.random() < 0.6 && messageArray.length > 0) showMessage(messageArray[Math.floor(Math.random() * messageArray.length)], 6000, 9);
|
||||||
else $.getJSON("https://v1.hitokoto.cn", function(result) {
|
else $.getJSON("https://v1.hitokoto.cn", function(result) {
|
||||||
var text = `这句一言来自 <span style="color:#0099cc;">『${result.from}』</span>,是 <span style="color:#0099cc;">${result.creator}</span> 在 hitokoto.cn 投稿的。`;
|
var text = `这句一言来自 <span style="color:#0099cc;">『${result.from}』</span>,是 <span style="color:#0099cc;">${result.creator}</span> 在 hitokoto.cn 投稿的。`;
|
||||||
@ -185,38 +181,33 @@ function initWidget(waifuPath, apiPath) {
|
|||||||
modelTexturesId = 53; //材质 ID
|
modelTexturesId = 53; //材质 ID
|
||||||
}
|
}
|
||||||
loadModel(modelId, modelTexturesId);
|
loadModel(modelId, modelTexturesId);
|
||||||
$.ajax({
|
$.getJSON(waifuPath, function(result) {
|
||||||
cache: true,
|
$.each(result.mouseover, function(index, tips) {
|
||||||
url: waifuPath,
|
$(document).on("mouseover", tips.selector, function() {
|
||||||
dataType: "json",
|
var text = Array.isArray(tips.text) ? tips.text[Math.floor(Math.random() * tips.text.length)] : tips.text;
|
||||||
success: function(result) {
|
text = text.replace("{text}", $(this).text());
|
||||||
$.each(result.mouseover, function(index, tips) {
|
showMessage(text, 4000, 8);
|
||||||
$(document).on("mouseover", tips.selector, function() {
|
|
||||||
var text = Array.isArray(tips.text) ? tips.text[Math.floor(Math.random() * tips.text.length)] : tips.text;
|
|
||||||
text = text.replace("{text}", $(this).text());
|
|
||||||
showMessage(text, 4000, 8);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
$.each(result.click, function(index, tips) {
|
});
|
||||||
$(document).on("click", tips.selector, function() {
|
$.each(result.click, function(index, tips) {
|
||||||
var text = Array.isArray(tips.text) ? tips.text[Math.floor(Math.random() * tips.text.length)] : tips.text;
|
$(document).on("click", tips.selector, function() {
|
||||||
text = text.replace("{text}", $(this).text());
|
var text = Array.isArray(tips.text) ? tips.text[Math.floor(Math.random() * tips.text.length)] : tips.text;
|
||||||
showMessage(text, 4000, 8);
|
text = text.replace("{text}", $(this).text());
|
||||||
});
|
showMessage(text, 4000, 8);
|
||||||
});
|
});
|
||||||
$.each(result.seasons, function(index, tips) {
|
});
|
||||||
var now = new Date(),
|
$.each(result.seasons, function(index, tips) {
|
||||||
after = tips.date.split("-")[0],
|
var now = new Date(),
|
||||||
before = tips.date.split("-")[1] || after;
|
after = tips.date.split("-")[0],
|
||||||
if ((after.split("/")[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split("/")[0]) && (after.split("/")[1] <= now.getDate() && now.getDate() <= before.split("/")[1])) {
|
before = tips.date.split("-")[1] || after;
|
||||||
var text = tips.text;
|
if ((after.split("/")[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split("/")[0]) && (after.split("/")[1] <= now.getDate() && now.getDate() <= before.split("/")[1])) {
|
||||||
if (Array.isArray(tips.text)) text = tips.text[Math.floor(Math.random() * tips.text.length)];
|
var text = tips.text;
|
||||||
text = text.replace("{year}", now.getFullYear());
|
if (Array.isArray(tips.text)) text = tips.text[Math.floor(Math.random() * tips.text.length)];
|
||||||
//showMessage(text, 7000, true);
|
text = text.replace("{year}", now.getFullYear());
|
||||||
messageArray.push(text);
|
//showMessage(text, 7000, true);
|
||||||
}
|
messageArray.push(text);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user