Poznámka: Po uložení musíte vyprázdnit mezipaměť vašeho prohlížeče, jinak změny neuvidíte.

// <nowiki><pre>

// nastavení shrnutí editace
function setWpSummary(str) {
	var eSummary = document.getElementById('wpSummary');
	if (eSummary != null) eSummary.value = str;
}

// najít element s nadpisem stránky
function findFirstHeading() {
	var eContent = document.getElementById('content');
	if (eContent == null) return null;
	var elems = eContent.getElementsByTagName("h1");
	if (elems.length == 0) return null;
	return elems[0];
}

// zjistit nadpis stránky
function getPagetitle() {
	var eHeading = findFirstHeading();
	if (eHeading == null) return "";
	var title = eHeading.innerHTML;
	// TODO: vyřešit stránky, kde se nečte článek (editace, přesouvání, …)
	return title;
}

// nastavit nadpis stránky
function setPagetitle(title) {
	var eHeading = findFirstHeading();
	if (eHeading == null) return;
	// TODO: vyřešit stránky, kde se nečte článek (editace, přesouvání, …)
	eHeading.innerHTML = title;
}

// získat (enkódované) lokální URL nějaké stránky (obdoba localurl:)
function getLocalURL(text) {
	text = text.substring(0, 1).toUpperCase() + text.substring(1);
	return "/wiki/" + encodeURIComponent(text.replace(/ /g,"_")).replace(/%2f/gi,"/");
}

// Appends a new tab.
// Převzato z [[commons:MediaWiki:Extra-tabs.js]].
function appendTab(url, name) {
  var na = document.createElement('a');
  na.setAttribute('href', url);

  var txt = document.createTextNode(name);
  na.appendChild(txt);

  var li = document.createElement('li');
  li.appendChild(na);

  // Grab the element we want to append the tab and append the tab to it.
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
  tabs.appendChild(li);
}

// Gets the article lemma, with the namespace and with sub pages.
// Převzato z [[commons:MediaWiki:Extra-tabs.js]].
function getPageName()
{
  // get the article link from the label 'ca-edit' out of the document text.
  var editlk = document.getElementById('ca-edit');

  // If a page is write protected (for that user, a sysop will always have 'ca-edit')
  // we need 'ca-viewsource' as 'ca-edit' does not exist there.
  if (editlk == null)
  {
    editlk = document.getElementById('ca-viewsource');
  }

  // editlk will still be null on a Special page.  Now we try the ca-article tab.
  if (editlk == null)
  {
    editlk = document.getElementById('ca-article');
  }

  editlk = editlk.getElementsByTagName('a')[0].href;

  // If we found the ca-edit or ca-viewsource tab, the link will have title=.
  // If we found the ca-article tab (on a Special page) it won't.
  if (editlk.indexOf('title=') >= 0)
  {
    // Cut everything up to "title=" from the start and everything past "&action=edit"
    // from the end.
    editlk = decodeURIComponent(editlk.substring(editlk.indexOf('title=') + 6, editlk.indexOf('&')));
  }
  else
  {
    // Cut everything up to "/wiki/" from the start.
    editlk = decodeURIComponent(editlk.substring(editlk.indexOf('/wiki/') + 6));
  }

  return editlk;
}

// najít v editboxu
function findInEditbox(needle) {
  if (needle.length == 0) {
    alert("ook?");
    return;
  }
  var eEditBox = document.getElementById("wpTextbox1");
  if (eEditBox == null) return;
  var text = eEditBox.value;
  var ofsStart = eEditBox.selectionStart + 1;
  if (ofsStart >= text.length) ofsStart = 1;
  if (ofsStart > 0) {
    text = text.substring(ofsStart, 99999999);
  } else {
    ofsStart = 0;
  }
  var result = new RegExp(needle, "i").exec(text);
  if (result == null) {
    alert("bzzzt… wrong!");
  } else {
    eEditBox.selectionStart = ofsStart + result.index;
    eEditBox.selectionEnd = ofsStart + result.index + result[0].length;
    eEditBox.focus();
  }
}

// najít a nahradit v editboxu
function replaceInEditbox(needle, replacement) {
  if (needle.length == 0) {
    alert("ook?");
    return;
  }
  var eEditBox = document.getElementById("wpTextbox1");
  if (eEditBox == null) return;
  var text = eEditBox.value;
  var ofsStart = eEditBox.selectionStart;
  if (ofsStart >= text.length) ofsStart = 0;
  if (ofsStart < 0) ofsStart = 0;
  var ofsEnd = eEditBox.selectionEnd;
  if (ofsEnd < ofsStart) ofsEnd = ofsStart;
  if (ofsEnd == ofsStart) ofsEnd = 99999999;
  var reNeedle = new RegExp(needle, "gi");
  text = text.substring(ofsStart, ofsEnd);
  if (!text.match(reNeedle)) {
    alert("bzzzt… wrong!");
  } else {
    eEditBox.value = eEditBox.value.substring(0, ofsStart) + text.replace(reNeedle, replacement) + eEditBox.value.substring(ofsEnd, 99999999);
  }
}

// editační toolbary
// příklad použití: addOnloadHook(function() { addSummaryToolbar(["typo", "interwiki", "", "pahýl", "upravit", "", "experimenty", "experimenty2"]); });
function addSummaryToolbar(items) {
	var elem = document.getElementById('editpage-copywarn');
	if (elem == null) return;
	if (document.getElementById('summarytools') != null) return;
	var addedBox = "<div id='summaryTools' class='infobox' style='float:right; text-align:center'><h5>Shrnutí editace</h5>";
	var firstOnLine = true;
	for (var i = 0; i < items.length; i++) {
		if (items[i] == "") {
			addedBox += "<br />";
			firstOnLine = true;
		} else {
			if (!firstOnLine) addedBox += " &bull; ";
			firstOnLine = false;
			addedBox += "<a href=\"javascript:setWpSummary('" + items[i] + "');\">" + items[i] + "</a>";
		}
	}
	addedBox += "</div>";
	elem.innerHTML = addedBox + elem.innerHTML;
}

// lišta s odkazy
// příklad použití: addOnloadHook(function() { addLinktoolbar("Poslední změny", [ ["Wikipedie:Žádost o práva správce", "RfA"], ["Wikipedie:Hlasování o smazání", "VfD"] ]); });
function addLinktoolbar(page, items) {
	if (page != "" && getPagetitle() != page) return;
	var elem = document.getElementById("bodyContent");
	if (elem == null) return;
	var addedToolbar = "<div id='linktoolbar' class='small'><b>Odkazy:</b> ";
	var firstOnLine = true;
	for (var i = 0; i < items.length; i++) {
		if (items[i] == "") {
			addedToolbar += "<br />";
			firstOnLine = true;
		} else {
			if (!firstOnLine) addedToolbar += " &bull; ";
			firstOnLine = false;
			addedToolbar += "<a href=\"" + getLocalURL(items[i][0]) + "\">" + items[i][1] + "</a>";
		}
	}
	addedToolbar += "</div>";
	elem.innerHTML = addedToolbar + elem.innerHTML;
}

function onFindClick(needle) {
  var elem = document.getElementById(needle);
  if (elem == null) return;
  findInEditbox(elem.value);
}

function onReplaceClick(needle, replacement) {
  var eNeedle = document.getElementById(needle);
  if (eNeedle == null) return;
  var eReplacement = document.getElementById(replacement);
  if (eReplacement == null) return;
  replaceInEditbox(eNeedle.value, eReplacement.value);
}

// toolbar pro find&replace
// použití: addOnloadHook(addFindAndReplaceToolbar);
function addFindAndReplaceToolbar() {
  // TODO: Checkboxy pro regulární výrazy a case sensitivitu
  var elem = document.getElementById('editpage-copywarn');
  if (elem == null) return;
  if (document.getElementById('findTools') != null) return;
  var addedBox = "<form id='findform' action='#'><div id='findTools' class='infobox' style='float:right; text-align:right'><label for='needle'>Najít: </label><input tabindex='8' type='text' value='' name='needle' id='needle' maxlength='200' size='20' /><br /><label for='replacement'>Nahradit za: </label><input tabindex='9' type='text' value='' name='replacement' id='replacement' maxlength='200' size='20' /><br /><center><button id='find' name='find' tabindex='10' accesskey='f' onclick='javascript:onFindClick(\"needle\");return false;'>Najít</button><button id='replace' name='replace' tabindex='11' accesskey='r' onclick='javascript:onReplaceClick(\"needle\", \"replacement\");return false;'>Nahradit</button></center></div></form>";
  elem.innerHTML = addedBox + elem.innerHTML;
}

// přidat dodatečné záložky
// použití: addOnloadHook(addAdditionalTabs);
function addAdditionalTabs() {
  var title = getPageName();
  var username = null;
  var addWhois = false, addLog = false;

  if (title.match(/^Wikipedista(_diskuse)?:/)) {
    // uživatelská stránka nebo diskuse (příp. podstránka)
    username = title;
    addWhois = true;
    addLog = true;
  } else if (title.indexOf('Speciální:Contributions') == 0) {
    // příspěvky uživatele
    username = document.getElementById('contentSub').getElementsByTagName('a')[0].getAttribute('title');
    addWhois = true;
  } else if (title.indexOf('Speciální:') != 0) {
    // normální, nespeciální stránka
    if (!document.getElementById('ca-history') || !document.getElementById('ca-edit')) {
      // neexistující nebo zamčená stránka – přidat odkaz na log
      appendTab('/w/index.php?title=Speci%C3%A1ln%C3%AD:Log&page=' + title, "Log");
    }
    return;
  } else return;

  username = username.substring(username.indexOf(':') + 1);
  username = username.replace(/\/.*$/, '');

  if (addLog) appendTab('/w/index.php?title=Speci%C3%A1ln%C3%AD:Log&page=Wikipedista:' + username, "Log");

  if (username.match(/([0-9]{1,3}\.){3}[0-9]{1,3}/)) {
    // anonymní uživatel
    if (addWhois) appendTab("http://whois.smartweb.cz/object/" + username + "/", "Whois");
  }
}

function removeAccessKeysRecursive(root)
{
	if (!root) return;
	if (typeof(root.removeAttribute) == "function") {
		root.removeAttribute("accesskey");
	}
	for (var child in root.childNodes)
	{
		removeAccessKeysRecursive(root.childNodes[child]);
	}
}

// Odstranit klávesové zkratky u některých či všech prvků Wikipedie
// Použití: addOnloadHook(function() { removeAccessKeys(['pt-userpage', ['n-randompage']); }); pro konkrétní prvky
// případně addOnloadHook(function() { removeAccessKeys(null); }); pro všechny prvky
function removeAccessKeys(remlist)
{
	if (!remlist) {
		remlist = new Array();
		for (var id in ta)
		{
			remlist.push(id);
		}
		remlist.push('searchInput');
		remlist.push('wpSaveprefs');
		remlist.push('historysubmit');
		remlist.push('pagehistory');
		remlist.push('wpMinoredit');
		remlist.push('wpWatchthis');
		remlist.push('wpSave');
		remlist.push('wpDiff');
		remlist.push('wpLivePreview');
		remlist.push('wpPreview');
		remlist.push('wpTextbox1');
	}
	for (var idx in remlist) {
		var id = remlist[idx];
		var n = document.getElementById(id);
		if (n) {
			var a;
			var elname = n.nodeName.toLowerCase();
			if (elname == "a" || elname == "input") {
				a = n;
			} else {
				a = n.childNodes[0];
			}
			if (a && typeof(a.removeAttribute) == "function") {
				a.removeAttribute("accesskey");
			}
		}
	}
}

// na stránce Speciální:Upload zobrazit odkaz na aktuální verzi (zejména užitečné při červených odkazech na smazaný soubor)
// použití: addOnloadHook(function() { imageReuploadLink(); });
function imageReuploadLink() {
	if (getPageName() != "Speciální:Upload") return;

	var editDest = document.getElementById('wpDestFile');
	if (!editDest) return;

	var link = document.createElement('a');
	link.setAttribute('id', 'uploadoriglink');
	link.setAttribute('href', editDest.value ? getLocalURL('Soubor:' + editDest.value) : '#');
	editDest.parentNode.appendChild(link);

	var linkText = document.createTextNode('(aktuální verze)');
	link.appendChild(linkText);

	editDest.onchange = function() {
		var editDest = document.getElementById('wpDestFile');
		if (!editDest) return;

		var link = document.getElementById('uploadoriglink');
		if (!link) return;

		link.setAttribute('href', editDest.value ? getLocalURL('Soubor:' + editDest.value) : '#');
	}
}

// </pre></nowiki>