Code style update

This commit is contained in:
StevenJoeZhang 2019-06-13 13:34:47 +08:00
parent 27005921cf
commit 54021a7265

View File

@ -1,10 +1,32 @@
console.log(`
__,.ヘヽ. / ,
', !--i / /´
' L/
/ , /| , , ',
/ /-/ L_ ! i
7 '-!| |
!,/7 '0' ´0i| |
|." _ ,,,, / |./ |
'| i.,,__ _,. / .i |
'| | / k__/レ', . |
| |/i 〈|/ i ,. | i |
.|/ / ! |
kヽ> _,. /!
!'〈//´', '7'ーr'
'ヽL__|___i,___,ンレ|
-,/ |___./
'ー' !_,.:
`);
/* /*
* https://imjad.cn/archives/lab/add-dynamic-poster-girl-with-live2d-to-your-blog-02 * https://imjad.cn/archives/lab/add-dynamic-poster-girl-with-live2d-to-your-blog-02
* https://www.fghrsh.net/post/123.html * https://www.fghrsh.net/post/123.html
*/ */
function initWidget(waifuPath, apiPath) { 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">
@ -20,6 +42,8 @@ function initWidget(waifuPath, apiPath) {
<span class="fa fa-lg fa-times"></span> <span class="fa fa-lg fa-times"></span>
</div> </div>
</div>`); </div>`);
function registerEventListener() {
$("#waifu-tool .fa-comment").click(showHitokoto); $("#waifu-tool .fa-comment").click(showHitokoto);
$("#waifu-tool .fa-paper-plane").click(function() { $("#waifu-tool .fa-paper-plane").click(function() {
var s = document.createElement("script"); var s = document.createElement("script");
@ -55,7 +79,10 @@ function initWidget(waifuPath, apiPath) {
$(document).on("visibilitychange", function() { $(document).on("visibilitychange", function() {
if (!document.hidden) showMessage("哇,你终于回来了~", 6000, 9); if (!document.hidden) showMessage("哇,你终于回来了~", 6000, 9);
}); });
(function() { }
registerEventListener();
function welcomeMessage() {
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();
@ -79,9 +106,12 @@ function initWidget(waifuPath, apiPath) {
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);
})(); }
welcomeMessage();
//检测用户活动状态,并在空闲时定时显示一言 //检测用户活动状态,并在空闲时定时显示一言
var userAction = false, var userAction = false,
hitokotoTimer = null, hitokotoTimer = null,
@ -118,7 +148,6 @@ function initWidget(waifuPath, apiPath) {
} }
function showMessage(text, timeout, priority) { function showMessage(text, timeout, priority) {
//console.log(text, timeout, priority);
if (!text) return; if (!text) return;
if (!sessionStorage.getItem("waifu-text") || sessionStorage.getItem("waifu-text") <= priority) { if (!sessionStorage.getItem("waifu-text") || sessionStorage.getItem("waifu-text") <= priority) {
if (messageTimer) { if (messageTimer) {
@ -126,7 +155,6 @@ function initWidget(waifuPath, apiPath) {
messageTimer = null; messageTimer = null;
} }
if (Array.isArray(text)) text = text[Math.floor(Math.random() * text.length)]; if (Array.isArray(text)) text = text[Math.floor(Math.random() * text.length)];
//console.log(text);
sessionStorage.setItem("waifu-text", priority); sessionStorage.setItem("waifu-text", priority);
$("#waifu-tips").stop().html(text).fadeTo(200, 1); $("#waifu-tips").stop().html(text).fadeTo(200, 1);
messageTimer = setTimeout(function() { messageTimer = setTimeout(function() {