forked from huangyafei/chishenme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
166 lines (159 loc) · 6.02 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>嘉然今天吃什么?</title>
<meta name="keywords" content="嘉然今天吃什么" />
<meta name="description" content="嘉然今天吃什么" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<link rel="shortcut icon" href="./favicon.ico">
<link rel="stylesheet" href="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-2-M/bootstrap/5.1.3/css/bootstrap.min.css">
<style type="text/css">
.html{font-family: -apple-system,BlinkMacSystemFont,Helvetica Neue,PingFang SC,Microsoft YaHei,Source Han Sans SC,Noto Sans CJK SC,WenQuanYi Micro Hei,sans-serif!important;}
#start{background:#E799B0; border:#c9778f; color: #fff;}
#start:hover{background: #c9778f}
.btn{width: 90%;}
body{background: linear-gradient(#FFFFFFaa,#FFFFFFaa),url(https://s2.loli.net/2022/03/22/r47ViYx6ynhLCQb.jpg) no-repeat fixed top}
</style>
</head>
<body>
<div id="app" class="container d-flex flex-column justify-content-center" style="height: 100vh;">
<div class="row justify-content-center">
<div class="col-12 col-md-6">
<div class="card" v-if="!finished">
<div class="card-body d-flex flex-column align-items-center">
<div class="spinner-border" role="status" style="color: #E799B0;">
<span class="visually-hidden">少女挨饿中...</span>
</div>
<h3 class="mt-3">稍等哟,🍓嘉然马上就来~</h3>
<small style="color: #ccc">资源加载中,视网络情况可能最长20s左右</small>
</div>
</div>
<div class="card" v-if="finished">
<div class="card-body d-flex flex-column align-items-center">
<div class="d-flex flex-column flex-lg-row align-items-center mb-3">
<div style="position: relative;width:200px;height:200px" class="mt-2 mb-2">
<img class="d-inline-block rounded" width="200" :src="currentPic">
<div id="spicy" style="width:200px;height:200px; position: absolute ;top: 0; right: 0; bottom: 0; left: 0;"></div>
</div>
<div class="d-inline-block ms-lg-4 mt-2 mb-3">
<div class="d-flex flex-column align-items-center">
<h2>嘉然今天吃什么?</h2>
<br>
<h4 style="color:#E799B0" >{{currentName}}</h4>
<br>
<small>{{currentTooltipText}}</small>
</div>
</div>
</div>
<button id="start" @click="start" class="btn btn-lg text-nowrap" type="button">吃什么捏?</button>
<button id="stop" @click="stop" class="btn btn-lg btn-danger text-nowrap" type="button" style="display: none;">停止</button>
</div>
</div>
<!--<div class="card">
<div class="card-body d-flex flex-column align-items-center">
<a href="https://t.bilibili.com/658648606533746724">Our response to Carol and Asoul</a>
</div>
</div> -->
</div>
</div>
</div>
</body>
<script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.min.js"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/axios/0.26.0/axios.min.js"></script>
<script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript">
var app = new Vue({
el:'#app',
data() {
return {
menu: [],
imgArr: [],
currentPic: "https://s2.loli.net/2022/03/22/Rf9Z13zehCO4XEM.gif",
currentName: "",
currentTooltipText: "",
finished: false,
}
},
created() {
axios
.get('./menu.json')
.then(res => {
this.menu = res.data.menu;
this.preload(res.data.imgArr).then(res=>{
this.finished = true;
})
})
},
mounted() {
},
methods: {
start(){
$('#start').css("display", "none");
$('#stop').css("display", "block");
timer = setInterval(function () {
var r = Math.ceil(Math.random() * app.menu.length),
food = app.menu[r - 1];
app.currentName = food.name;
if(food.easteregg.text){
app.currentTooltipText = '💭 ' + food.easteregg.text;
}else{
app.currentTooltipText = '...';
}
if(food.easteregg.img) {
app.currentPic = food.easteregg.img;
}else{
app.currentPic = "https://s2.loli.net/2022/03/22/6gPctLmrQRdEfbl.gif";
}
if(food.spicy) {
let j = Math.ceil(Math.random() * 10);
for (i = 1; i < j; i++) {
var rTop = Math.ceil(Math.random() * 200),
rLeft = Math.ceil(Math.random() * 200),
rSize = Math.ceil(Math.random() * (37 - 14) + 14);
$("<span style='position:absolute'></span>").html('🥵').hide().css({
"top": rTop + "px",
"left": rLeft + "px",
"fontSize": rSize + "px"
}).appendTo("#spicy").fadeIn(i * 50, function () {
$(this).fadeOut(i * 50, function () {
$(this).remove();
});
});
}
}
}, 150);
},
stop(){
clearInterval(timer);
$('#stop').css("display", "none");
$('#start').css("display", "block");
$('#start').html("不要,换一个");
},
preload(arr){
let result = []
console.log("Loading pics, please wait...")
arr.forEach(item => {
let img = new Image();
img.src = item;
console.log("Pic url: " + item);
let p = new Promise((resolve, reject) => {
img.onload = () => {
resolve(img);
}
img.onerror = (e) => {
reject(e);
}
});
result.push(p);
});
return Promise.all(result).then(() => {
console.log("All pics are loaded.");
}).catch((err) => {
console.log(err);
});
}
}
})
</script>
</html>