找回密码
 注册
搜索
系统gho:最纯净好用系统下载站升级VIP会员,联系 微信:wuyouceo
查看: 1581|回复: 92

用豆包做的无忧论坛搜索油猴扩展

 荐  火.. [复制链接]
发表于 3 天前 | 显示全部楼层 |阅读模式
本帖最后由 qjldw 于 2026-11-21 04:47 编辑
  1. // ==UserScript==
  2. // @name         无忧论坛 · 站内搜索增强(默认百度 site:)
  3. // @namespace    https://bbs.wuyou.net/
  4. // @version      3.4.3
  5. // @description  无忧论坛取消站内搜索后的替代方案。①论坛页:右上角搜索框,默认走百度 site:(必应已忽略 site: 运算符,仅作备用),支持 10 条搜索历史、多引擎切换;②结果页(百度 / 必应):自动把 wuyou.net 条目卡片化标注(必应会先解码 /ck/a 跳转链),并提供「只看无忧站内」筛选。
  6. // @match        *://*.wuyou.net/*
  7. // @match        *://*.baidu.com/s*
  8. // @match        *://*.bing.com/search*
  9. // @run-at       document-idle
  10. // @noframes
  11. // @grant        none
  12. // ==/UserScript==

  13. (function () {
  14.   'use strict';

  15.   /* ================== 配置 ================== */
  16.   const SITE = 'wuyou.net';                 // 站内范围(site:wuyou.net)
  17.   const DEFAULT_ENGINE = 'baidu';           // baidu | google | bing(默认百度:必应已忽略 site:;360 已移除,其 site: 实测归零)
  18.   const ENGINES = {
  19.     baidu:  { label: '百度', url: 'https://www.baidu.com/s?ie=utf-8&wd=' },
  20.     google: { label: '谷歌', url: 'https://www.google.com/search?q=' },
  21.     bing:   { label: '必应', url: 'https://cn.bing.com/search?q=', noSite: true }   // noSite: 该引擎已忽略 site: 运算符
  22.   };
  23.   const SUGGEST = false;                      // 关键词联想(走百度 JSONP)。只在「历史里没有匹配」时才请求,设为 false 则完全不请求
  24.   const HIST_FIRST = true;                   // 历史优先:输入时先在前缀/包含命中的历史里过滤,命中就只显示历史
  25.   const HIJACK_SITE_SEARCH = true;          // 是否接管站点自带的 search.php 搜索框(VIP/将军级用户可设 false 保留原功能)
  26.   const HIST_MAX = 10;                      // 搜索历史条数
  27.   const HOTKEY = 's';                       // Alt+S 聚焦搜索框
  28.   /* ========================================== */

  29.   /* 站点判断:结果页(百度 / 必应)vs 论坛页 */
  30.   const onBaiduSerp = /^(www\.)?baidu\.com$/i.test(location.hostname) && location.pathname.indexOf('/s') === 0;
  31.   const onBingSerp  = /^(cn|www)\.bing\.com$/i.test(location.hostname) && location.pathname.indexOf('/search') === 0;

  32.   if (onBaiduSerp) { initSerp('baidu'); }
  33.   else if (onBingSerp) { initSerp('bing'); }
  34.   else { initForum(); }

  35.   /* ==========================================================
  36.      一、论坛页:搜索框
  37.      ========================================================== */
  38.   function initForum() {

  39.     const CSS = `
  40. #wys-panel{position:fixed;top:34px;right:12px;z-index:2147483100;display:flex;align-items:center;
  41.   font:13px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;color:#333;}
  42. #wys-bar{display:flex;align-items:center;gap:4px;padding:4px 6px;border-radius:999px;
  43.   background:rgba(255,255,255,.96);border:1px solid #d7e2ee;box-shadow:0 2px 12px rgba(0,0,0,.18);}
  44. #wys-input{width:190px;height:26px;padding:0 10px;border:1px solid #cfdae6;border-radius:999px;
  45.   outline:none;font-size:13px;background:#f7fafd;color:#222;box-sizing:border-box;
  46.   transition:border-color .15s,box-shadow .15s;}
  47. #wys-input:focus{border-color:#3b82c4;background:#fff;box-shadow:0 0 0 3px rgba(59,130,196,.15);}
  48. #wys-engine{height:26px;border:1px solid #cfdae6;border-radius:999px;background:#fff;
  49.   font-size:12px;color:#333;padding:0 2px;outline:none;cursor:pointer;}
  50. #wys-go{height:28px;padding:0 12px;border:0;border-radius:999px;background:#2f6fb5;color:#fff;
  51.   font-size:12px;cursor:pointer;white-space:nowrap;}
  52. #wys-go:hover{background:#255c99;}
  53. #wys-min{width:20px;height:26px;border:0;background:transparent;color:#93a5b8;cursor:pointer;font-size:14px;line-height:1;}
  54. #wys-min:hover{color:#2f6fb5;}
  55. #wys-open{display:none;width:40px;height:40px;border:0;border-radius:50%;background:#2f6fb5;color:#fff;
  56.   font-size:13px;cursor:pointer;box-shadow:0 3px 12px rgba(0,0,0,.25);}
  57. #wys-open:hover{background:#255c99;}
  58. #wys-panel[data-min="1"] #wys-bar{display:none;}
  59. #wys-panel[data-min="1"] #wys-open{display:block;}

  60. #wys-sug{position:fixed;z-index:2147483300;display:none;max-height:250px;overflow:auto;box-sizing:border-box;
  61.   background:#fff;border:1px solid #d7e2ee;border-radius:8px;box-shadow:0 8px 22px rgba(15,35,60,.14);}
  62. #wys-sug .sug-cap{padding:5px 10px;font-size:11px;color:#9aabbd;background:#fafcfe;border-bottom:1px solid #eef3f8;}
  63. #wys-sug .sug-item{padding:6px 10px;font-size:12px;color:#33475b;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
  64. #wys-sug .sug-item:hover,#wys-sug .sug-item.on{background:#eef5fc;color:#2f6fb5;}

  65. @media (max-width:620px){
  66.   #wys-panel{left:8px;right:8px;justify-content:flex-end;}
  67.   #wys-bar{width:100%;flex-wrap:wrap;justify-content:flex-end;}
  68.   #wys-input{flex:1 1 110px;width:auto;min-width:96px;}
  69. }`;

  70.     const KEY = { engine: 'wys.engine', min: 'wys.min', hist: 'wys.hist' };
  71.     const load = (k, d) => { try { const v = localStorage.getItem(k); return v === null ? d : v; } catch (e) { return d; } };
  72.     const save = (k, v) => { try { localStorage.setItem(k, v); } catch (e) { /* 忽略 */ } };

  73.     let engine = load(KEY.engine, DEFAULT_ENGINE);
  74.     if (!ENGINES[engine]) engine = DEFAULT_ENGINE;

  75.     // 默认引擎迁移:只做一次,把本地存着的旧默认值(百度)覆盖成必应。
  76.     // 之后你在下拉里手动选的其他引擎不会被再改回来。
  77.     const ENGINE_STAMP = 'v340-baidu';
  78.     if (load('wys.engineStamp', '') !== ENGINE_STAMP) {
  79.       engine = DEFAULT_ENGINE;
  80.       save(KEY.engine, engine);
  81.       save('wys.engineStamp', ENGINE_STAMP);
  82.     }

  83.     const style = document.createElement('style');
  84.     style.textContent = CSS;
  85.     document.head.appendChild(style);

  86.     const panel = document.createElement('div');
  87.     panel.id = 'wys-panel';
  88.     panel.innerHTML =
  89.       '<div id="wys-bar">' +
  90.         '<input id="wys-input" type="search" placeholder="搜索无忧论坛(回车)" autocomplete="off" spellcheck="false">' +
  91.         '<select id="wys-engine" title="搜索引擎"></select>' +
  92.         '<button id="wys-go" type="button" title="搜索">搜索</button>' +
  93.         '<button id="wys-min" type="button" title="收起">—</button>' +
  94.       '</div>' +
  95.       '<button id="wys-open" type="button" title="展开(Alt+S)">搜</button>';

  96.     const sugBox = document.createElement('div');
  97.     sugBox.id = 'wys-sug';

  98.     document.body.appendChild(panel);
  99.     document.body.appendChild(sugBox);

  100.     const input = panel.querySelector('#wys-input');
  101.     const select = panel.querySelector('#wys-engine');
  102.     const goBtn = panel.querySelector('#wys-go');
  103.     const minBtn = panel.querySelector('#wys-min');
  104.     const openBtn = panel.querySelector('#wys-open');

  105.     Object.keys(ENGINES).forEach(function (id) {
  106.       const o = document.createElement('option');
  107.       o.value = id;
  108.       o.textContent = ENGINES[id].label + (ENGINES[id].noSite ? '(无 site:)' : '');
  109.       select.appendChild(o);
  110.     });
  111.     select.value = engine;
  112.     const PH_NORMAL = '搜索无忧论坛(回车)';
  113.     const PH_NOSITE = '该引擎已忽略 site:,建议改选百度';
  114.     function syncPlaceholder() { input.placeholder = ENGINES[engine].noSite ? PH_NOSITE : PH_NORMAL; }
  115.     syncPlaceholder();

  116.     const setMin = (v) => { panel.dataset.min = v ? '1' : '0'; save(KEY.min, v ? '1' : '0'); };
  117.     // 默认收起:只留一个圆形「搜」钮,避免遮挡 Discuz 页头右侧的登录/注册区
  118.     setMin(load(KEY.min, '1') === '1');

  119.     /* ---------- 历史记录 ---------- */
  120.     function getHist() {
  121.       try { const a = JSON.parse(load(KEY.hist, '[]')); return Array.isArray(a) ? a.slice(0, HIST_MAX) : []; } catch (e) { return []; }
  122.     }
  123.     function pushHist(kw) {
  124.       const a = getHist().filter(function (x) { return x !== kw; });
  125.       a.unshift(kw);
  126.       save(KEY.hist, JSON.stringify(a.slice(0, HIST_MAX)));
  127.     }

  128.     /* ---------- 搜索 ---------- */
  129.     function buildQuery(kw) {
  130.       return 'site:' + SITE + ' ' + kw;
  131.     }

  132.     function go() {
  133.       const kw = input.value.trim();
  134.       if (!kw) { input.focus(); return; }
  135.       pushHist(kw);
  136.       hideSug();
  137.       const q = buildQuery(kw);
  138.       const url = ENGINES[engine].url + encodeURIComponent(q);
  139.       const w = window.open(url, '_blank');
  140.       if (!w) location.href = url;   // 弹窗被拦截时降级
  141.     }

  142.     goBtn.addEventListener('click', go);

  143.     input.addEventListener('keydown', function (e) {
  144.       if (e.key === 'Enter') {
  145.         e.preventDefault();
  146.         const on = sugBox.querySelector('.sug-item.on');
  147.         if (sugBox.style.display === 'block' && on) input.value = on.dataset.q;   // 回车选高亮联想词
  148.         go();
  149.       } else if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
  150.         const items = Array.prototype.slice.call(sugBox.querySelectorAll('.sug-item'));
  151.         if (!items.length || sugBox.style.display !== 'block') return;
  152.         e.preventDefault();
  153.         let idx = items.findIndex(function (n) { return n.classList.contains('on'); });
  154.         idx = e.key === 'ArrowDown' ? Math.min(items.length - 1, idx + 1) : Math.max(0, idx - 1);
  155.         items.forEach(function (n) { n.classList.remove('on'); });
  156.         items[idx].classList.add('on');
  157.         input.value = items[idx].dataset.q;
  158.       } else if (e.key === 'Escape') {
  159.         input.value = '';
  160.         input.blur();
  161.         hideSug();
  162.       }
  163.     });

  164.     minBtn.addEventListener('click', function () { setMin(true); });
  165.     openBtn.addEventListener('click', function () {
  166.       setMin(false); input.focus();
  167.       if (!input.value.trim()) showHistory();
  168.     });
  169.     select.addEventListener('change', function () { engine = select.value; save(KEY.engine, engine); syncPlaceholder(); });

  170.     document.addEventListener('keydown', function (e) {
  171.       if (e.altKey && !e.ctrlKey && !e.metaKey && e.key && e.key.toLowerCase() === HOTKEY) {
  172.         e.preventDefault(); setMin(false); input.focus(); input.select();
  173.       }
  174.     });

  175.     /* ---------- 联想词 + 历史(JSONP) ---------- */
  176.     let sugTimer = null, sugSeq = 0;
  177.     const sugCache = Object.create(null);

  178.     function hideSug() { sugBox.style.display = 'none'; sugBox.innerHTML = ''; }

  179.     function placeSug() {
  180.       const r = input.getBoundingClientRect();
  181.       sugBox.style.left = Math.max(8, r.left) + 'px';
  182.       sugBox.style.top = (r.bottom + 6) + 'px';
  183.       sugBox.style.width = Math.max(240, r.width) + 'px';
  184.     }

  185.     function renderItems(list, cap) {
  186.       if (!list || !list.length) { hideSug(); return; }
  187.       sugBox.innerHTML =
  188.         '<div class="sug-cap">' + cap + '</div>' +
  189.         list.map(function (q) {
  190.           return '<div class="sug-item" data-q="' + q.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;') + '">' +
  191.                  q.replace(/&/g, '&amp;').replace(/</g, '&lt;') + '</div>';
  192.         }).join('');
  193.       placeSug();
  194.       sugBox.style.display = 'block';
  195.     }

  196.     function showHistory() {
  197.       const h = getHist();
  198.       if (!h.length) return;
  199.       renderItems(h, '最近搜索');
  200.     }

  201.     // 历史里挑出与当前输入匹配的项:先按前缀,再按包含
  202.     function matchHist(kw) {
  203.       if (!HIST_FIRST) return [];
  204.       const h = getHist();
  205.       const low = kw.toLowerCase();
  206.       const pre = h.filter(function (q) { return String(q).toLowerCase().indexOf(low) === 0; });
  207.       if (pre.length) return pre;
  208.       return h.filter(function (q) { return String(q).toLowerCase().indexOf(low) !== -1; });
  209.     }

  210.     function fetchSug(kw) {
  211.       if (sugCache[kw]) { renderItems(sugCache[kw], '百度联想'); return; }
  212.       const cb = 'wysSug' + (++sugSeq) + '_' + Date.now();
  213.       let done = false;

  214.       window[cb] = function (data) {
  215.         done = true;
  216.         const list = (data && data.g || []).map(function (x) { return x.q; }).filter(Boolean).slice(0, 10);
  217.         sugCache[kw] = list;
  218.         if (input.value.trim() === kw && !matchHist(kw).length) renderItems(list, '百度联想');   // 防慢响应覆盖新输入 / 覆盖已命中的历史
  219.         cleanup();
  220.       };

  221.       const s = document.createElement('script');
  222.       s.src = 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&wd=' +
  223.               encodeURIComponent(kw) + '&cb=' + cb;
  224.       s.onerror = cleanup;
  225.       s.onload = function () { if (!done) cleanup(); };

  226.       function cleanup() {
  227.         try { delete window[cb]; } catch (e) { window[cb] = undefined; }
  228.         if (s.parentNode) s.parentNode.removeChild(s);
  229.       }

  230.       document.head.appendChild(s);
  231.     }

  232.     input.addEventListener('input', function () {
  233.       clearTimeout(sugTimer);
  234.       const kw = input.value.trim();
  235.       if (!kw) { showHistory(); return; }          // 清空输入 → 回到「最近搜索」

  236.       const m = matchHist(kw);                     // 历史命中优先,命中就只显示历史
  237.       if (m.length) { renderItems(m, '最近搜索'); return; }

  238.       if (!SUGGEST) { hideSug(); return; }         // 关掉联想 → 输入中不弹下拉
  239.       sugTimer = setTimeout(function () { fetchSug(kw); }, 300);
  240.     });

  241.     input.addEventListener('focus', function () { if (!input.value.trim()) showHistory(); });

  242.     sugBox.addEventListener('click', function (e) {
  243.       const it = e.target && e.target.closest ? e.target.closest('.sug-item') : null;
  244.       if (!it) return;
  245.       input.value = it.dataset.q;
  246.       hideSug();
  247.       go();
  248.     });

  249.     input.addEventListener('blur', function () { setTimeout(hideSug, 200); });
  250.     window.addEventListener('resize', function () { if (sugBox.style.display === 'block') placeSug(); });

  251.     /* ---------- 接管站点残留的搜索入口 ---------- */
  252.     if (HIJACK_SITE_SEARCH) {
  253.     document.addEventListener('click', function (e) {
  254.       const a = e.target && e.target.closest ? e.target.closest('a[href*="search.php"]') : null;
  255.       if (!a || panel.contains(a)) return;
  256.       e.preventDefault();
  257.       e.stopPropagation();
  258.       setMin(false);
  259.       input.focus();
  260.       input.select();
  261.       if (!input.value.trim()) showHistory();
  262.     }, true);

  263.     document.addEventListener('submit', function (e) {
  264.       const form = e.target;
  265.       if (!form || !form.action || form.action.indexOf('search.php') === -1) return;
  266.       const field = form.querySelector('input[name="srchtxt"], input[name="keywords"], input[name="q"], input[type="text"], input[type="search"]');
  267.       const kw = field && field.value ? field.value.trim() : '';
  268.       e.preventDefault();
  269.       e.stopPropagation();
  270.       if (!kw) { setMin(false); input.focus(); return; }
  271.       input.value = kw;
  272.       go();
  273.     }, true);
  274.     }
  275.   }

  276.   /* ==========================================================
  277.      二、结果页(百度 / 必应):把 wuyou.net 条目卡片化 + 只看站内
  278.      ========================================================== */
  279.   function initSerp(which) {

  280.     const CSS = `
  281. .wys-hit{position:relative;border-radius:6px;box-shadow:inset 3px 0 0 #2f6fb5;}
  282. .wys-hit .wys-badge{display:inline-block;margin:0 0 4px;padding:0 6px;line-height:18px;border-radius:3px;
  283.   background:#2f6fb5;color:#fff;font:11px/18px -apple-system,"Microsoft YaHei",sans-serif;vertical-align:middle;}
  284. body.wys-only-on .wys-other{display:none !important;}
  285. #wys-only{position:fixed;right:16px;bottom:16px;z-index:2147483400;height:32px;padding:0 14px;
  286.   border:1px solid #cfdae6;border-radius:999px;background:#fff;color:#2f6fb5;cursor:pointer;
  287.   font:12px/30px -apple-system,"Microsoft YaHei",sans-serif;box-shadow:0 3px 14px rgba(15,35,60,.18);}
  288. #wys-only:hover{border-color:#9dc0e0;background:#f2f8fd;}
  289. #wys-only[data-on="1"]{background:#2f6fb5;color:#fff;border-color:#2f6fb5;}
  290. #wys-bingtip{position:fixed;left:50%;transform:translateX(-50%);top:12px;z-index:2147483400;
  291.   padding:8px 14px;border-radius:8px;background:#fff8e1;border:1px solid #f0d089;color:#6b4e00;
  292.   font:12px/1.6 -apple-system,"Microsoft YaHei",sans-serif;box-shadow:0 4px 16px rgba(15,35,60,.18);max-width:92vw;}
  293. #wys-bingtip a{margin-left:6px;color:#2f6fb5;}
  294. `;

  295.     const style = document.createElement('style');
  296.     style.textContent = CSS;
  297.     document.head.appendChild(style);

  298.     let hitCount = 0;
  299.     let onlyOn = false;
  300.     const isBing = which === 'bing';

  301.     /* 结果块:百度取 #content_left 的直接子块;必应取 #b_results 里的 li.b_algo */
  302.     function getBlocks() {
  303.       if (isBing) {
  304.         return Array.prototype.slice.call(document.querySelectorAll('#b_results > li.b_algo'));
  305.       }
  306.       const box = document.querySelector('#content_left') || document.querySelector('#results');
  307.       if (!box) return [];
  308.       return Array.prototype.slice.call(box.children).filter(function (n) {
  309.         return n.nodeType === 1 && !/^(SCRIPT|STYLE)$/.test(n.tagName);
  310.       });
  311.     }

  312.     function observerTarget() {
  313.       if (isBing) return document.querySelector('#b_results') || document.body;
  314.       return document.querySelector('#content_left') || document.querySelector('#results') || document.body;
  315.     }

  316.     const DOMAIN_HIT = /^(?:https?:\/\/|\/\/)?(?:[a-z0-9-]+\.)*wuyou\.net(?:[\/?#]|$)/i;

  317.     // 百度:有机结果的跳转链接是 baidu.com/link?url=…,href 里看不到目标域名,
  318.     // 域名只出现在「显示网址」那行(cite/.c-showurl)的**可见文本**里;
  319.     // 另外「大家还在搜」这类聚合模块(class 含 result-op)里的搜索链接 href 带原查询串,
  320.     // 里面可能就有 wuyou.net,按 href 判断会整块误判,所以必须排除聚合模块、且只认可见文本。
  321.     function isHitBaidu(block) {
  322.       if (!block || block.nodeType !== 1) return false;
  323.       if (/result-op/.test(block.className || '')) return false;

  324.       const as = block.querySelectorAll('a');
  325.       for (let i = 0; i < as.length; i++) {
  326.         const href = as[i].getAttribute('href') || '';
  327.         if (DOMAIN_HIT.test(href)) return true;                            // 真·直链
  328.         if (/wuyou\.net/i.test(as[i].textContent || '')) return true;       // 显示出来的网址文本
  329.       }

  330.       const cites = block.querySelectorAll('cite, .c-showurl, .f13');
  331.       for (let j = 0; j < cites.length; j++) {
  332.         if (/wuyou\.net/i.test(cites[j].textContent || '')) return true;
  333.       }
  334.       return false;
  335.     }

  336.     // 解码必应 /ck/a 跳转链,还原真实目标地址
  337.     // 形如 https://www.bing.com/ck/a?!&&p=xxx&u=a1aHR0cHM6Ly9...&ntb=1
  338.     // u 参数是「a1 前缀 + URL-safe Base64」,需要剥离前缀、补齐填充后再解码
  339.     function unwrapBingUrl(href) {
  340.       if (!href || href.indexOf("/ck/a") === -1) return href;
  341.       try {
  342.         const u0 = new URL(href, location.origin).searchParams.get("u");
  343.         if (!u0) return href;
  344.         let u = u0;
  345.         if (u.slice(0, 2) === "a1") u = u.slice(2);
  346.         const padded = u + "=".repeat((4 - (u.length % 4)) % 4);
  347.         const out = atob(padded.replace(/-/g, "+").replace(/_/g, "/"));
  348.         return /^(https?:)?\/\//i.test(out) ? out : href;   // 不像网址就退回原值
  349.       } catch (e) {
  350.         return href;
  351.       }
  352.     }

  353.     // 必应:结果链接就是真实地址,直接看 href 最准;cite / .b_attribution 里也有域名文本兜底
  354.     function isHitBing(block) {
  355.       if (!block || block.nodeType !== 1) return false;

  356.       const as = block.querySelectorAll('a');
  357.       for (let i = 0; i < as.length; i++) {
  358.         const realHref = unwrapBingUrl(as[i].getAttribute('href') || '');
  359.         if (DOMAIN_HIT.test(realHref)) return true;            // 用解码后的真实地址判断
  360.         if (/wuyou\.net/i.test(as[i].textContent || '')) return true;
  361.       }

  362.       const cites = block.querySelectorAll('cite, .tptt, .b_attribution');
  363.       for (let j = 0; j < cites.length; j++) {
  364.         if (/wuyou\.net/i.test(cites[j].textContent || '')) return true;
  365.       }
  366.       return false;
  367.     }

  368.     function scan() {
  369.       const blocks = getBlocks();
  370.       if (!blocks.length) { hitCount = 0; bingTip(); return; }

  371.       hitCount = 0;
  372.       blocks.forEach(function (b) {
  373.         if ((isBing ? isHitBing : isHitBaidu)(b)) {
  374.           hitCount++;
  375.           if (!b.classList.contains('wys-hit')) {
  376.             b.classList.add('wys-hit');
  377.             const badge = document.createElement('span');
  378.             badge.className = 'wys-badge';
  379.             badge.textContent = '无忧站内';
  380.             // 放在块内第一个可见元素之前;找不到就插到块首
  381.             const first = b.querySelector(isBing ? 'h2' : 'h3, .c-title, .t') || b.firstChild;
  382.             if (first && first.parentNode === b) b.insertBefore(badge, first);
  383.             else b.insertBefore(badge, b.firstChild);
  384.           }
  385.           b.classList.remove('wys-other');
  386.         } else {
  387.           // 上一轮可能误标过(结果页异步渲染会替换节点),这里顺手撤回
  388.           if (b.classList.contains('wys-hit')) {
  389.             b.classList.remove('wys-hit');
  390.             const old = b.querySelector('.wys-badge');
  391.             if (old && old.parentNode) old.parentNode.removeChild(old);
  392.           }
  393.           b.classList.add('wys-other');
  394.         }
  395.       });

  396.       updateBtn();
  397.       bingTip();
  398.     }

  399.     const btn = document.createElement('button');
  400.     btn.id = 'wys-only';
  401.     btn.type = 'button';
  402.     btn.addEventListener('click', function () {
  403.       onlyOn = !onlyOn;
  404.       document.body.classList.toggle('wys-only-on', onlyOn);
  405.       updateBtn();
  406.       bingTip();
  407.     });

  408.     // 必应已忽略 site: 运算符:一条站内结果都没有时给出提示,并附一键转百度
  409.     let tipBox = null;
  410.     function bingTip() {
  411.       if (!isBing) return;
  412.       if (hitCount > 0) { if (tipBox) { tipBox.remove(); tipBox = null; } return; }
  413.       if (tipBox) return;
  414.       let q = "";
  415.       try { q = decodeURIComponent((location.search.match(/[?&]q=([^&]*)/) || [])[1] || ""); } catch (e) { q = ""; }
  416.       if (!/site:|domain:/i.test(q)) return;
  417.       const kw = q.replace(/(site|domain):[^ ]+/gi, "").trim();
  418.       const url = ENGINES.baidu.url + encodeURIComponent('site:' + SITE + (kw ? ' ' + kw : ''));
  419.       tipBox = document.createElement("div");
  420.       tipBox.id = "wys-bingtip";
  421.       tipBox.innerHTML = "必应已忽略 <b>site:</b> / <b>domain:</b> 运算符,下面这些结果没限定在无忧站内。" +
  422.         "<a href="" + url + "" target="_blank" rel="noopener">改用百度搜「" + kw.replace(/&/g, "&amp;").replace(/</g, "&lt;") + "」</a>";
  423.       document.body.appendChild(tipBox);
  424.     }

  425.     function updateBtn() {
  426.       if (!hitCount) { btn.style.display = 'none'; return; }
  427.       btn.style.display = 'block';
  428.       btn.dataset.on = onlyOn ? '1' : '0';
  429.       btn.textContent = onlyOn ? '显示全部结果' : '只看无忧站内(' + hitCount + '条)';
  430.     }

  431.     function boot() {
  432.       if (!document.body) { setTimeout(boot, 300); return; }
  433.       document.body.appendChild(btn);
  434.       scan();
  435.       // 结果是异步/分页加载的,监听变化后重扫
  436.       let t = null;
  437.       const mo = new MutationObserver(function () {
  438.         clearTimeout(t);
  439.         t = setTimeout(scan, 600);
  440.       });
  441.       mo.observe(observerTarget(), { childList: true, subtree: true });
  442.     }

  443.     boot();
  444.   }

  445. })();
复制代码


保存为A.JS 然后用油猴导入或者直接拉到油猴扩展界面自动安装。安装后在论坛右上角有个“搜”字就是扩展了。必应失效了。优先采用百度。

想调整的话
用 Tampermonkey 编辑器打开这个脚本,顶部有一块配置:
const DEFAULT_ENGINE = 'baidu';           // baidu | google | so360 | bing(默认百度:必应已忽略 site:)
  const HIST_MAX = 10;                      // 搜索历史条数
发表于 3 天前 | 显示全部楼层
太牛了升级要8000积分啊
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
论坛大佬太多了
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
谢谢分享
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢分享
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
楼主大牛人啊,下载试用了
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
哈哈哈哈哈,管理员估计也没想到,提高了搜索的门槛后,竟然百花齐放百舸争流涌现出各种搜索来

点评

我以前没有搜索权限的时候 就是用bing搜  详情 回复 发表于 1 小时前 回复
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
楼主大牛人啊
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
啥也不说了,楼主就是给力!
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
可以试试
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
太牛了,给力
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
谢谢分享,这个应该很多坛友都需要
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
啥也不说了,楼主就是给力!
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
很有趣 试用下
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
牛人,棒棒哒
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢大哥的无私分享!
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
思路和办法都是相当的强,试试看看使用效果
回复

使用道具 举报

发表于 3 天前 来自手机 | 显示全部楼层
多谢分享
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
谢谢分享
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
厉害啊百花齐放
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
这个必须支持
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢分享!
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
好用, 谢谢分享.
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
百花齐放!感谢分享。
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
谢谢大佬牛逼
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢大佬。我是搞不懂,为什么无忧不能用自带的搜索框,之前可以的,怎么现在不能用了呢?

点评

https://bbs.wuyou.net/forum.php?mod=viewthread&tid=454675  详情 回复 发表于 前天 07:08 回复
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
提高了搜索的门槛后,竟然百花齐放百舸争流涌现出各种搜索来
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
谢谢分享
回复

使用道具 举报

发表于 前天 00:09 | 显示全部楼层
谢谢分享,安装使用了
回复

使用道具 举报

发表于 前天 00:34 | 显示全部楼层
感谢楼主分享,试试看!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|捐助支持|无忧启动 ( 闽ICP备05002490号-1|闽公网安备35020302032614号 )

GMT+8, 2026-11-21 10:25

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表