Thành viên:Nguyễn Thanh Quang/Google/monobook.js

Chú ý: Sau khi lưu thay đổi trang, bạn phải xóa bộ nhớ đệm của trình duyệt để nhìn thấy các thay đổi. Google Chrome, Firefox, Internet ExplorerSafari: Giữ phím ⇧ Shift và nhấn nút Reload/Tải lại trên thanh công cụ của trình duyệt. Để biết chi tiết và hướng dẫn cho các trình duyệt khác, xem Trợ giúp:Xóa bộ nhớ đệm.

//<pre><nowiki>

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

//Google/Google Scholar search
function googlesrch(type)
{
var rest = '';
var target = wgTitle;
//for disambigged stuff
if (target.indexOf("(") !=-1 && target.indexOf(")") !=-1)
{
  rest = target.split(" (")[1].split(")")[0];
  target = target.split(" (")[0];
}
if (type == 'regular')
  {
  srch_window = window.open('http://www.google.com/search?hl=en&lr=&safe=on&q=%22' + escape(target) + '%22+' + escape(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' + escape(target) + '%22+' + escape(keyword) + '&btnG=Search',
              'Scholarsearch' + target,
              'status,toolbar,location,menubar,directories,resizeable,scrollbars,fullscreen=yes');
  }
}
/////////////////////

/////////////////////Reference divs/////////////////////
$(Ref_navbar_div)
function Ref_navbar_div()
{
var references = false;
var ref_div = false;
//get references
var ols = document.getElementsByTagName('ol');
if (!ols[0]){return;}
for (var i=0; i<ols.length; i++)
   {
   if (ols[i].className == 'references')
   {references = ols[i]; break;}
   }
if (!references){return;}
var l = references.getElementsByTagName('li');
//only do this for long lists
if (l.length < 15){return;}
//renumber refs
for (var i=0; i<l.length; i++)
   {
   var num = i+1;
   l[i].innerHTML = '<strong>' + num + '.</strong> ' + l[i].innerHTML;
   }
references.innerHTML = references.innerHTML;
var divs = document.getElementsByTagName('div');
if (!divs[0]){return;}
for (var i=0; i<divs.length; i++)
   {
   if (divs[i].className == 'references-small')
   {ref_div = divs[i]; break;}
   }
//scrollbars
references.setAttribute("style", "width:95%; height:400px; overflow: scroll;");
//removed any columns
if (ref_div){ref_div.setAttribute("style", "");}
}
/////////////////////

////////////////////////Reference (cite.php) Toggling////////////////////////
$(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()
{
  if (document.editform.wpTextbox1.value.indexOf('<<REF:') == -1 && document.editform.wpTextbox1.value.search(/<[Rr]ef[> ]/) != -1)
  {
  txt = document.editform.wpTextbox1.value;
  ref_return_js_cache = txt.match(/<[Rr]ef[> ].+<\/[Rr]ef>/gm);
  z_auto_ref_countup = 0;
  document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace(/<[Rr]ef[> ].+<\/[Rr]ef>/gm,zreplace_refs);
  if (edit_input) {lock_input();}
  else {unlock_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+)>>/gm,zreturn_refs);
  }
  else if (document.getElementById('wpSummary'))
  {lock_input();}
  else
  {unlock_input();}
}

//
var input_locked_message='<br><strong>References abbreviated - (PRESS "TOGGLE REFERENCES" AGAIN TO BE ABLE SAVE/PREVIEW THE PAGE)</strong>';
var edit_input=true;
function lock_input()
{
edit_input=false;
document.getElementById('contentSub').innerHTML += input_locked_message;
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()
{
document.getElementById('contentSub').innerHTML = document.getElementById('contentSub').innerHTML.replace(input_locked_message,'');
edit_input=true;
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."); } 
  }
xmlhttp = false;
xmlhttp = new XMLHttpRequest(); 
if (xmlhttp.overrideMimeType) 
{xmlhttp.overrideMimeType('text/xml'); }
if (!xmlhttp)
{alert('Cannot create XMLHTTP instance'); return false; } 
  alert('Performing spelling corrections for common mistakes.' + '\n' + 'This may take longer for large pages.');
  xmlhttp = HTTPClient();
  var URL = 'http://en.wikipedia.org/w/index.php?title=Wikipedia:Lists_of_common_misspellings/For_machines&action=edit';
  if (!xmlhttp)
  {return;}
  xmlhttp.open("GET", URL, true);
  xmlhttp.onreadystatechange = spellcheck;
  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 (!xmlhttp){return;}
if (xmlhttp.readyState != 4) return;
var xml = xmlhttp.responseText;
txt_spell = xml.split('<textarea ')[1].split('</textarea>')[0];
txt_spell = txt_spell.replace(/&gt;/g,'>');
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) 
         {
        document.editform.wpMinoredit.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;
}

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