Jump to content

User:HueSatLum/googleTitle.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$(function(){
  if([0, 1].indexOf(mw.config.get('wgNamespaceNumber')) > -1){
    importStylesheet('User:HueSatLum/googleTitle.css');
    var title = mw.config.get('wgTitle'),
        searchTitle = title.toLowerCase().replace(/\((.+?)\)$/, '$1'),
        searchURL = 'https://www.google.com/search?q=-site:wikipedia.org%20' + encodeURIComponent(searchTitle),
        linkElem = $('<a>', {
                              'class': 'external',
                              'href': searchURL,
                              'id': 'googleTitle',
                              'target': '_blank',
                              'text': 'G',
                              'title': 'Search Google for the article title'
                            });
    $('#firstHeading').prepend(linkElem, '\n');
  }
});