index.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. <!DOCTYPE html>
  2. <html lang="zh-Hans-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=350px, initial-scale=1.0" />
  6. <title>自己搜去</title>
  7. <meta
  8. name="description"
  9. content="给不愿意或不会自己搜索的人类,快速生成教他们搜索页面的工具"
  10. />
  11. <meta name="repo" content="search-it-yourself" />
  12. <meta name="author" content="wasteest, pj568" />
  13. <meta name="license" content="cc by-sa 4.0" />
  14. <link
  15. rel="icon"
  16. type="image/svg+xml"
  17. href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ctext y='.9em' font-size='90'%3E🔍%3C/text%3E%3C/svg%3E"
  18. />
  19. <style>
  20. :root,
  21. html {
  22. padding: 0;
  23. margin: 0;
  24. height: 100%;
  25. }
  26. body {
  27. margin: 0;
  28. padding: 40px 20px;
  29. font-family: Arial, sans-serif;
  30. background-color: #e6e6e6;
  31. color: #333333;
  32. }
  33. h1 {
  34. text-align: center;
  35. font-weight: bold;
  36. color: #333333;
  37. }
  38. .search-container {
  39. max-width: 600px;
  40. margin: 20vh auto 0 auto;
  41. text-align: center;
  42. }
  43. .search-form {
  44. display: flex;
  45. gap: 10px;
  46. justify-content: center;
  47. align-items: center;
  48. }
  49. .search-input {
  50. padding: 12px;
  51. font-size: 16px;
  52. border: none;
  53. background: #f5f5f5;
  54. width: 300px;
  55. }
  56. .search-button {
  57. padding: 12px 24px;
  58. font-size: 16px;
  59. border: none;
  60. background: #888;
  61. color: white;
  62. cursor: pointer;
  63. svg {
  64. width: 16px;
  65. height: 16px;
  66. }
  67. }
  68. .search-button:hover {
  69. background: #555;
  70. }
  71. /* 深色模式支持 */
  72. @media (prefers-color-scheme: dark) {
  73. :root,
  74. html,
  75. body {
  76. background-color: #212121;
  77. color: #f1f1f1;
  78. }
  79. h1 {
  80. color: #f1f1f1;
  81. }
  82. .search-input {
  83. background: #333333;
  84. color: #f1f1f1;
  85. border: 1px solid #555555;
  86. }
  87. .search-button {
  88. background: #4a90e2;
  89. color: #f1f1f1;
  90. border: 1px solid #357abd;
  91. }
  92. .search-button:hover {
  93. background: #357abd;
  94. }
  95. }
  96. /* 搜索结果样式 */
  97. .search-result {
  98. margin-top: 30px;
  99. text-align: center;
  100. }
  101. .result-code-block {
  102. display: inline-block;
  103. background: #f8f9fa;
  104. border: 1px solid #e9ecef;
  105. padding: 15px;
  106. margin: 10px 0;
  107. font-family: "Courier New", monospace;
  108. font-size: 14px;
  109. color: #495057;
  110. cursor: pointer;
  111. transition: all 0.2s ease;
  112. max-width: 100%;
  113. word-break: break-all;
  114. }
  115. .result-code-block:hover {
  116. background: #e9ecef;
  117. border-color: #adb5bd;
  118. }
  119. .result-code-block:active {
  120. background: #dee2e6;
  121. transform: scale(0.98);
  122. }
  123. .copy-notification {
  124. position: fixed;
  125. top: 20px;
  126. right: 20px;
  127. background: #1f512b;
  128. color: white;
  129. padding: 10px 20px;
  130. font-size: 14px;
  131. opacity: 0;
  132. transition: opacity 0.3s ease;
  133. z-index: 1000;
  134. }
  135. .copy-notification.show {
  136. opacity: 1;
  137. }
  138. /* 深色模式下的搜索结果样式 */
  139. @media (prefers-color-scheme: dark) {
  140. .result-code-block {
  141. background: #2d3748;
  142. border-color: #4a5568;
  143. color: #e2e8f0;
  144. }
  145. .result-code-block:hover {
  146. background: #4a5568;
  147. border-color: #718096;
  148. }
  149. .result-code-block:active {
  150. background: #718096;
  151. }
  152. }
  153. /* 有序列表样式 */
  154. .list-div {
  155. display: none;
  156. background: #12121211;
  157. max-width: 600px;
  158. margin: 40px auto 0;
  159. padding: 1rem;
  160. position: relative;
  161. a {
  162. text-decoration: underline;
  163. cursor: pointer;
  164. position: absolute;
  165. top: 1rem;
  166. right: 1rem;
  167. }
  168. }
  169. .list-div li {
  170. margin-bottom: 1rem;
  171. color: inherit;
  172. }
  173. .list-div li:last-child {
  174. margin-bottom: 0;
  175. }
  176. .list-div li p {
  177. margin: 0;
  178. padding: 0;
  179. }
  180. /* 深色模式下的有序列表样式 */
  181. @media (prefers-color-scheme: dark) {
  182. .list-div {
  183. background: #e9ecef11;
  184. }
  185. .list-div li {
  186. color: #f1f1f1;
  187. }
  188. }
  189. .cursor {
  190. color: #333333;
  191. display: none;
  192. top: -24px;
  193. left: -24px;
  194. position: fixed;
  195. width: 24px;
  196. height: 24px;
  197. z-index: 1000;
  198. pointer-events: none;
  199. transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  200. filter: drop-shadow(0 0 0.3rem white);
  201. }
  202. .cursor.visible {
  203. display: block;
  204. }
  205. .cursor.click {
  206. animation: clickPulse 0.3s ease-in-out;
  207. }
  208. @keyframes clickPulse {
  209. 0% {
  210. transform: scale(1);
  211. }
  212. 50% {
  213. transform: scale(1.2);
  214. }
  215. 100% {
  216. transform: scale(1);
  217. }
  218. }
  219. /* 输入框焦点状态下的光标 */
  220. .search-input.focused {
  221. box-shadow: 0 0 0 2px #007bff;
  222. }
  223. /* 按钮点击效果 */
  224. .search-button.clicked {
  225. transform: scale(0.95);
  226. transition: transform 0.1s ease;
  227. }
  228. /* 深色模式下的光标 */
  229. @media (prefers-color-scheme: dark) {
  230. .cursor {
  231. color: #e9ecef;
  232. filter: drop-shadow(0 0 0.3rem black);
  233. }
  234. }
  235. /* 自定义搜索引擎输入框样式 */
  236. .search-engine-input {
  237. box-sizing: border-box;
  238. padding: 12px;
  239. font-size: 16px;
  240. border: none;
  241. background: #f5f5f5;
  242. width: 100%;
  243. }
  244. /* 深色模式下的自定义搜索引擎输入框样式 */
  245. @media (prefers-color-scheme: dark) {
  246. .search-engine-input {
  247. background: #333333;
  248. color: #f1f1f1;
  249. border: 1px solid #555555;
  250. }
  251. }
  252. </style>
  253. </head>
  254. <body>
  255. <div class="search-container">
  256. <h1>自己搜去</h1>
  257. <form class="search-form" id="searchForm" action="javascript:void(0);">
  258. <input
  259. type="text"
  260. class="search-input"
  261. id="searchInput"
  262. name="q"
  263. placeholder="请输入搜索内容"
  264. />
  265. <button type="submit" class="search-button">
  266. <!-- MIT Copyright (c) 2018-2025 Tabler -->
  267. <svg
  268. xmlns="http://www.w3.org/2000/svg"
  269. width="24"
  270. height="24"
  271. viewBox="0 0 24 24"
  272. fill="none"
  273. stroke="currentColor"
  274. stroke-width="2"
  275. stroke-linecap="round"
  276. stroke-linejoin="round"
  277. class="icon icon-tabler icons-tabler-outline icon-tabler-search"
  278. >
  279. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  280. <path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" />
  281. <path d="M21 21l-6 -6" />
  282. </svg>
  283. </button>
  284. </form>
  285. <!-- 搜索链接区域 -->
  286. <div class="search-result" id="searchResult" style="display: none">
  287. <div class="result-code-block" id="resultLink" title="点击复制链接">
  288. <!-- 搜索链接将在这里显示 -->
  289. </div>
  290. </div>
  291. </div>
  292. <!-- 复制成功提示 -->
  293. <div class="copy-notification" id="copyNotification">
  294. 链接已复制到剪贴板!
  295. </div>
  296. <div class="list-div">
  297. <ol>
  298. <li>
  299. <p>输入要搜索的内容;</p>
  300. </li>
  301. <li>
  302. <p>点击搜索按钮;</p>
  303. </li>
  304. <li>
  305. <p>将生成的链接复制到剪贴板,发给不愿意或不会自己搜索的人类。</p>
  306. </li>
  307. </ol>
  308. <!-- 自定义搜索引擎输入框 -->
  309. <input
  310. type="text"
  311. class="search-engine-input"
  312. id="searchEngineInput"
  313. placeholder="https://bing.com/search?q=QUERY"
  314. />
  315. <a
  316. onclick="javascript:window.open('?q=Z2l0IHJlcG8gc2VhcmNoLWl0LXlvdXJzZWxmIHBqNTY4')"
  317. >
  318. 项目源码
  319. </a>
  320. </div>
  321. <div class="cursor">
  322. <!-- MIT Copyright (c) 2018-2025 Tabler -->
  323. <svg
  324. xmlns="http://www.w3.org/2000/svg"
  325. width="24"
  326. height="24"
  327. viewBox="0 0 24 24"
  328. fill="none"
  329. stroke="currentColor"
  330. stroke-width="2"
  331. stroke-linecap="round"
  332. stroke-linejoin="round"
  333. class="icon icon-tabler icons-tabler-outline icon-tabler-pointer"
  334. >
  335. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  336. <path
  337. d="M7.904 17.563a1.2 1.2 0 0 0 2.228 .308l2.09 -3.093l4.907 4.907a1.067 1.067 0 0 0 1.509 0l1.047 -1.047a1.067 1.067 0 0 0 0 -1.509l-4.907 -4.907l3.113 -2.09a1.2 1.2 0 0 0 -.309 -2.228l-13.582 -3.904l3.904 13.563z"
  338. />
  339. </svg>
  340. </div>
  341. <script>
  342. // 语言检测和翻译功能
  343. function detectLanguage() {
  344. // 获取浏览器语言偏好
  345. const browserLang =
  346. navigator.language || navigator.userLanguage || "zh-CN";
  347. // 检查是否为英语(包含 en 开头的语言代码)
  348. const isEnglish = browserLang.startsWith("en");
  349. // 翻译映射
  350. const translations = {
  351. title: "Search It Yourself",
  352. mainTitle: "Search It Yourself",
  353. inputPlaceholder: "Enter search content",
  354. copyNotification: "Link copied to clipboard!",
  355. emptyInputAlert: "Please enter search content",
  356. instruction1: "Enter the content to search;",
  357. instruction2: "Click the search button;",
  358. instruction3:
  359. "Copy the generated link to clipboard and send it to people who are unwilling or unable to search themselves.",
  360. projectSource: "Project Source Code",
  361. };
  362. // 如果是英语,则进行翻译
  363. if (isEnglish) {
  364. // 翻译页面标题
  365. document.title = translations.title;
  366. // 翻译主标题
  367. const mainTitle = document.querySelector("h1");
  368. if (mainTitle) {
  369. mainTitle.textContent = translations.mainTitle;
  370. }
  371. // 翻译输入框占位符
  372. const searchInput = document.getElementById("searchInput");
  373. if (searchInput) {
  374. searchInput.placeholder = translations.inputPlaceholder;
  375. }
  376. // 翻译复制成功提示
  377. const copyNotification = document.getElementById("copyNotification");
  378. if (copyNotification) {
  379. copyNotification.textContent = translations.copyNotification;
  380. }
  381. // 翻译使用说明
  382. const listDiv = document.querySelector(".list-div");
  383. if (listDiv) {
  384. const instructions = listDiv.querySelectorAll("p");
  385. if (instructions.length >= 3) {
  386. instructions[0].textContent = translations.instruction1;
  387. instructions[1].textContent = translations.instruction2;
  388. instructions[2].textContent = translations.instruction3;
  389. }
  390. // 翻译项目源码链接
  391. const projectSourceLink = listDiv.querySelector("a");
  392. if (projectSourceLink) {
  393. projectSourceLink.textContent = translations.projectSource;
  394. }
  395. }
  396. }
  397. return isEnglish;
  398. }
  399. const isEnglish = detectLanguage();
  400. // 获取页面元素
  401. const searchForm = document.getElementById("searchForm");
  402. const searchInput = document.getElementById("searchInput");
  403. const searchResult = document.getElementById("searchResult");
  404. const resultLink = document.getElementById("resultLink");
  405. const copyNotification = document.getElementById("copyNotification");
  406. const listDiv = document.querySelector(".list-div");
  407. const cursor = document.querySelector(".cursor");
  408. const searchButton = document.querySelector(".search-button");
  409. const defaultSearchEngine = "https://bing.com/search?q=QUERY";
  410. // 光标动画函数
  411. function moveCursorTo(element, callback, x = 0, y = 0) {
  412. const rect = element.getBoundingClientRect();
  413. const cursorRect = cursor.getBoundingClientRect();
  414. // 计算光标应该移动到的位置(元素中心)
  415. const targetX = rect.left + rect.width / 2 - cursorRect.width / 2 + x;
  416. const targetY = rect.top + rect.height / 2 - cursorRect.height / 2 + y;
  417. cursor.style.left = targetX + "px";
  418. cursor.style.top = targetY + "px";
  419. setTimeout(callback, 1000); // 等待移动动画完成
  420. }
  421. // 点击光标动画
  422. function clickCursor(callback) {
  423. cursor.classList.add("click");
  424. setTimeout(() => {
  425. cursor.classList.remove("click");
  426. if (callback) callback();
  427. }, 400);
  428. }
  429. // 逐字输入动画
  430. function typeText(text, callback) {
  431. let index = 0;
  432. searchInput.value = "";
  433. function typeNextChar() {
  434. if (index < text.length) {
  435. searchInput.value += text[index];
  436. searchInput.dispatchEvent(new Event("input", { bubbles: true }));
  437. index++;
  438. setTimeout(typeNextChar, 100); // 每个字符间隔 100ms
  439. } else {
  440. if (callback) callback();
  441. }
  442. }
  443. typeNextChar();
  444. }
  445. // 动画序列控制器
  446. function runAnimationSequence(queryValue, searchEngineUrl) {
  447. // 显示光标
  448. cursor.classList.add("visible");
  449. // 步骤 1: 光标从右上角移动到搜索框
  450. setTimeout(() => {
  451. moveCursorTo(
  452. searchInput,
  453. () => {
  454. // 步骤 2: 点击搜索框
  455. clickCursor(() => {
  456. searchInput.classList.add("focused");
  457. searchInput.focus();
  458. // 等待焦点效果,然后开始输入
  459. setTimeout(() => {
  460. // 步骤 3: 逐字输入查询内容
  461. typeText(queryValue, () => {
  462. // 等待输入完成
  463. setTimeout(() => {
  464. // 步骤 4: 光标移动到搜索按钮
  465. moveCursorTo(
  466. searchButton,
  467. () => {
  468. // 步骤 5: 点击搜索按钮
  469. clickCursor(() => {
  470. searchButton.classList.add("clicked");
  471. // 等待点击效果,然后跳转
  472. setTimeout(() => {
  473. // 步骤 6: 跳转到自定义搜索引擎
  474. // 将 QUERY 替换为实际的搜索内容
  475. const searchUrl = searchEngineUrl.replace(
  476. "QUERY",
  477. encodeURIComponent(queryValue)
  478. );
  479. window.location.href = searchUrl;
  480. }, 200);
  481. });
  482. },
  483. searchButton.offsetWidth * 0.3
  484. );
  485. }, 100);
  486. });
  487. }, 300);
  488. });
  489. },
  490. searchInput.offsetWidth * 0.4,
  491. searchInput.offsetHeight * 0.3
  492. );
  493. }, 1000); // 1 秒后开始动画
  494. }
  495. function preventAllEvents() {
  496. const events = [
  497. "click",
  498. "mousedown",
  499. "mouseup",
  500. "mousemove",
  501. "keydown",
  502. "keyup",
  503. "keypress",
  504. ];
  505. events.forEach((eventType) => {
  506. document.addEventListener(
  507. eventType,
  508. function (e) {
  509. e.preventDefault();
  510. e.stopPropagation();
  511. e.stopImmediatePropagation();
  512. },
  513. true
  514. );
  515. });
  516. }
  517. // 页面初始化时检查参数 q 的值
  518. function initializePage() {
  519. const urlParams = new URLSearchParams(window.location.search);
  520. let encodedQueryValue = urlParams.get("q");
  521. let encodedSearchEngineValue = urlParams.get("se");
  522. // 对获取到的编码值进行 Base64 解码
  523. let queryValue = "";
  524. if (encodedQueryValue) {
  525. try {
  526. queryValue = decodeURIComponent(escape(atob(encodedQueryValue)));
  527. } catch (error) {
  528. // 如果解码失败,使用原始值(兼容旧链接)
  529. queryValue = encodedQueryValue;
  530. }
  531. }
  532. // 对获取到的自定义搜索引擎值进行 Base64 解码
  533. let searchEngineValue = ""; // 格式形似:https://example.com/search?q=QUERY
  534. if (encodedSearchEngineValue) {
  535. try {
  536. searchEngineValue = decodeURIComponent(
  537. escape(atob(encodedSearchEngineValue))
  538. );
  539. } catch (error) {
  540. // 如果解码失败,使用默认值
  541. searchEngineValue = defaultSearchEngine;
  542. }
  543. }
  544. // 如果没有提供自定义搜索引擎,或自定义搜索引擎没有“QUERY”,使用默认的 Bing 搜索
  545. if (
  546. !searchEngineValue ||
  547. searchEngineValue.trim() === "" ||
  548. !searchEngineValue.includes("QUERY")
  549. ) {
  550. searchEngineValue = defaultSearchEngine;
  551. } else {
  552. // 设置自定义搜索引擎输入框的占位符值为
  553. document.getElementById("searchEngineInput").placeholder =
  554. searchEngineValue;
  555. }
  556. // 如果 q 参数无或空,显示 .list-div
  557. if (!queryValue || queryValue.trim() === "") {
  558. listDiv.style.display = "block";
  559. } else {
  560. // 隐藏默认光标
  561. const style = document.createElement("style");
  562. style.textContent = "*,html,:root { cursor: none !important; }";
  563. document.head.appendChild(style);
  564. // 阻止所有鼠标事件和键盘事件
  565. preventAllEvents();
  566. // 开始动画序列
  567. runAnimationSequence(queryValue, searchEngineValue);
  568. }
  569. }
  570. initializePage();
  571. // 监听表单提交事件
  572. searchForm.addEventListener("submit", function (event) {
  573. event.preventDefault(); // 阻止表单默认提交行为
  574. const searchValue = searchInput.value.trim();
  575. // 检查输入框是否为空
  576. if (!searchValue) {
  577. alert(isEnglish ? "Please enter search content" : "请输入搜索内容");
  578. return;
  579. }
  580. // 生成搜索链接,对搜索值进行 Base64 编码混淆
  581. const currentUrl = window.location.href.split("?")[0]; // 获取当前页面路径,去除查询参数
  582. const obfuscatedValue = btoa(unescape(encodeURIComponent(searchValue)));
  583. // 获取当前页面输入框中自定义搜索引擎值(优先级高于当前 URL 中的 se 参数)
  584. const currentSearchEngine = document
  585. .getElementById("searchEngineInput")
  586. .value.trim();
  587. // 获取当前 URL 中的 se 参数(如果有)
  588. const urlParams = new URLSearchParams(window.location.search);
  589. const paramSearchEngine = urlParams.get("se");
  590. // 验证自定义搜索引擎格式,确保包含 QUERY 占位符
  591. let validSearchEngine = "";
  592. if (currentSearchEngine && currentSearchEngine.includes("QUERY")) {
  593. validSearchEngine = currentSearchEngine;
  594. }
  595. // 检查 URL 参数中的搜索引擎(需要先解码再验证)
  596. else if (paramSearchEngine) {
  597. let decodedSearchEngine = "";
  598. try {
  599. // 尝试 Base64 解码
  600. decodedSearchEngine = decodeURIComponent(
  601. escape(atob(paramSearchEngine))
  602. );
  603. } catch (error) {
  604. // 如果解码失败,使用默认值
  605. decodedSearchEngine = defaultSearchEngine;
  606. }
  607. // 验证解码后的搜索引擎是否包含 QUERY
  608. if (decodedSearchEngine.includes("QUERY")) {
  609. validSearchEngine = decodedSearchEngine;
  610. }
  611. }
  612. // 构建搜索链接,包含原有的搜索引擎参数
  613. let searchLink = `${currentUrl}?q=${encodeURIComponent(
  614. obfuscatedValue
  615. )}`;
  616. if (validSearchEngine) {
  617. searchLink += `&se=${btoa(
  618. unescape(encodeURIComponent(validSearchEngine))
  619. )}`;
  620. }
  621. // 在代码块中显示链接
  622. resultLink.textContent = searchLink;
  623. searchResult.style.display = "block";
  624. // 滚动到结果区域
  625. searchResult.scrollIntoView({ behavior: "smooth", block: "nearest" });
  626. });
  627. // 监听结果链接点击事件,实现复制功能
  628. resultLink.addEventListener("click", async function () {
  629. const linkText = resultLink.textContent;
  630. try {
  631. // 使用现代剪贴板 API
  632. await navigator.clipboard.writeText(linkText);
  633. // 显示复制成功提示
  634. copyNotification.classList.add("show");
  635. // 3 秒后隐藏提示
  636. setTimeout(() => {
  637. copyNotification.classList.remove("show");
  638. }, 3000);
  639. } catch (err) {
  640. // 兼容旧版浏览器的备用方案
  641. console.warn("现代剪贴板 API 不可用,使用备用方案");
  642. // 创建临时文本区域
  643. const textArea = document.createElement("textarea");
  644. textArea.value = linkText;
  645. textArea.style.position = "fixed";
  646. textArea.style.left = "-999999px";
  647. textArea.style.top = "-999999px";
  648. document.body.appendChild(textArea);
  649. textArea.focus();
  650. textArea.select();
  651. try {
  652. document.execCommand("copy");
  653. // 显示复制成功提示
  654. copyNotification.classList.add("show");
  655. // 3 秒后隐藏提示
  656. setTimeout(() => {
  657. copyNotification.classList.remove("show");
  658. }, 3000);
  659. } catch (err) {
  660. alert("复制失败,请手动复制链接:" + linkText);
  661. }
  662. // 清理临时元素
  663. document.body.removeChild(textArea);
  664. }
  665. });
  666. // 监听输入框回车键事件,确保在按下回车键时触发表单提交
  667. searchInput.addEventListener("keydown", function (event) {
  668. if (event.key === "Enter") {
  669. event.preventDefault(); // 阻止输入框的默认回车行为
  670. searchForm.dispatchEvent(new Event("submit"));
  671. }
  672. });
  673. // 输入框获得焦点时隐藏之前的结果
  674. searchInput.addEventListener("focus", function () {
  675. searchResult.style.display = "none";
  676. });
  677. </script>
  678. </body>
  679. </html>