MyWiki:WikiProject User scripts/Scripts/Google link

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by imported>SD0001 at 14:37, 17 September 2025 (addPortletLink -> mw.util.addPortletLink). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
// This script adds "Google search" and "Yahoo! search" links to the toolbox. <syntaxhighlight lang="javascript">

$.when($.ready, mw.loader.using('mediawiki.util')).then(function () {
    if (mw.config.get('wgCanonicalNamespace') == "Special")
        return;  // no links for special pages

    var title = mw.config.get('wgTitle');
    if (mw.config.get('wgCanonicalNamespace') != "")
        title = title.replace(/^.*\//, "");  // subpage name only

    var query = encodeURIComponent('"'+title+'" -Wikipedia' ); 
    mw.util.addPortletLink('p-tb', 'http://www.google.com/search?ie=utf-8&oe=utf-8&q='+query,
                   'Google search', 't-googlesearch', 'Search Google for "'+title+'"', 'G');
    mw.util.addPortletLink('p-tb', 'http://search.yahoo.com/search?ei=UTF-8&p='+query,
                   'Yahoo! search', 't-yahoosearch', 'Search Yahoo! for "'+title+'"', 'Y');
});

// </syntaxhighlight>