-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaidu.html
310 lines (271 loc) · 11 KB
/
baidu.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Go and search it yurself!!!!</title>
<link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
<script src="./lib/jquery/js/jquery-3.6.3.min.js"></script>
</head>
<body class="d-flex flex-column">
<main class="search-container text-center">
<img aria-hidden="true" src="https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png" width="270"
height="129">
<form id="search-form" action="https://baidu.com/s" method="get" class="mt-4">
<div class="input-group mb-3">
<input type="text" id="search-input" class="form-control" name="wd">
<button id="search-btn" disabled="">百度一下</button>
</div>
</form>
<button id="teach-twice" class="btn btn-primary" style="display: none;">对不起,我没学会,请再教我一遍</button>
<img id="pointer" class="pointer" src="images/pointer.png" style="display: none;">
<img id="pointer-active" class="pointer" src="images/pointer-active.png" style="display: none;">
</main>
<footer class="mt-auto">
<nav class="navbar navbar-light">
<ul class="navbar-nav d-inline-flex flex-row flex-wrap mx-auto">
<li class="nav-item">
<a class="nav-link mx-2" href="https://github.com/YubaC/GO-AND-SEARCH-IT-YOURSELF/">Github</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="index.html">生成器</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="https://yuba.tech">煜霸科技</a>
</li>
</ul>
</nav>
</footer>
<style>
html,
body {
width: 100%;
height: 100%;
}
.search-container {
width: 654px;
max-width: 90%;
height: 100%;
margin: 0 auto;
margin-top: 40px;
text-align: left;
}
#search-input {
user-select: none;
pointer-events: none;
max-width: 100%;
padding-right: 87px;
/* height: 16px; */
/* padding: 12px 16px; */
padding-right: 16px;
font-size: 16px;
margin: 0;
vertical-align: top;
outline: 0;
box-shadow: none;
border-radius: 10px 0 0 10px;
border: 2px solid #c4c7ce;
border-right: none;
background: #fff !important;
color: #222;
overflow: hidden;
box-sizing: content-box;
-webkit-tap-highlight-color: transparent;
}
#search-input.active,
#search-input:focus {
border-color: #4e71f2;
/* box-shadow: 0 0 0 2px rgba(78, 110, 242, 0.2); */
}
#search-btn {
cursor: pointer;
width: 108px;
/* height: 44px; */
line-height: 45px;
line-height: 44px\9;
padding: 0;
background: 0 0;
background-color: rgba(0, 0, 0, 0);
background-color: #4e6ef2;
border-radius: 0 10px 10px 0;
font-size: 17px;
color: #fff;
box-shadow: none;
font-weight: 400;
border: none;
outline: 0;
}
#search-btn.active {
background-color: #4662d9;
}
.pointer {
position: absolute;
top: 0;
left: 0;
width: 50px;
z-index: 99999;
}
</style>
<script>
/**
* 获取URL参数值
* @param {string} para URL参数名
* @returns {Array} URL参数值数组
*/
function getUrlParam(para) {
var search = location.search; //页面URL的查询部分字符串
var arrPara = new Array(); //参数数组。数组单项为包含参数名和参数值的字符串,如“para=value”
var arrVal = new Array(); //参数值数组。用于存储查找到的参数值
if (search != "") {
var index = 0;
search = search.substr(1); //去除开头的“?”
arrPara = search.split("&");
for (i in arrPara) {
var paraPre = para + "="; //参数前缀。即参数名+“=”,如“para=”
if (
arrPara[i].indexOf(paraPre) == 0 &&
paraPre.length < arrPara[i].length
) {
arrVal[index] = decodeURI(arrPara[i].substr(paraPre.length)); //顺带URI解码避免出现乱码
index++;
}
}
}
if (arrVal.length == 0) {
return [];
} else {
return arrVal;
}
}
async function movePointer($target, duration = 1500) {
return new Promise(async (resolve, reject) => {
const $pointer = $("#pointer");
const $pointerActive = $("#pointer-active");
const $pointerInactive = $("#pointer-inactive");
const targetOffset = $target.offset();
const targetHeight = $target.height();
const targetWidth = $target.width();
const pointerHeight = $pointer.height();
const pointerWidth = $pointer.width();
const pointerTop = targetOffset.top + targetHeight / 2 - pointerHeight / 2 + 25;
const pointerLeft = targetOffset.left + targetWidth / 2 - pointerWidth / 2;
$pointer.show();
$pointerActive.css({
top: pointerTop,
left: pointerLeft
});
await $pointer.animate(
{
left: pointerLeft,
top: pointerTop
},
duration
).promise();
await new Promise(resolve => setTimeout(resolve, 500));
$pointerActive.show();
$pointer.hide();
// 使元素展现出active状态
$target.addClass("active");
$target.focus();
await new Promise(resolve => setTimeout(resolve, 300));
$pointer.show();
$pointerActive.hide();
$target.removeClass("active");
await new Promise(resolve => setTimeout(resolve, 500));
$pointer.hide();
// // 回归原位
// $pointer.css({
// top: 0,
// left: 0
// });
resolve();
});
}
function fillWd(wd, $element) {
$element.addClass("active");
return new Promise(async (resolve, reject) => {
const words = wd.split("");
for (word of words) {
$element.val($element.val() + word);
$element[0].setSelectionRange($element.val().length, $element.val().length);
// 如果下一个字符为中日韩文,则延迟0.4s后再填充,否则延迟0.1s后填充
if (/[^\x00-\xff]/.test(word)) {
await new Promise(resolve => setTimeout(resolve, 400));
} else {
await new Promise(resolve => setTimeout(resolve, 100));
}
}
$element.removeClass("active");
resolve();
});
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
var expires = "expires=" + d.toGMTString();
document.cookie =
cname + "=" + cvalue + "; " + expires + "; SameSite=None; Secure";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(";");
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
$(document).ready(() => {
// 1. 获取URL参数:wd
// 2. 向#search-input中填充wd参数值,
// 动画为:如果下一个字符为中日韩文,则延迟0.4s后再填充,否则延迟0.1s后填充。伴随光标闪烁的打字效果。
// 3. 填充完毕后,提交表单。
// 1. 获取URL参数:wd
const wd = getUrlParam("wd")[0] || "百度一下";
// 是否开启第二次嘲讽模式
const allowSecond = (getUrlParam("second")[0] || "true") === "true";
const $searchInput = $("#search-input");
const $searchBtn = $("#search-btn");
const $teachTwice = $("#teach-twice");
// 清空输入框
$searchInput.val("");
async function showAnimation() {
await movePointer($searchInput);
await new Promise(resolve => setTimeout(resolve, 500));
await fillWd(wd, $searchInput);
await new Promise(resolve => setTimeout(resolve, 500));
await movePointer($searchBtn);
// 访问百度
$("#search-form").submit();
}
// 查找同一关键词的cookie
const cookieName = `search-${wd}`;
const cookieValue = getCookie(cookieName);
// 如果找到了cookie,说明已经教过一次了
const teached = cookieValue !== "";
if (!allowSecond && teached) {
$searchInput.attr("placeholder", "只教一遍,包教不包会,自己百度吧");
// 解禁表单
$searchBtn.removeAttr("disabled");
$searchInput.css("pointer-events", "auto");
$teachTwice.show();
$teachTwice.click(() => {
$searchInput.attr("placeholder", "");
$teachTwice.hide();
$searchBtn.attr("disabled", "");
$searchInput.css("pointer-events", "none");
showAnimation();
});
} else {
// 设置cookie
setCookie(cookieName, "true", 365);
showAnimation();
}
});
</script>
</body>
</html>