跳去內容

MediaWiki:Gadget-externalsearch.js

出自維基百科,自由嘅百科全書

注意:儲存之後,你可能要兜過你嘅瀏覽器快取至睇到更改。Internet Explorer: 撳住Ctrl掣再撳重新整理掣。 Firefox: 撳住Shift掣再撳重新載入(又或者撳Ctrl-Shift-R)。 Google Chrome同埋Safari用戶就噉撳個重載掣。

/** Change Special:Search to use a drop-down menu *******************************************************
  *
  *  Description: Change Special:Search to use a drop-down menu, with the default being
  *               the internal MediaWiki engine
  *  Created and maintained by: [[User:Gracenotes]]
  */

function SpecialSearchEnhanced() {
    var createOption = function(site, action, mainQ, addQ, addV) {
        var opt = document.createElement('option');
        opt.appendChild(document.createTextNode(site));
        window.searchEngines.push([action, mainQ, addQ, addV]);
        return opt;
    }

    if (document.forms.powersearch)
        var searchForm = document.forms.powersearch;
    if (document.forms.search)
        var searchForm = document.forms.search;

    if (searchForm.lsearchbox) {
        var searchBox = searchForm.lsearchbox;
    } else {
        var searchBox = searchForm.search;
    }
    var selectBox = document.createElement('select');
    selectBox.id = 'searchEngine';
    searchForm.onsubmit = function() {
        var optSelected = window.searchEngines[document.getElementById('searchEngine').selectedIndex];
        searchForm.action = optSelected[0];
        searchBox.name = optSelected[1];
        searchForm.title.value = optSelected[3];
        searchForm.title.name = optSelected[2];
    }
    selectBox.appendChild(createOption('粵文維基百科', mw.config.get( 'wgScript' ), 'search', 'title', 'Special:Search'));
    selectBox.appendChild(createOption('Google', 'http://www.google.com/search', 'q', 'sitesearch', 'zh-yue.wikipedia.org'));
    selectBox.appendChild(createOption('Yahoo', 'http://hk.search.yahoo.com/search', 'p', 'vs', 'zh-yue.wikipedia.org'));
    selectBox.appendChild(createOption('Bing', 'http://www.bing.com/search', 'q', 'q1', 'site:http://zh-yue.wikipedia.org'));
    selectBox.appendChild(createOption('Wikiwix', 'http://www.wikiwix.com/', 'action', 'lang', 'zh-yue'));
    selectBox.appendChild(createOption('中文系維基百科 Google Co-op', 'http://www.google.com/cse', 'q', 'cx', '009212467671870524522:mw9ug06rtl4'));
    searchBox.style.marginLeft = '0px';
    if (document.getElementById('loadStatus')) {
        var lStat = document.getElementById('loadStatus');
    } else {
        var lStat = searchForm.title;
        if( typeof lStat === 'object'  && typeof lStat.length === 'number' ) lStat = lStat[0];
    }
    lStat.parentNode.insertBefore(selectBox, lStat);
}

window.searchEngines = [];

// Script is specific to Special:Search
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search'){
  $(SpecialSearchEnhanced);
}