Skip to content

Commit 05cc012

Browse files
New feature: Show toggle button after hiding the widget
1 parent 2281944 commit 05cc012

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

waifu-tips.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ console.log(`
2323
* https://www.fghrsh.net/post/123.html
2424
*/
2525

26-
function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") {
27-
if (screen.width <= 768 || (localStorage.getItem("waifu-display") && new Date().getTime() - localStorage.getItem("waifu-display") <= 86400000)) {
28-
return;
29-
}
26+
function loadWidget(waifuPath, apiPath) {
3027
localStorage.removeItem("waifu-display");
3128
sessionStorage.removeItem("waifu-text");
3229
$("body").append(`<div id="waifu">
@@ -42,13 +39,14 @@ function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") {
4239
<span class="fa fa-lg fa-times"></span>
4340
</div>
4441
</div>`);
42+
$("#waifu").show().animate({ bottom: 0 }, 3000);
4543

4644
function registerEventListener() {
4745
$("#waifu-tool .fa-comment").click(showHitokoto);
4846
$("#waifu-tool .fa-paper-plane").click(function() {
4947
var s = document.createElement("script");
5048
document.body.appendChild(s);
51-
s.src = "https://galaxymimi.com/js/asteroids.js";
49+
s.src = "https://cdn.jsdelivr.net/gh/GalaxyMimi/CDN/asteroids.js";
5250
});
5351
$("#waifu-tool .fa-user-circle").click(loadOtherModel);
5452
$("#waifu-tool .fa-street-view").click(loadRandModel);
@@ -65,6 +63,7 @@ function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") {
6563
showMessage("愿你有一天能与重要的人重逢。", 2000, 11);
6664
$("#waifu").animate({ bottom: -500 }, 3000, function() {
6765
$("#waifu").hide();
66+
$("#waifu-toggle").show().animate({ "margin-left": -50 }, 1000);
6867
});
6968
});
7069
var re = /x/;
@@ -238,3 +237,33 @@ function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") {
238237
});
239238
}
240239
}
240+
241+
function initWidget(waifuPath = "/waifu-tips.json", apiPath = "") {
242+
if (screen.width <= 768) return;
243+
$("body").append(`<div id="waifu-toggle" style="margin-left: -100px;">
244+
<span>看板娘</span>
245+
</div>`);
246+
$("#waifu-toggle").hover(function() {
247+
$("#waifu-toggle").animate({ "margin-left": -30 }, 500);
248+
}, function() {
249+
$("#waifu-toggle").animate({ "margin-left": -50 }, 500);
250+
}).click(function() {
251+
$("#waifu-toggle").animate({ "margin-left": -100 }, 1000, function() {
252+
$("#waifu-toggle").hide();
253+
});
254+
if ($("#waifu-toggle").attr("first-time")) {
255+
loadWidget(waifuPath, apiPath);
256+
$("#waifu-toggle").attr("first-time", false);
257+
}
258+
else {
259+
localStorage.removeItem("waifu-display");
260+
$("#waifu").show().animate({ bottom: 0 }, 3000);
261+
}
262+
});
263+
if (localStorage.getItem("waifu-display") && new Date().getTime() - localStorage.getItem("waifu-display") <= 86400000) {
264+
$("#waifu-toggle").attr("first-time", true).css({ "margin-left": -50 });
265+
}
266+
else {
267+
loadWidget(waifuPath, apiPath);
268+
}
269+
}

waifu.css

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1+
#waifu-toggle {
2+
position: fixed;
3+
writing-mode: vertical-rl;
4+
bottom: 10px;
5+
left: 0px;
6+
background-color: #fa0;
7+
color: #fff;
8+
border-radius: 5px;
9+
padding: 5px;
10+
font-size: 12px;
11+
width: 60px;
12+
cursor: pointer;
13+
}
114
#waifu {
215
position: fixed;
3-
bottom: -3px;
16+
bottom: -1000px;
417
left: 0;
518
z-index: 1;
619
line-height: 0;
7-
transition: bottom .3s ease-in-out;
20+
transition: transform .3s ease-in-out;
21+
transform: translateY(3px);
822
}
923
#waifu:hover {
10-
bottom: 0;
24+
transform: translateY(0);
1125
}
1226
@media (max-width: 768px) {
1327
#waifu {

0 commit comments

Comments
 (0)