Jump to content

User:Voice of All/Google/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Aaron Schulz (talk | contribs) at 02:52, 26 August 2006 (//<pre><nowiki>). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
//<pre><nowiki>
//Helper tools

//Google/Google Scholar search
function googlesrch(type)
{
var undefined;
var rest = '';
var target = document.title.split(" - ")[0];
  if (target.split("Talk:")[1] != undefined)
  {
  target = target.split("Talk:")[1];
  }
  if (target.split("Main Page")[1] != undefined)
  {
  target = 'Wikipedia';
  }
//for disambigged stuff
if (target.split(")")[1] == '')
{
  if (target.split(" (")[1] != undefined)
  {
  rest = target.split(" (")[1].split(")")[0];
  target = target.split(" (")[0];
  }
}
target = target.replace('&','%26').replace('&','%26').replace('+','%2B').replace('+','%2B');
if (type == 'regular')
  {
  srch_window = window.open('http://www.google.com/search?hl=en&lr=&safe=on&q=%22' + target + '%22+' + rest + '&btnG=Search',
              'Googlesearch' + target,
              'status,toolbar,location,menubar,directories,resizeable,scrollbars,fullscreen=yes');
  }
else if (type == 'scholar')
  {
  var keyword = prompt('Enter extra keywords:');
  srch_window = window.open('http://scholar.google.com/scholar?q=%22' + target + '%22+' + keyword + '&btnG=Search',
              'Scholarsearch' + target,
              'status,toolbar,location,menubar,directories,resizeable,scrollbars,fullscreen=yes');
  }
}
/////////////////////

/////////////////////Google search tabs/////////////////////
addOnloadHook(googletab)
function googletab()
{
var undefined;
if(document.getElementById('ca-nstab-main'))
  {
  if (document.title.indexOf('Editing ') == -1)
    {
      if (location.href.search('\\&action=') == -1)
        {
     //addTab("javascript:googlesrch('scholar')", "sch", "ca-googler", "Google Scholar search", "");
     addTab("javascript:googlesrch('regular')", "find", "ca-google2", "Google search", "");
        }
    } 
  }
}
/////////////////////

/////////////////////Reference divs/////////////////////
addOnloadHook(Ref_showhide_div)
function Ref_showhide_div()
{
var ols = document.getElementsByTagName('ol');
if (!ols[0]){return;}
var references = false;
for (var i=0; i<ols.length; i++)
   {
   if (ols[i].className == 'references')
   {references = ols[i]; break;}
   }
if (!references){return;}
//from commons; make this really high or 0 depending...
if (location.href.search(/&printable=yes/) != -1)
  {NavigationBarShowDefault = 0;}
else
  {NavigationBarShowDefault = 100;}
//
var hidea = '<div id="referencelist" class="NavFrame" style="border-style: none; text-align: left; background: #ccddcc; padding: 0px;"><div class="NavHead"  style="border-style: none; background: #ccddcc; text-align: left; padding: 2px; font-size: 120%;">' + '\n';
var hideb = '\n' + '</div><div class="NavContent" style="background: #FFFFCC; font-size: 110%; display: block; ">';
var hidec = '<br>' + '</div></div>';
//
var number = references.getElementsByTagName('li').length;
references.innerHTML = hidea + 'There are ' + number + ' citations (labelled with corresponding numbers) used on this page:' + hideb + references.innerHTML + hidec;
}
/////////////////////

////////////////////////Reference (cite.php) Toggling////////////////////////
addOnloadHook(toggle_refs_add)
function toggle_refs_add()
{
if (document.title.indexOf('Editing ') == 0 && document.title.search('(Image:|Template:| talk:|Category:|Portal:|Wikipedia:|MediaWiki:|Help:|Talk:|User:|View and restore deleted pages)') == -1)
  {addToolboxLink("javascript:toggle_refs()","Toggle references","toggle-ref");}
}

function zreplace_refs()
{
  z_auto_ref_countup += 1;
  var string = '<<REF:' + z_auto_ref_countup + '>>';
  return string;
}

function zreturn_refs(match,number)
{
  if (ref_return_js_cache[number-1] != undefined)
  {var string = ref_return_js_cache[number-1];}
  else 
  {alert('Error parsing reference #' + number + '.'); var string = match;}
  return string;
}

function toggle_refs()
{
  var message = '<br><strong>References abbreviated - (PRESS "TOGGLE REFERENCES" AGAIN TO BE ABLE SAVE/PREVIEW THE PAGE)</strong>';
  if (document.editform.wpTextbox1.value.indexOf('<<REF:') == -1 && document.editform.wpTextbox1.value.search(/<ref[> ]/) != -1)
  {
  txt = document.editform.wpTextbox1.value;
  ref_return_js_cache = txt.match(/<ref[> ].+<\/ref>/g);
  z_auto_ref_countup = 0;
  document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(/<ref[> ].+<\/ref>/g,zreplace_refs);
  document.getElementById('contentSub').innerHTML += message;
  lock_input();
  }
  else if (document.editform.wpTextbox1.value.indexOf('<<REF:') != -1)
  {
  if (document.getElementById('wpSummary') == undefined)
  {unlock_input();}
  document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(/<<REF:(\d+)>>/g,zreturn_refs);
  document.getElementById('contentSub').innerHTML = document.getElementById('contentSub').innerHTML.replace(message,'');
  }
  else if (document.getElementById('wpSummary'))
  {
  document.getElementById('contentSub').innerHTML += message;
  lock_input();
  }
  else
  {
  document.getElementById('contentSub').innerHTML = document.getElementById('contentSub').innerHTML.replace(message,'');
  unlock_input();
  }
}
//END

function lock_input()
{
var divs = document.getElementById('bodyContent').getElementsByTagName('div');
input_help_js_return_cache = document.getElementById('wpSummaryLabel').innerHTML;
document.getElementById('wpSummaryLabel').innerHTML = '';
for (i=0; i <divs.length; i++)
   {
   if (divs[i].className == 'editOptions')
     {input_form_js_return_cache = divs[i].innerHTML; divs[i].innerHTML = '';}
   }
}

function unlock_input()
{
var page = document.title.replace('Editing ','').replace('Edit Conflict','').replace('Edit conflict','').split(' - ')[0];
var divs = document.getElementById('bodyContent').getElementsByTagName('div');
for (i=0; i <divs.length; i++)
   {
   if (divs[i].className == 'editOptions')
   {divs[i].innerHTML = input_form_js_return_cache;}
   }
document.getElementById('wpSummaryLabel').innerHTML = input_help_js_return_cache;
}
////////////////////////


////////////////////////////////////////
//spelling corrections                //
////////////////////////////////////////
function js_misspell_check()
{
if (!window.ActiveXObject)
  {
try {netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); } 
catch (e) {alert("Permission UniversalBrowserRead denied."); } 
  }
gml_xmlhttp = false;
gml_xmlhttp = new XMLHttpRequest(); 
if (gml_xmlhttp.overrideMimeType) 
{gml_xmlhttp.overrideMimeType('text/xml'); }
if (!gml_xmlhttp)
{alert('Cannot create XMLHTTP instance'); return false; } 
  document.getElementById('contentSub').innerHTML += '<br><strong>Performing spelling corrections for common mistakes. This may take a while for large pages.</strong>';
  gml_xmlhttp = HTTPClient();
  var URL = 'http://en.wikipedia.org/w/index.php?title=Wikipedia:Lists_of_common_misspellings/For_machines&action=edit';
  if (!gml_xmlhttp)
  {return;}
  gml_xmlhttp.open("GET", URL, true);
  gml_xmlhttp.onreadystatechange = spellcheck;
  gml_xmlhttp.send(null);
}

function searchtxt()
{
var string = document.editform.wpTextbox1.value;
var input = prompt('Search for what?');
alert('Found ' + string.match(input + '(,|\.| )'));
}

function spellcheck()
{
if (!gml_xmlhttp){return;}
if (gml_xmlhttp.readyState != 4)
{return;}
var xml = gml_xmlhttp.responseText;
//txt_spell = gml_XMLParse(xml);
txt_spell = xml.split('<textarea ')[1].split('</textarea>')[0];
txt_spell = txt_spell.replace(/&gt;/g,'>');
//alert(txt_spell);
//txt_spell = txt_spell.getElementsByTagName('textarea')[0].value
var txtsplit = txt_spell.match(/ \w+->\w+\n/g);
var spellregexp = '';
for (var i=0; i < txtsplit.length; i++)
   {
   if (i < txtsplit.length - 1)
     {spellregexp += txtsplit[i].split('->')[0].split(' ')[1] + '|';}
   else
     {spellregexp += txtsplit[i].split('->')[0].split(' ')[1];}
   }
spellregexp = RegExp('([ \.,:;])(' + spellregexp + ')([ \.,:;])','gi');
if (document.editform.wpSummary)
  {document.editform.wpSummary.value = '';}
sp_errors = 0;
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(spellregexp,errorfound);
if (sp_errors == 0)
  {
alert('Spelling corrections finished. No common spelling errors were found.');
  }
else if (sp_errors == 1)
  {
if (document.editform.wpSummary)
  {document.editform.wpSummary.value = 'Spelling: ' + document.editform.wpSummary.value;}
alert('Spelling corrections finished. 1 correction made.');
  }
else
  {
  if (document.editform.wpSummary)
    {document.editform.wpSummary.value = 'Spelling: ' + document.editform.wpSummary.value;}
  alert('Spelling corrections finished. ' + sp_errors + ' corrections made.');
  }
  if (sp_errors> 0) 
         {
        form = document.getElementById('bodyContent');
        l = form.getElementsByTagName('input');
        for (i = 0 ; i < l.length; i++)
               {
           if (l[i].name == 'wpMinoredit')
           {l[i].value = '1'; l[i].checked=true;}
               }
        document.getElementById('wpDiff').click();
         }
}

function errorfound(match,punc1,badword,punc2)
{
var find = txt_spell.split(' ' + badword + '->')[1];
if (find != undefined)
  {
  var goodword = find.split('\n')[0].split(' ')[0];
  sp_errors += 1;
  alert('Replaced "' + badword + '" with "' + goodword + '".');
  if (document.editform.wpSummary)
    {document.editform.wpSummary.value += badword + '->' + goodword + ' ; ';}
  var spell_find = punc1 + goodword + punc2;
  return spell_find;
  }
return match;
}

addOnloadHook(addspelltab)
function addspelltab()
{
if (document.title.indexOf("Editing ") != -1)
  {
  addToolboxLink("javascript:js_misspell_check()","JS spell checker","txt-spell");
  //addtoolbox_link("javascript:js_misspell_check()","JS spell checker","txt-spell");
  }
}
//END
//</nowiki></pre>