@@ -65,32 +65,12 @@ const someHTML = `
6565 background-color: #333333;
6666 }
6767
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 {
8469 border-color: #777777;
8570 background-color: #333333;
8671 }
8772
88- .engine-tab.active {
89- color: #7c786f;
90- background-color: #d9d2c2;
91- }
92-
93- .dark-mode .engine-tab.active {
73+ .dark-mode {
9474 color: #ffffff;
9575 background-color: #555555;
9676 }
@@ -188,24 +168,26 @@ const someHTML = `
188168 </svg>
189169 </a>
190170 </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>
197181 </div>
198- <input type="text" class="search-box" placeholder="输入要访问的网址..." />
199182 <h3>常用网站</h3>
200183 <hr>
201184 <div class="websites">
202185 <div><a class="website" href="https://duckduckgo.com/aichat" target="_blank">DuckDuckGo AI Chat</a></div>
203186 <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>
206188 <div><a class="website" href="https://x.com/" target="_blank">X / Twitter</a></div>
207189 <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>
209191 </div>
210192 <h3>新闻网站</h3>
211193 <hr>
@@ -233,18 +215,13 @@ const someHTML = `
233215 <p id="copyright"></p>
234216 </div>
235217 </div>
236-
237218 <script>
238219 const currentYear = new Date().getFullYear();
239220 document.getElementById("copyright").innerHTML = "Copyright 2020-" + currentYear + " <a href='https://github.com/netptop/siteproxy' target='_blank'>siteproxy</a> All Rights Reserved";
240221 </script>
241-
242222 <script>
243223 const searchBox = document.querySelector('.search-box');
244- const engineTabs = document.querySelectorAll('.engine-tab');
245224 const themeToggle = document.querySelector('.theme-toggle');
246- let activeEngine = 'visit';
247-
248225 window.addEventListener('load', () => {
249226 const theme = localStorage.getItem('theme');
250227 if (theme === 'dark-mode') {
@@ -268,87 +245,36 @@ const someHTML = `
268245
269246 searchBox.addEventListener('keyup', (event) => {
270247 if (event.key === 'Enter') {
271- const inputText = searchBox.value;
272- if (activeEngine === 'visit') {
273- visitWebsite(inputText);
274- } else {
275- search(inputText);
276- }
248+ navigate();
277249 }
278250 });
279251
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;
298256 }
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');
311258 }
312259 </script>
313260</body>
314-
315261</html>
316-
317262`
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-
333263/**
334- * rawJsonResponse delievers a response with a Json Object inputted directly
264+ * rawHtmlResponse delievers a response with HTML inputted directly
335265 * into the worker script
336- * @param {Object } json
266+ * @param {string } html
337267 */
338- async function rawJsonResponse ( json ) {
268+ async function rawHtmlResponse ( html ) {
339269 const init = {
340270 headers : {
341- 'content-type' : 'application/json ;charset=UTF-8' ,
271+ 'content-type' : 'text/html ;charset=UTF-8' ,
342272 } ,
343- }
344-
345- return new Response ( JSON . stringify ( json ) , init )
273+ } ;
274+ return new Response ( html , init ) ;
346275}
347276
348277addEventListener ( '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 ) ) ;
354280} )
0 commit comments