打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

搜索

来自Googology Wiki

<!-- 自定义全库条件搜索框 --> <div id="custom-wiki-search" style="max-width: 800px; margin: 2rem auto; padding: 1rem; border: 1px solid #ddd; border-radius: 8px;"> <h3>维基全站条件搜索</h3> <form id="wiki-search-form" onsubmit="return doWikiSearch()"> <div style="margin: 1rem 0;"> <label>搜索关键词:</label> <input type="text" id="search-keyword" placeholder="输入要匹配的内容..." required style="width: 70%; padding: 0.5rem; margin-left: 0.5rem;"> </div> <div style="margin: 1rem 0;"> <label>限定命名空间:</label> <select id="search-namespace" style="padding: 0.5rem; margin-left: 0.5rem;"> <option value="0">主命名空间(文章)</option> <option value="14">分类</option> <option value="10">模板</option> <option value="-1">所有命名空间</option> </select> </div> <button type="submit" style="padding: 0.5rem 2rem; background: # 0645ad; color: white; border: none; border-radius: 4px; cursor: pointer;">开始搜索</button> </form> <!-- 搜索结果展示区 --> <div id="search-results" style="margin-top: 2rem;"> <ul id="results-list" style="list-style: none; padding: 0;"></ul> </div> </div> <script> function doWikiSearch() { // 获取搜索参数 const keyword = document.getElementById('search-keyword').value.trim(); const namespace = document.getElementById('search-namespace').value; const resultsList = document.getElementById('results-list'); resultsList.innerHTML = '<li>正在搜索中,请稍候...</li>'; // 调用MediaWiki原生API const apiUrl = mw.config.get('wgScriptPath') + '/api.php'; const params = new URLSearchParams({ action: 'query', list: 'search', srsearch: keyword, srnamespace: namespace, srlimit: 50, // 最多返回50条结果,可自行修改 format: 'json' }); fetch(`${apiUrl}?${params.toString()}`) .then(response => response.json()) .then(data => { resultsList.innerHTML = ''; const results = data.query.search; if (results.length === 0) { resultsList.innerHTML = '<li>未找到符合条件的页面</li>'; return; } // 渲染搜索结果 results.forEach(page => { const li = document.createElement('li'); li.style = 'margin: 0.8rem 0; padding-bottom: 0.8rem; border-bottom: 1px solid #eee;'; li.innerHTML = ` <a href="${mw.config.get('wgArticlePath').replace('$1', encodeURIComponent(page.title))}" target="_blank"> <strong>${page.title}</strong> </a> <p style="margin: 0.3rem 0 0 0; color: # 0666; font-size: 0.9em;">${page.snippet}...</p> `; resultsList.appendChild(li); }); }) .catch(error => { resultsList.innerHTML = `<li>搜索出错:${error.message}</li>`; }); return false; // 阻止表单默认跳转 } </script>