Jump to content

User:Robbiemuffin/common.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 urlencode (str) {  
    str = (str + '').toString();   
      
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').  
    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');  
}  

var jQueryScriptOutputted = false;
function initJQuery() {    
  //if the jQuery object isn't available
  if (typeof(jQuery) == 'undefined') {
    
    if (! jQueryScriptOutputted) {
      //only output the script once..
      jQueryScriptOutputted = true;
            
      //output the script (load it from google api)
      document.write("<scr" + "ipt type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></scr" + "ipt>");
    }
      setTimeout("initJQuery()", 50);
    } else {
      $(function() {  
        //do anything that needs to be done on document.ready
        target=urlencode($("#firstHeading span").text());
        $("#firstHeading").append("<img src=\"http://i.imgur.com/jpFfs.jpg\" style=\"margin-left:1em; cursor:pointer\" onClick=\"window.open('http://www.freebase.com/search?opensearch=1&query=" + target + "','_newtab');\" />");
      });
    }            
}
initJQuery();