From 54021a7265d3c0ebaa424ea7af79815e2aeadf3a Mon Sep 17 00:00:00 2001
From: StevenJoeZhang <1119186082@qq.com>
Date: Thu, 13 Jun 2019 13:34:47 +0800
Subject: [PATCH] Code style update
---
waifu-tips.js | 108 +++++++++++++++++++++++++++++++-------------------
1 file changed, 68 insertions(+), 40 deletions(-)
diff --git a/waifu-tips.js b/waifu-tips.js
index 47bef0e..a29927d 100755
--- a/waifu-tips.js
+++ b/waifu-tips.js
@@ -1,10 +1,32 @@
+console.log(`
+ く__,.ヘヽ. / ,ー、 〉
+ \ ', !-─‐-i / /´
+ /`ー' L//`ヽ、
+ / /, /| , , ',
+ イ / /-‐/ i L_ ハ ヽ! i
+ レ ヘ 7イ`ト レ'ァ-ト、!ハ| |
+ !,/7 '0' ´0iソ| |
+ |.从" _ ,,,, / |./ |
+ レ'| i>.、,,__ _,.イ / .i |
+ レ'| | / k_7_/レ'ヽ, ハ. |
+ | |/i 〈|/ i ,.ヘ | i |
+ .|/ / i: ヘ! \ |
+ kヽ>、ハ _,.ヘ、 /、!
+ !'〈//`T´', \ `'7'ーr'
+ レ'ヽL__|___i,___,ンレ|ノ
+ ト-,/ |___./
+ 'ー' !_,.:
+`);
+
/*
* https://imjad.cn/archives/lab/add-dynamic-poster-girl-with-live2d-to-your-blog-02
* https://www.fghrsh.net/post/123.html
*/
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");
sessionStorage.removeItem("waifu-text");
$("body").append(`
@@ -20,42 +42,47 @@ function initWidget(waifuPath, apiPath) {
`);
- $("#waifu-tool .fa-comment").click(showHitokoto);
- $("#waifu-tool .fa-paper-plane").click(function() {
- var s = document.createElement("script");
- document.body.appendChild(s);
- s.src = "https://galaxymimi.com/js/asteroids.js";
- });
- $("#waifu-tool .fa-user-circle").click(loadOtherModel);
- $("#waifu-tool .fa-street-view").click(loadRandModel);
- $("#waifu-tool .fa-camera-retro").click(function() {
- showMessage("照好了嘛,是不是很可爱呢?", 6000, 9);
- window.Live2D.captureName = "photo.png";
- window.Live2D.captureFrame = true;
- });
- $("#waifu-tool .fa-info-circle").click(function() {
- window.open("https://github.com/stevenjoezhang/live2d-widget");
- });
- $("#waifu-tool .fa-times").click(function() {
- localStorage.setItem("waifu-display", new Date().getTime());
- showMessage("愿你有一天能与重要的人重逢。", 2000, 11);
- $("#waifu").animate({ bottom: -500 }, 3000, function() {
- $("#waifu").hide();
+
+ function registerEventListener() {
+ $("#waifu-tool .fa-comment").click(showHitokoto);
+ $("#waifu-tool .fa-paper-plane").click(function() {
+ var s = document.createElement("script");
+ document.body.appendChild(s);
+ s.src = "https://galaxymimi.com/js/asteroids.js";
});
- });
- var re = /x/;
- console.log(re);
- re.toString = function() {
- showMessage("哈哈,你打开了控制台,是想要看看我的秘密吗?", 6000, 9);
- return "";
- };
- $(document).on("copy", function() {
- showMessage("你都复制了些什么呀,转载要记得加上出处哦!", 6000, 9);
- });
- $(document).on("visibilitychange", function() {
- if (!document.hidden) showMessage("哇,你终于回来了~", 6000, 9);
- });
- (function() {
+ $("#waifu-tool .fa-user-circle").click(loadOtherModel);
+ $("#waifu-tool .fa-street-view").click(loadRandModel);
+ $("#waifu-tool .fa-camera-retro").click(function() {
+ showMessage("照好了嘛,是不是很可爱呢?", 6000, 9);
+ window.Live2D.captureName = "photo.png";
+ window.Live2D.captureFrame = true;
+ });
+ $("#waifu-tool .fa-info-circle").click(function() {
+ window.open("https://github.com/stevenjoezhang/live2d-widget");
+ });
+ $("#waifu-tool .fa-times").click(function() {
+ localStorage.setItem("waifu-display", new Date().getTime());
+ showMessage("愿你有一天能与重要的人重逢。", 2000, 11);
+ $("#waifu").animate({ bottom: -500 }, 3000, function() {
+ $("#waifu").hide();
+ });
+ });
+ var re = /x/;
+ console.log(re);
+ re.toString = function() {
+ showMessage("哈哈,你打开了控制台,是想要看看我的秘密吗?", 6000, 9);
+ return "";
+ };
+ $(document).on("copy", function() {
+ showMessage("你都复制了些什么呀,转载要记得加上出处哦!", 6000, 9);
+ });
+ $(document).on("visibilitychange", function() {
+ if (!document.hidden) showMessage("哇,你终于回来了~", 6000, 9);
+ });
+ }
+ registerEventListener();
+
+ function welcomeMessage() {
var SiteIndexUrl = location.port ? `${location.protocol}//${location.hostname}:${location.port}/` : `${location.protocol}//${location.hostname}/`, text; //自动获取主页
if (location.href == SiteIndexUrl) { //如果是主页
var now = new Date().getHours();
@@ -79,9 +106,12 @@ function initWidget(waifuPath, apiPath) {
else if (domain == 'google') text = 'Hello!来自 谷歌搜索 的朋友
欢迎阅读『' + document.title.split(' - ')[0] + '』';
else text = 'Hello!来自 ' + referrer.hostname + ' 的朋友';
}
- else text = '欢迎阅读『' + document.title.split(' - ')[0] + '』';
+ else {
+ text = `欢迎阅读『${document.title.split(' - ')[0]}』`;
+ }
showMessage(text, 7000, 8);
- })();
+ }
+ welcomeMessage();
//检测用户活动状态,并在空闲时定时显示一言
var userAction = false,
hitokotoTimer = null,
@@ -118,7 +148,6 @@ function initWidget(waifuPath, apiPath) {
}
function showMessage(text, timeout, priority) {
- //console.log(text, timeout, priority);
if (!text) return;
if (!sessionStorage.getItem("waifu-text") || sessionStorage.getItem("waifu-text") <= priority) {
if (messageTimer) {
@@ -126,7 +155,6 @@ function initWidget(waifuPath, apiPath) {
messageTimer = null;
}
if (Array.isArray(text)) text = text[Math.floor(Math.random() * text.length)];
- //console.log(text);
sessionStorage.setItem("waifu-text", priority);
$("#waifu-tips").stop().html(text).fadeTo(200, 1);
messageTimer = setTimeout(function() {