@@ -65,32 +65,12 @@ const someHTML = `
65
65
background-color: #333333;
66
66
}
67
67
68
- .engine-tabs {
69
- width: 100%;
70
- }
71
-
72
- .engine-tab {
73
- display: inline-block;
74
- padding: 5px 10px;
75
- margin: 0 10px 15px 0;
76
- text-decoration: none;
77
- border: 2px solid #a89e84;
78
- background-color: #eee8d5;
79
- border-radius: 3px;
80
- cursor: pointer;
81
- }
82
-
83
- .dark-mode .engine-tab {
68
+ .dark-mode {
84
69
border-color: #777777;
85
70
background-color: #333333;
86
71
}
87
72
88
- .engine-tab.active {
89
- color: #7c786f;
90
- background-color: #d9d2c2;
91
- }
92
-
93
- .dark-mode .engine-tab.active {
73
+ .dark-mode {
94
74
color: #ffffff;
95
75
background-color: #555555;
96
76
}
@@ -188,24 +168,26 @@ const someHTML = `
188
168
</svg>
189
169
</a>
190
170
</div>
191
- <div class="engine-tabs">
192
- <span class="engine-tab active" data-engine="visit">访问网址</span>
193
- <span class="engine-tab" data-engine="google_ipv4">Google IPv4</span>
194
- <span class="engine-tab" data-engine="google_ipv6">Google IPv6</span>
195
- <span class="engine-tab" data-engine="duckduckgo">DuckDuckGo</span>
196
- <span class="engine-tab" data-engine="bing">Bing</span>
171
+ <div class="websites">
172
+ <input type="text" class="search-box" placeholder="输入要访问的网址。。。" />
173
+ </div>
174
+ <h3>搜索引擎</h3>
175
+ <hr>
176
+ <div class="websites">
177
+ <div><a class="website" href="https://www.google.com" target="_blank">Google IPv4</a></div>
178
+ <div><a class="website" href="https://ipv6.google.com" target="_blank">Google IPv6</a></div>
179
+ <div><a class="website" href="https://duckduckgo.com" target="_blank">DuckDuckGo</a></div>
180
+ <div><a class="website" href="https://www.bing.com" target="_blank">Bing</a></div>
197
181
</div>
198
- <input type="text" class="search-box" placeholder="输入要访问的网址..." />
199
182
<h3>常用网站</h3>
200
183
<hr>
201
184
<div class="websites">
202
185
<div><a class="website" href="https://duckduckgo.com/aichat" target="_blank">DuckDuckGo AI Chat</a></div>
203
186
<div><a class="website" href="https://zh.wikipedia.org/" target="_blank">Wikipedia</a></div>
204
- <div><a class="website" href="https://www.youtube.com/?gl=US" target="_blank">YouTube</a>
205
- </div>
187
+ <div><a class="website" href="https://www.youtube.com/?gl=US" target="_blank">YouTube</a></div>
206
188
<div><a class="website" href="https://x.com/" target="_blank">X / Twitter</a></div>
207
189
<div><a class="website" href="https://www.apkmirror.com/" target="_blank">APKMirror</a></div>
208
- <div><a class="website" href="https://web.telegram.org/" target="_blank">Telegram 网页版 </a></div>
190
+ <div><a class="website" href="https://web.telegram.org/" target="_blank">Web Telegram </a></div>
209
191
</div>
210
192
<h3>新闻网站</h3>
211
193
<hr>
@@ -233,18 +215,13 @@ const someHTML = `
233
215
<p id="copyright"></p>
234
216
</div>
235
217
</div>
236
-
237
218
<script>
238
219
const currentYear = new Date().getFullYear();
239
220
document.getElementById("copyright").innerHTML = "Copyright 2020-" + currentYear + " <a href='https://github.com/netptop/siteproxy' target='_blank'>siteproxy</a> All Rights Reserved";
240
221
</script>
241
-
242
222
<script>
243
223
const searchBox = document.querySelector('.search-box');
244
- const engineTabs = document.querySelectorAll('.engine-tab');
245
224
const themeToggle = document.querySelector('.theme-toggle');
246
- let activeEngine = 'visit';
247
-
248
225
window.addEventListener('load', () => {
249
226
const theme = localStorage.getItem('theme');
250
227
if (theme === 'dark-mode') {
@@ -268,87 +245,36 @@ const someHTML = `
268
245
269
246
searchBox.addEventListener('keyup', (event) => {
270
247
if (event.key === 'Enter') {
271
- const inputText = searchBox.value;
272
- if (activeEngine === 'visit') {
273
- visitWebsite(inputText);
274
- } else {
275
- search(inputText);
276
- }
248
+ navigate();
277
249
}
278
250
});
279
251
280
- engineTabs.forEach(tab => {
281
- tab.addEventListener('click', () => {
282
- engineTabs.forEach(t => t.classList.remove('active'));
283
- tab.classList.add('active');
284
- activeEngine = tab.dataset.engine;
285
- if (activeEngine === 'visit') {
286
- searchBox.placeholder = "输入要访问的网址...";
287
- } else {
288
- searchBox.placeholder = "输入搜索内容...";
289
- }
290
- });
291
- });
292
-
293
- function visitWebsite(url) {
294
- if (url.startsWith('http://') || url.startsWith('https://')) {
295
- window.open(url, '_blank');
296
- } else {
297
- alert('请输入以 http:// 或 https:// 开头的 URL');
252
+ function navigate() {
253
+ let inputText = searchBox.value.trim();
254
+ if (!inputText.startsWith('http://') && !inputText.startsWith('https://')) {
255
+ inputText = 'https://' + inputText;
298
256
}
299
- }
300
-
301
- function search(query) {
302
- if (activeEngine === 'google_ipv4') {
303
- window.open('https://ipv4.google.com/search?q=' + encodeURIComponent(query), '_blank');
304
- } else if (activeEngine === 'google_ipv6') {
305
- window.open('https://ipv6.google.com/search?q=' + encodeURIComponent(query), '_blank');
306
- } else if (activeEngine === 'duckduckgo') {
307
- window.open('https://duckduckgo.com/?kae=c&kp=-2&kz=-1&kav=1&kn=1&k1=-1&kk=-1&kaj=m&kay=b&kak=-1&kax=-1&kap=-1&kaq=-1&kao=-1&kau=-1&ko=1&kpsb=-1&kbg=-1&kbd=-1&kbc=1&kw=w&kt=n&ka=n&k18=1&q=' + encodeURIComponent(query), '_blank');
308
- } else if (activeEngine === 'bing') {
309
- window.open('https://www.bing.com/search?q=' + encodeURIComponent(query), '_blank');
310
- }
257
+ window.open(inputText, '_blank');
311
258
}
312
259
</script>
313
260
</body>
314
-
315
261
</html>
316
-
317
262
`
318
- /**
319
- * rawHtmlResponse delievers a response with HTML inputted directly
320
- * into the worker script
321
- * @param {string } html
322
- */
323
- async function rawHtmlResponse ( html ) {
324
- const init = {
325
- headers : {
326
- 'content-type' : 'text/html;charset=UTF-8' ,
327
- } ,
328
- }
329
-
330
- return new Response ( html , init )
331
- }
332
-
333
263
/**
334
- * rawJsonResponse delievers a response with a Json Object inputted directly
264
+ * rawHtmlResponse delievers a response with HTML inputted directly
335
265
* into the worker script
336
- * @param {Object } json
266
+ * @param {string } html
337
267
*/
338
- async function rawJsonResponse ( json ) {
268
+ async function rawHtmlResponse ( html ) {
339
269
const init = {
340
270
headers : {
341
- 'content-type' : 'application/json ;charset=UTF-8' ,
271
+ 'content-type' : 'text/html ;charset=UTF-8' ,
342
272
} ,
343
- }
344
-
345
- return new Response ( JSON . stringify ( json ) , init )
273
+ } ;
274
+ return new Response ( html , init ) ;
346
275
}
347
276
348
277
addEventListener ( 'fetch' , event => {
349
- const { url } = event . request
350
-
351
- /*if (url.endsWith('/index_netptop.html')) {
352
- */
353
- return event . respondWith ( rawHtmlResponse ( someHTML ) )
278
+ const { url } = event . request ;
279
+ return event . respondWith ( rawHtmlResponse ( someHTML ) ) ;
354
280
} )
0 commit comments