User:Nið ricsað/monobook.js

var autoTranslitScripts = { "Geor": true };

window.makedefsidebox = function(q) { function clickiconfunction { var moreoptions, originalHeight, buttons;

function uncollapse { $(moreoptions).slideUp; $("body").off("click", uncollapse); }		editdefinition(q); if ($('>.addusexbutton', q).length === 0) { buttons = q.insertBefore(newNode('div', { 'class': 'addusexbutton' }, newNode('a', '+Add example sentence', {				'click': function {					setupusexadder(q);				}			}), newNode('a', '+Add quotation', {				'click': function {					setupquoteadder(q);				}			}), newNode('a', 'More ►', {				'click': function {					$(moreoptions).slideDown;					setTimeout(function { $("body").click(uncollapse); }, 16);				}			}), newNode('span', {				'style': 'display:inline-block;'			}, moreoptions = newNode('ul', newNode('li', q.className ? newNode('a', 'Edit gloss', { 'click': function { editgloss(q); }			}) : newNode('a', 'Add gloss', { 'click': function { addgloss(q); }			})), newNode('li', newNode('a', q.className ? undefined : { 'class': 'DSBinactive', 'title': 'Please add a gloss before adding synonyms.' }, {				'click': function { setupnymadder(q, "Synonyms"); }			}, 'Add synonyms')), newNode('li', newNode('a', q.className ? undefined : { 'class': 'DSBinactive', 'title': 'Please add a gloss before adding antonyms.' }, {				'click': function { setupnymadder(q, "Antonyms"); }			}, 'Add antonyms')), newNode('li', newNode('a', { 'href': mw.config.get('wgScript') + '?title=User_talk:Yair_rand/editor2.js&action=edit&section=new' }, 'Give feedback on this tool')), newNode('li', newNode('a', { click: function { $.cookie("DisableYREdit", 1, {						path: '/'					}); location.href = location.href; }			}, 'Disable this tool'))))), $('>dl,>ul,>ol', q)[0] || null); }	}	q.insertBefore(		newNode('span', { 'class': 'defEditButton' }, newNode('span', {			'click': clickiconfunction,			'title': 'Edit'		})), q.firstChild); return clickiconfunction; }

function setupusexadder(qq) { var x, y;	var usexform; var findsubdef = (qq.parentNode.parentNode.nodeName.toLowerCase == "li" ? "#" : "") + (qq.parentNode.parentNode.parentNode.parentNode.nodeName.toLowerCase == "li" ? "#" : "") editor = new Editor findlang(qq.parentNode, function(findlang_) {		var findscript = (new LangMetadata).getScripts(findlang_),			selectedscript = findscript[0] || "Latn";		if (qq.getElementsByTagName('dl')[0] && qq.getElementsByTagName('dl')[0].parentNode == qq) x = qq.getElementsByTagName('dl')[0];		else if ($(">ul", qq).length > 0) x = qq.insertBefore(newNode('dl'), $(">ul", qq)[0]);		else x = qq.appendChild(newNode('dl'));

x.appendChild(y = newNode('dd'))

new AdderWrapper(new Editor, {			'createForm': function {				var x, i = 0,					y = function {						selectedscript = this.value;						usexform.getElementsByTagName('dd')[0].style.display = this.value == 'Latn' ? 'none' : 'block'					}				if (findscript.length > 1) {					for (x = newNode('select', {							'name': 'script',							'change': y						}); i < findscript.length; i++) {						x.appendChild(newNode('option', {							'value': findscript[i]						}, findscript[i]))					}				} else {					x = newNode('input', { 'name': 'script', 'value': findscript[0] || "Latn", 'style': "width:50px;", 'change': y					})				}				return usexform = newNode('form', { 'style': 'display:inline;' }, newNode('input', {					'size': 100,					'placeholder': 'Example sentence',					'name': 'examplesentence'				}), newNode('span', {					'style': 'display:' + (findscript.length == 1 ? "none" : "inline") + ";"				}, 'Script: ', x), newNode('div', {					'class': "DSBRedButton",					'click': function {						usexform.style.display = 'none'					}				}, newNode('div', 'Cancel')), newNode('div', {					'class': "DSBGreenButton",					'click': function {						usexform.onsubmit					}				}, newNode('div', "Preview ►")), newNode('input', {					'type': 'submit',					'style': 'visibility:hidden;width:0px;'				}), newNode('dl', (findlang_ == "en" ? {					'style': 'display:none;' } : ), newNode('dd', 'Transliteration: ', ((findscript[0] == 'Latn' || !findscript[0]) ? {					'style': 'display:none;'				} : ), newNode('input', {					'size': '100px',					name: 'transliteration'				})), newNode('dd', 'Translation: ', newNode('input', {					'size': '100px',					name: 'translation'				}))))			},			'fields': {				'examplesentence': function(txt, error) {					return util.validateNoWikisyntax('example sentence', true)(txt, error)				},				'transliteration': function(txt, error) {					return txt || ;				},				'translation': function(txt, error) {					if (findlang_ != "en") {						return util.validateNoWikisyntax('translation', true)(txt, error);					}					return ;				},				'script': util.validateNoWikisyntax('script', true)			},			'onsubmit': function(values, render) {				var renderWikitext = "";				if (findlang_ === "en")					renderWikitext = "" + values.examplesentence + ""; else { renderWikitext = "{" + "{ux|" + findlang_ + "|" + values.examplesentence + "|" + values.translation;

if (values.script) { renderWikitext += "|sc=" + values.script; if (!(values.script in autoTranslitScripts) && values.transliteration) renderWikitext += "|tr=" + values.transliteration; }					renderWikitext += "}}"; }

render(renderWikitext, function(newhtml) {

var findnumberofheaders = findnumberofheaders_(qq); var findnumberofdefs = findnumberofdefs_(qq); var usextobeadded = newNode('span') usextobeadded.innerHTML = newhtml.replace(/ |<\/p>/g, ''); editor.addEdit({						edit: function(wikitext) {

var usexWikitext = renderWikitext;

wikitext = wikitext.replace(RegExp( "(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + "[\\s\\S]*?)\n(?!#" + findsubdef + ":)|$"), "$1\n#" + findsubdef + ":" + usexWikitext + "\n"); ccc = wikitext; return wikitext; },						redo: function { usexform.parentNode.appendChild(usextobeadded); usextobeadded.style.display = 'block'; usexform.style.display = "none"; y.style.display = 'block' },						undo: function { usexform.parentNode.removeChild(usextobeadded); usexform.style.display = "inline"; },						summary: "+usex: " + values.examplesentence }, usextobeadded)

})			}		}, y)		usexform.firstChild.focus }) }

window.editdefinition = function(qq) {

(new Editor).withCurrentText(function(wikitext) {		if (qq.YREditing) {			return		}		qq.YREditing = true;		var findnumberofheaders = findnumberofheaders_(qq),			findnumberofdefs = findnumberofdefs_(qq)		var temporarydefholder = qq.insertBefore(newNode('span', {			'style': 'display:none;'		}), qq.childNodes[1].nodeName.toLowerCase != "form" ? qq.childNodes[1] : qq.childNodes[2])		while (qq.childNodes[3] && qq.childNodes[3].nodeName != "DL" && qq.childNodes[3].nodeName != "UL" && qq.childNodes[3].nodeName != "OL" && qq.childNodes[3].className != "HQToggle" && qq.childNodes[3].className != "addusexbutton")			temporarydefholder.appendChild(qq.childNodes[3]);		if (qq.childNodes[2] != temporarydefholder) temporarydefholder.insertBefore(qq.childNodes[2], temporarydefholder.firstChild);		var defform		var olddef = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + "\\s?)"), '').match(/^(\{\{senseid\|[^\}]*\}\})?\s?(.*)/)[2]		new AdderWrapper(new Editor, { 'createForm': function { return defform = newNode('form', {					'style': 'width:100%;display:inline-block;margin-bottom:-6px;'				}, newNode('table', { 'style': 'width:100%;' }, newNode('tr', newNode('td', newNode('input', {						'style': 'height:17px;width:100%;',						'name': 'definition',						'size': 80,						'value': olddef					}) // newNode('input',{type:'submit',value:'Preview'}), // newNode('input',{type:'button',value:'Cancel',click:function{temporarydefholder.style.display='inline';defform.style.display='none';qq.YREditing = false}}) ), newNode('td', { 'style': 'white-space:nowrap;' }, newNode('div', {					'class': "DSBRedButton"				}, newNode('div', { click: function { temporarydefholder.style.display = 'inline'; defform.style.display = 'none'; qq.YREditing = false }				}, "Discard Changes")), newNode('div', {					'class': "DSBGreenButton"				}, newNode('div', { click: function { defform.onsubmit }				}, "Preview Changes ►")))))) },			'fields': { 'definition': function(txt, error) { return txt || error("Please specify a definition.") }			},			'onsubmit': function(values, render) { render(values.definition, function(newhtml) {

editor = new Editor var findnumberofdefs = findnumberofdefs_(qq) // apparently this is sometimes necessary var addedspan = newNode('span') addedspan.innerHTML = newhtml var updatecatscallback; editor.addEdit({						edit: function(wikitext) {							wikitext = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + "\\s?(\{\{senseid\\|[^\}]*\}\})*?)(?!{" + "{senseid\\|).*"), "$1" + values.definition);							ccc = wikitext;							return wikitext						},						redo: function {							defform.parentNode.insertBefore(addedspan, defform);							defform.style.display = temporarydefholder.style.display = 'none';							updatecatscallback = window.tabbedLanguages && updateCategories(findtopli(defform.parentNode).parentNode.parentNode, values.definition, olddef)							qq.YREditing = false;						},						undo: function {							defform.parentNode.removeChild(addedspan);							defform.style.display = "inline";							defform.firstChild.firstChild.firstChild.firstChild.value = olddef;							updatecatscallback && updatecatscallback;							qq.YREditing = true; },						summary: "def: " + values.definition }, addedspan)

})

}		}, qq, qq.childNodes[1].nodeName.toLowerCase != "form" ? qq.childNodes[1] : qq.childNodes[2])

})

}

function findtopli(li) { for (li.parentNode.parentNode.nodeName.toLowerCase == "li";) { li = li.parentNode.parentNode; }	return li; }

function findnumberofheaders_(tosearchfrom) { tosearchfrom = findtopli(tosearchfrom).parentNode; while (!tosearchfrom.nodeName.match(/^h\d$/i)) tosearchfrom = tosearchfrom.previousSibling; return Number(tosearchfrom.lastChild.getElementsByTagName('a')[0].href.match(/\d*$/)) }

function findnumberofdefs_(tosearchfrom) { var findnumberofdefs = [], tosearchfrom_, findnumberofpredefs = 0, result; // subdefinitions while (tosearchfrom.nodeName.toLowerCase == "li") { tosearchfrom_ = tosearchfrom; findnumberofdefs.splice(0, 0, 0); while (tosearchfrom) { if (tosearchfrom.nodeName.toLowerCase == "li") findnumberofdefs[0]++; tosearchfrom = tosearchfrom.previousSibling; }		tosearchfrom = tosearchfrom_.parentNode.parentNode; }	// in case of any def lists before the current def list under the same header for (tosearchfrom_ = tosearchfrom_.parentNode.previousSibling; !tosearchfrom_.nodeName.match(/^h\d$/i); tosearchfrom_ = tosearchfrom_.previousSibling) { if (tosearchfrom_.nodeName.toLowerCase == "ol") findnumberofpredefs += 1; }	result = "([\\s\\S]*?\n#[\\s\\S]*?\n(?!#)){" + findnumberofpredefs + "}"; for (var i = 0; i < findnumberofdefs.length; i++) { result += "([\\s\\S]*?\n" + Array(i + 2).join("#") + "(?![:*#])){" + findnumberofdefs[i] + "}"; }	return result; }

function findlang(tosearchfrom, callback) { var tosearchfrom_, findlang__ if (tosearchfrom.parentNode.nodeName.toLowerCase == "li") tosearchfrom = findtopli(tosearchfrom.parentNode).parentNode; if (tosearchfrom.parentNode.className == "languageContainer") { if (tosearchfrom.parentNode.id == "Englishcontainer") return callback("en"); } else { tosearchfrom_ = tosearchfrom; while (tosearchfrom_.nodeName.toLowerCase != "h2") tosearchfrom_ = tosearchfrom_.previousSibling; if (tosearchfrom_.lastChild.innerHTML == "English") return callback("en"); }	tosearchfrom_ = tosearchfrom; while (tosearchfrom_ && !/^h\d$/i.test(tosearchfrom_.nodeName) && tosearchfrom_.className != "fakeheader") tosearchfrom_ = tosearchfrom_.previousSibling; while (tosearchfrom_ && tosearchfrom_.nodeName.toLowerCase != "p" && tosearchfrom_.className != "fakeheader") tosearchfrom_ = tosearchfrom_.nextSibling; if (tosearchfrom_ && tosearchfrom_.className != "fakeheader" && tosearchfrom_.firstChild && (tosearchfrom_.firstChild.lang || (tosearchfrom_.firstChild.firstChild && tosearchfrom_.firstChild.firstChild.lang) || (tosearchfrom_.firstChild.firstChild && tosearchfrom_.firstChild.firstChild.firstChild && tosearchfrom_.firstChild.firstChild.firstChild.lang))) { return callback(tosearchfrom_.firstChild.lang || tosearchfrom_.firstChild.firstChild.lang || tosearchfrom_.firstChild.firstChild.firstChild.lang) }

if (tosearchfrom.parentNode.className == "languageContainer") findlang__ = tosearchfrom.parentNode.id.split("container")[0]; else { while (tosearchfrom.nodeName.toLowerCase != "h2") tosearchfrom = tosearchfrom.previousSibling; findlang__ = (findlang__ = tosearchfrom.getElementsByTagName("span")[0]).innerText || findlang__.textContent }

window.languagecodefinder_preload = window.languagecodefinder_preload || mw.loader.getScript('https://en.wiktionary.org/w/index.php?title=User:Yair_rand/languagecodefinder.js&action=raw&ctype=text/javascript');

window.languagecodefinder_preload.always( function {		window.languagenametocode && languagenametocode[findlang__] && callback(languagenametocode[findlang__])	}); }

function setupquoteadder(q) { findlang(q.parentNode, function(findlang_) {		var z;		if (!$(".HQToggle a", q)[0]) {			z = q.appendChild(document.createElement("ul"))			setupHiddenQuotes(q);		} else {			z = $(">ul", q)[0];		}		if (z.style.display == 'none') {			$(".HQToggle a", q).click;		}		var zz = z.appendChild(document.createElement("li")),			quoteform;		var findsubdef = q.parentNode.parentNode.nodeName.toLowerCase == "li" ? "#" : "",			editor = new Editor;		new AdderWrapper(editor, { 'createForm': function { return quoteform = newNode('form', {					'style': 'display:inline;'				}, 'Year: ', newNode('input', { 'name': 'year', 'size': 4 }), ' Author: ', newNode('input', { 'name': 'author', 'size': 20 }), ' Source title: ', newNode('input', { 'name': 'source', 'size': 20 }), ' Publisher: ', newNode('input', { 'name': 'publisher', 'size': 20 }), ' Page(s): ', newNode('input', { 'name': 'page', 'size': 5 }), newNode('dl', newNode('dd', 'Quotation: ', newNode('input', { 'name': 'quotation', 'size': 40 }), newNode('div', { 'class': "DSBRedButton", 'click': function { z.removeChild(zz) }				}, newNode('div', 'Cancel')), newNode('div', { 'class': "DSBGreenButton", 'click': function { quoteform.onsubmit }				}, newNode('div', "Preview ►")), newNode('input', { 'type': 'submit', 'style': 'visibility:hidden;width:0px;' }), newNode('dl', { 'style': 'display:' + (findlang_ == "en" ? "none" : "block") }, newNode('dd', 'Translation: ', newNode('input', { 'size': 40, 'name': 'translation' }))))))			},			'fields': { 'quotation': util.validateNoWikisyntax('quotation', true), 'year': util.validateNoWikisyntax('year', true), 'author': function(t) { return t				}, 'source': function(t) { return t ? ", " + t + "" : '' },				'publisher': function(t) { return t ? ", " + t : '' },				'page': function(t) { return t ? (/\-/.test(t) ? "pages " + t : "page " + t) : t				}, 'translation': function(t) { return t				} },			'onsubmit': function(values, render) { var topline = "" + values.year + "" + (values.author ? ", " + values.author : ) + values.source + values.publisher + (values.page ? ", " + values.page : ) render(topline + "\n:" + values.quotation + (values.translation ? "\n:" + values.translation : ""), function(newhtml) {					var findnumberofheaders = findnumberofheaders_(q),						findnumberofdefs = findnumberofdefs_(q),						quotetobeadded = newNode('span', { 'style': 'display:block;' });					quotetobeadded.innerHTML = newhtml.replace(/\|\<\/p\>/g, '');					editor.addEdit({ 'edit': function(wikitext) { return ccc = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + "[\\s\\S]*?)\n(?!#" + findsubdef + "[:\*])|$"), "$1\n#" + findsubdef + "*" + topline + "\n#" + findsubdef + "*:" + values.quotation + (values.translation ? "\n#" + findsubdef + "*:" + values.translation : '') + '\n') },						'redo': function { quoteform.style.display = 'none'; quotetobeadded.style.display = 'block'; zz.appendChild(quotetobeadded) },						'undo': function { quoteform.style.display = 'inline'; zz.removeChild(quotetobeadded) },						'summary': '+quote: "' + values.quotation + '"- ' + values.source }, quotetobeadded)				}) }		}, zz)	}) }

window.addPOSHeader = function(cancelhover) { var bodyContent = $(".mw-content-ltr")[0]; if (!defeditoptions.addingPOS) { defeditoptions.addingPOS = true; editor = new Editor var headerLevel = (window.languageContainers && languageContainers[currentLanguageTab] && languageContainers[currentLanguageTab].firstChild) || bodyContent.firstChild; var ii; var temp, temp_; var theform; var findnumberofheaders; var addedwikitext; var prefakeheaders; var currentFocus; var langNames = [], docLink, docExists = {}; if (window.loadedTabs) { langNames = tabbedLanguages; } else { mw.util.$content.find("h2>.mw-headline").each(function {				langNames.push($(this).text)			}) }		var langNameCodes; new mw.Api.get({			"action": "expandtemplates",			"format": "json",			"text": "",			"prop": "wikitext"		}).done(function(r){			if(r.expandtemplates && r.expandtemplates.wikitext){				langNameCodes = JSON.parse(r.expandtemplates.wikitext);			}		}); function updateDocLink { var pos = theform.getElementsByTagName("input")[0].value; pos = (({ Adjective: "adj", Adverb: "adv", Interjection: "interj", Preposition: "prep", Pronoun: "pron", Conjunction: "con", Contraction: "cont", Determiner: "det" })[pos] || pos.toLowerCase); if (!langNameCodes || !pos || !theform.getElementsByTagName("input")[0].value) { return; }			var currentLang = window.loadedTabs ? theform.parentNode.id.split("container")[0] : (function {				for (var s = theform; s && s.nodeName != "H2"; s = s.previousSibling);				return s && s.lastChild && (s.lastChild.innerText || s.lastChild.textContent)			}); var docName = langNameCodes[currentLang] + "-" + pos; if (docExists[docName] === false) { return docLink.style.display = 'none'; }			if (docExists[docName] === true) { docLink.style.display = 'inline'; docLink.href = mw.config.get("wgArticlePath").replace("$1", "Template:" + docName + "/doc"); return; }			if (docExists[docName] === 'l') { docLink.style.display = 'none'; return; }			docExists[docName] = 'l'; new mw.Api.get({				action: 'query',				prop: 'info',				titles: 'Template:' + docName + '/documentation'			}).then(function(r) {				docExists[docName] = r.query.pages.length == 1;				updateDocLink;			}); }

var poslist = '\nNoun\nVerb\nAdjective\nAdverb\nPronoun\nConjunction\nInterjection\nPreposition\nProper noun\nArticle\nPrepositional phrase\nAcronym\nAbbreviation\nInitialism\nContraction\nPrefix\nSuffix\nSymbol\nLetter\nLigature\nIdiom\nPhrase\nNumber\nNumeral\nCardinal number\nOrdinal number\nCardinal numeral\nOrdinal numeral\nPersonal pronoun\nDeterminer\nDemonstrative determiner\nClitic\nInfix\nInterfix\nAffix\nCircumfix\nCircumposition\nCounter\nKanji\nKanji reading\nHanja reading\nHirigana letter\nKatakana letter\nPinyin\nHan character\nHanzi\nHanja\nProverb\nExpression\nParticle\nInfinitive particle\nPossesive adjective\nPostposition\nPhrasal verb\nParticiple\nGerund\nInterrogative auxiliary verb\nPronominal adverb\nAdnominal\nAbstract pronoun\nConjunction particle\nCombining form\nRoot\nPinyin syllable\nSyllable\nHirigana character\nKatakana character\nJyutping syllable\nGismu\nLujvo\nBrivla\nClassifier\nPredicative\nMeasure word\nCorrelative\nPreverb\nPrenoun\nNoun stem\nNoun class\nCombined-kana character\nCmavo\n'; while (headerLevel.nextSibling) { if (/^h[34]$/i.test(headerLevel.nodeName) && !/Etymology|Pronunciation|Alternative\sforms/.test(headerLevel.innerHTML)) { headerLevel = headerLevel.nodeName.toLowerCase; break; }			headerLevel = headerLevel.nextSibling }

currentBoxToBeAdded = newNode('div', {			'style': 'position:fixed;top:500px;'		}) new AdderWrapper(editor, {			createForm: function {				return theform = newNode('form', currentFocus = newNode('input', {					'style': 'font-size: 0.8em;font-size: ' + ((headerLevel == 'h3') ? '132%' : '116%') + ';font-weight: bold;font-family: sans-serif;width:auto;',					'placeholder': 'Part of speech',					'rows': 1,					'name': 'pos',					focus: function {						currentFocus = this					}				}), newNode('input', {					'type': 'submit',					'value': 'Preview'				}), newNode('input', {					'type': 'button',					'value': 'Cancel',					click: function {						theform.style.display = 'none';						hoverNewPOS(null);						defeditoptions.addingPOS = false;						document.onmousemove = null;						document.body.style.cursor = '';					}				}), newNode('br'), newNode('input', {					'style': 'width:300px;font-family:monospace;',					'placeholder': '{\{head}}',					'name': 'inflline',					focus: function {						currentFocus = this					}				}), docLink = newNode('a', {					style: "margin-left:5px;display:none;",					'target': '_blank'				}, "Help?"), newNode('ol', newNode('li', newNode('input', { 'size': 100, 'disabled': 'disabled' }))))			},			fields: { 'pos': function(txt, error) { return poslist.indexOf('\n' + txt + '\n') > -1 ? txt : error('Please select a valid part of speech.') },				'inflline': function(txt, error) { return txt || "{" + "{head}}" }			},			onsubmit: function(values, render) { addedwikitext = '{' + '{subst:=}}==' + (headerLevel == 'h4' ? '=' : ) + values.pos + (headerLevel == 'h4' ? '=' : ) + '===\n' + values.inflline hoverNewPOS(null); document.onmousemove = null; defeditoptions.addingPOS = false; document.body.style.cursor = ''; render(addedwikitext, function(res) {					theform.style.display = 'none'					temp = document.createDocumentFragment;					temp.appendChild(temp_ = newNode('div', {						'class': 'fakeheader'					}));					temp_.innerHTML = res;					temp.appendChild(newNode('ol', newNode('li', ' ', newNode('span'))));					theform.parentNode.insertBefore(temp, theform);

prefakeheaders = 0 findnumberofheaders = theform.previousSibling.previousSibling; while (true) { if (findnumberofheaders.previousSibling) { findnumberofheaders = findnumberofheaders.previousSibling; if (/h[2-6]/i.test(findnumberofheaders.nodeName)) { findnumberofheaders = Number(findnumberofheaders.lastChild.getElementsByTagName('a')[0].href.split("section=")[1]); break; }							findnumberofheaders.className == 'fakeheader' && prefakeheaders++; } else { findnumberofheaders.parentNode.insertBefore(newNode('h2', languageHeaderEditButtons[currentLanguageTab].cloneNode(true), { 'style': 'display:none;' }), findnumberofheaders); }					}

var updatecatscallback; editor.addEdit({						'edit': function(wikitext) {							return ccc = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}([\\s\\S]*?\n\\{\\{subst:\\=\\}\\}==" + (headerLevel == 'h4' ? '=' : ) + "[^=]){" + prefakeheaders + "}[\\s\\S]*?(?=(\n=|\n|\n\\{\\{subst:\\=\\}\\}==" + (headerLevel == 'h4' ? '=' : ) + "[^=]|$)))"), "$1\n" + addedwikitext + "\n\n# {" + "{rfdef}}\n")						},						'redo': function {							theform.style.display = 'none';							theform.parentNode.insertBefore(temp, theform);							updatecatscallback = window.tabbedLanguages && updateCategories(theform.parentNode, addedwikitext)						},						'undo': function {							theform.style.display = 'block';							temp.appendChild(temp_);							temp.appendChild(theform.previousSibling);							updatecatscallback && updatecatscallback						},						'summary': '+pos ' + values.pos					}, temp_)

makedefsidebox(theform.previousSibling.firstChild);

editor.withCurrentText(function {						theform.previousSibling.getElementsByTagName('input')[0].value = '';						theform.previousSibling.getElementsByTagName('input')[0].focus					}) })			}		}, currentBoxToBeAdded)

cancelhover || setUpBoxToBeAdded; theform.firstChild.focus

function hoverNewPOS(thefunction) { for (var ii = bodyContent.getElementsByTagName(headerLevel), i = 0; i < ii.length; i++) { if (!/^Etymology|Pronunciation|Alternative\sforms$/.test(ii[i].firstChild.innerHTML))(ii[i].parentNode.className == 'fakeheader' ? ii[i].parentNode : ii[i]).onmouseover = thefunction; }			if (window.tabbedLanguages) { for (var i = 0; i < languageContainers.length; i++) languageContainers[i].lastChild.onmouseover = thefunction; } else { ii = bodyContent.getElementsByTagName('hr'); for (var i = 0; i < ii.length; i++) ii[i].onmouseover = thefunction; }		}

function hoverNewPOS_ { currentBoxToBeAdded.style.display = 'none'; this.parentNode.insertBefore(theform, this); currentFocus.focus; updateDocLink }

cancelhover || hoverNewPOS(hoverNewPOS_);

// autocomplete pos field theform.firstChild.onkeydown = function(e) { if ((e || event).keyCode == 9) { theform.getElementsByTagName("input")[3].focus; return false }		}		theform.firstChild.onkeyup = function(e) { if (this.value[0] != this.value.charAt(0).toUpperCase) this.value = this.value.charAt(0).toUpperCase + this.value.substr(1); e = (e || event).keyCode; if (!(e >= 33 && e <= 40) && e != 8 && e != 46 && e != 27 && e != 16 && this.value) { if (poslist.indexOf('\n' + this.value) > -1) { if (this.setSelectionRange) this.setSelectionRange([this.value.length, this.value = poslist.match(RegExp(this.value + "[^\n]*"))][0], this.value.length); else if (this.createTextRange) { var z = this.createTextRange; z.moveEnd('character', 0 - z.move('character', [this.value.length, this.value = poslist.match(RegExp(this.value + "[^\n]*"))][0]) + this.value.length); z.select }				}				updateDocLink }		}

} }

window.updateCategories = function(container, newvalue, oldvalue) { var addedCategories = [], removedCategories = [] new mw.Api.get({		action: "parse",		prop: "categorieshtml",		title: mw.config.get('wgPageName'),		text: newvalue	}).then(function(r) {		var e = r.parse.categorieshtml['*'].match(/\/g);		var d = container.lastChild.lastChild;		var f = document.createElement('ul');		for (var i = 0; e && i < e.length; i++) {			f.innerHTML = e[i];			if (d.innerHTML.indexOf(f.firstChild.innerHTML) == -1) {				addedCategories.push(d.insertBefore(f.lastChild, d.lastChild))			}		}		oldvalue && new mw.Api.get({ action: "parse", prop: "categorieshtml", title: mw.config.get('wgPageName'), text: oldvalue }).then(function(o) { e = o.parse.categorieshtml['*'].match(/\/g) for (var i = 0; e && i < e.length; i++) { f.innerHTML = e[i]; if (r.parse.categorieshtml['*'].indexOf(f.firstChild.innerHTML) == -1 && d.innerHTML.indexOf(f.firstChild.innerHTML) != -1) { var lis = d.getElementsByTagName('li') for (var ii = 0; ii < lis.length; ii++) { if (lis[ii].firstChild.innerHTML == f.firstChild.firstChild.innerHTML) { removedCategories.push(lis[ii]); lis[ii].style.display = 'none'; break; }					}				}			}		})	});	return function { for (var i = 0; i < addedCategories.length; i++) { container.lastChild.lastChild.removeChild(addedCategories[i]) }		for (var i = 0; i < removedCategories.length; i++) { removedCategories[i].style.display = ''; }	} }

function addgloss(qq) { var senseidform; findlang(qq.parentNode, function(findlang_) {		if (qq.addinggloss) {			return		}		qq.addinggloss = true;		editor = new Editor;		new AdderWrapper(editor, { 'createForm': function { return senseidform = newNode('form', {					'style': 'display:inline; padding-right:20px;'				}, newNode('input', { 'size': 30, 'name': 'senseid' }), newNode('input', { 'type': 'submit', 'value': 'Add' }), newNode('input', { 'type': 'button', 'value': 'Cancel', 'click': function { qq.removeChild(senseidform); qq.addinggloss = false }				}), newNode('a', { href: '/wiki/Help:Glosses' }, 'Help?!')) },			'fields': { 'senseid': util.validateNoWikisyntax('gloss', true) },			'onsubmit': function(values) { var findnumberofheaders = findnumberofheaders_(qq) var findnumberofdefs = findnumberofdefs_(qq) senseidform.lastChild.innerHTML = ''; var nymB = qq.getElementsByTagName('li')[1] editor.addEdit({					edit: function(wikitext) {						wikitext = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + ") ?"), "$1{" + "{senseid|" + findlang_ + "|" + values.senseid + "}}");						return ccc = wikitext;					},					redo: function {						senseidform.style.display = "none";						$([nymB.firstChild, nymB.nextSibling.firstChild]).removeClass('DSBinactive');						nymB.firstChild.title = nymB.nextSibling.firstChild.title = ''					},					undo: function {						senseidform.style.display = "inline";						$([nymB.firstChild, nymB.nextSibling.firstChild]).addClass('DSBinactive');						nymB.firstChild.title = 'Please add a gloss before adding synonyms.';						nymB.nextSibling.firstChild.title = 'Please add a gloss before adding antonyms.'					},					summary: "+senseid: " + values.senseid				}) }		}, qq, qq.childNodes[1])		senseidform.firstChild.focus		editor.withCurrentText(function(wikitext) { wikitext = wikitext.match("==" + (window.loadedTabs ? tabbedLanguages[currentLanguageTab] : $(findtopli(qq).parentNode).prevUntil("h2").eq(-1).prev.find(".mw-headline").text) + "==\n[\\s\\S]+?(|$)")[0]; if (!wikitext) return; var senses = '', matches = wikitext.match(/(\{\{sense\||\{\{trans-top\|)[^\}]+(?=\}\})/g) if (!matches) return; for (var ms = 0; ms < matches.length; ms++) { senses += "\n" + matches[ms].split("|")[1] }			if (!senses) return; senseidform.firstChild.onkeyup = function(e) { e = (e || event).keyCode; if (!(e >= 33 && e <= 40) && e != 8 && e != 46 && e != 27 && e != 16 && this.value) { if (senses.indexOf('\n' + this.value) > -1) { if (this.setSelectionRange) this.setSelectionRange([this.value.length, this.value = senses.match(RegExp("\n" + this.value + "[^\n]*")).toString.substr(1)][0], this.value.length); else if (this.createTextRange) { var z = this.createTextRange; z.moveEnd('character', 0 - z.move('character', [this.value.length, this.value = senses.match(RegExp("\n" + this.value + "[^\n]*")).toString.substr(1)][0]) + this.value.length); z.select }					}				}			}		})	}) }

function editgloss(qq) {

editor = new Editor editor.withCurrentText(function(wikitext) {		if (qq.editinggloss) {			return		}		qq.editinggloss = true;		var findnumberofheaders = findnumberofheaders_(qq)		var findnumberofdefs = findnumberofdefs_(qq)		var senseidform;		var oldsenseid;		new AdderWrapper(editor, { 'createForm': function { var thisId = "a" + String(Math.random).replace(".", "") oldsenseid = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + "\\s?)"), '').match(/^\{\{senseid\|[^\\|]*\|([^\}]*)/)[1] return senseidform = newNode('form', {					'style': 'display:inline; padding-right:20px; '				}, newNode('input', { 'size': 30, 'name': 'senseid', 'value': oldsenseid }), newNode('input', { 'type': 'checkbox', 'id': thisId, 'name': 'changematching', style: 'display:' + (window.tabbedLanguages ? 'inline' : 'none') }), newNode('label', { 'for': thisId, style: 'display:' + (window.tabbedLanguages ? 'inline' : 'none') }, 'Edit matching glosses'), newNode('input', { 'type': 'submit', 'value': 'Change' }), newNode('input', { 'type': 'button', 'value': 'Cancel', 'click': function { qq.editinggloss = false; qq.removeChild(senseidform); }				}), newNode('a', { href: '/wiki/Help:Glosses' }, 'Help?!')) },			'fields': { 'senseid': util.validateNoWikisyntax('gloss', true), 'changematching': 'checkbox' },			'onsubmit': function(values) { var ttables = [], sensetemps = [], backups = []; if (values.changematching) { ttables = jQuery(".NavHead", languageContainers[currentLanguageTab]).filter(function {						if (this.parentNode.getElementsByTagName("table")[0].className != "translations") return false;						for (var i = 0; i < this.childNodes.length; i++) {							if (this.childNodes[i].nodeType == 3 || this.childNodes[i].className == 'wt-edit-recurse') {								return (this.childNodes[i].nodeValue || this.childNodes[i].innerHTML) == oldsenseid;							}						}					}) sensetemps = jQuery(".qualifier-content", languageContainers[currentLanguageTab]).filter(function {						return this.parentNode.nextSibling.nextSibling.className == "ib-colon" && this.innerHTML == oldsenseid;					}) }				editor.addEdit({					edit: function(wikitext) {						wikitext = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + "\\s?(\{\{senseid\\|[^\\|]*\\|))[^\}]*"), "$1" + values.senseid);						if (values.changematching) {							var asd = wikitext.match('==' + tabbedLanguages[currentLanguageTab] + '==\n[\\s\\S]+?(\n==[^=]|$)');							wikitext = wikitext.replace(asd[0], asd[0].replace(RegExp("\\{\\{(sense|trans-top)\\|" + oldsenseid + "\\}\\}", "g"), "{\{$1\|" + values.senseid + "}}"))						}						return ccc = wikitext					},					redo: function {						senseidform.style.display = "none";						for (var i = 0; i < ttables.length; i++) {							backups.push(document.createDocumentFragment);							while (ttables[i].childNodes[1]) {								backups[backups.length - 1].appendChild(ttables[i].childNodes[1]);							}							ttables[i].appendChild(document.createTextNode(values.senseid)) }						for (var i = 0; i < sensetemps.length; i++) { backups.push(document.createDocumentFragment); backups[backups.length - 1].appendChild(sensetemps[i].firstChild); sensetemps[i].appendChild(document.createTextNode(values.senseid)) }					},					undo: function { senseidform.style.display = "inline"; for (var i = 0; i < ttables.length; i++) { ttables[i].removeChild(ttables[i].childNodes[1]); ttables[i].appendChild(backups.shift) }						for (var i = 0; i < sensetemps.length; i++) { sensetemps[i].removeChild(sensetemps[i].firstChild) sensetemps[i].appendChild(backups.shift) }					},					summary: "senseid: " + values.senseid })			}		}, qq, qq.childNodes[1]) senseidform.firstChild.focus }) }

function setupnymadder(qq, nymtype) { var passtheseheaders = "Usage notes|Inflection|Conjugation|Declension|Quotations", nymtypelist = ["Synonyms", "Antonyms", "Hypernyms", "Hyponyms", "Meronyms", "Holonyms"] for (var x = 0; nymtypelist[x] != nymtype; x++) passtheseheaders += "|" + nymtypelist[x]; if (qq.parentNode.parentNode.nodeName.toLowerCase == "li") qq = qq.parentNode.parentNode; var findnumberofheaders = findnumberofheaders_(qq) var findnumberofdefs = findnumberofdefs_(qq.parentNode.getElementsByTagName('li')[0]) for (var findheaderlevel = qq.parentNode; !/^h\d$/i.test(findheaderlevel.nodeName); findheaderlevel = findheaderlevel.previousSibling); findheaderlevel = Number(findheaderlevel.nodeName.match(/\d/)); var senseidencoded = [] editor = new Editor editor.withCurrentText(function(wikitext) {

// Find nym header, or add it if it doesn't exist var qqq = qq.parentNode;

while (!((qqq.className == "fakesubheader" || /h\d/i.test(qqq.nodeName)) && !qqq.innerHTML.match(passtheseheaders) || qqq.className == "printfooter" || qqq.className == "fakeheader" || qqq.className == "catlinks")) { qqq = qqq.nextSibling }		if (!qqq.innerHTML.match(nymtype)) { qqq = qqq.parentNode.insertBefore(newNode('div', { 'class': 'fakesubheader' }, newNode('h' + (findheaderlevel + 1), nymtype)), qqq); }		// relevant vars: // findheaderlevel is the the headerlevel of the most recent header above the ol		//  qq is still the li itself // qqq is the (possibly newly added) nym header // find all relevant senseids, make an array of them, the whole template in each var senseid = wikitext.replace(			RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + ")"), ).replace(/\n\n[\s\S]*$/, ).match(/\{\{senseid\|[^\\|]*\|[^\}]*/g)

if (!senseid) { alert("No glosses were found. Click \"Add gloss\" to attach a gloss to the definition before adding " + nymtype.toLowerCase + "."); return }

// run through senseids, checking for a corresponding span id'd nymtype-langcode-id, adding them encased in an li in a soon-to-be-parsed temp variable if not found, otherwise suppressing new form creation temp = "" var nymformexists = [] for (var i = 0; i < senseid.length; i++) { if (document.getElementById(senseidencoded[i] = nymtype + "-" + encodeURIComponent(senseid[i].split("|")[1] + "-" + senseid[i].split("|")[2]).replace(/%20/g, '_').replace(/%3A/g, ':').replace(/%/g, '.'))) { nymformexists[i] = true } else { temp += "* {" + "{sense|" + senseid[i].split("|")[2] + "}}  \n" }

}		new mw.Api.parse(temp, {					title: mw.config.get('wgPageName'), 					pst: true, //pst makes subst work as expected					disablelimitreport: true				}).then(function(res) {			var qqqq = newNode('span')			qqqq.innerHTML = res			qqqq = qqq.parentNode.insertBefore(qqqq.firstChild, qqq.nextSibling) // the ul containing the form-holder spans, right below the nym header			for (var i = 0; i < senseid.length; i++) {				if (!nymformexists[i]) {					setupnymadder2(i, senseid, wikitext)				}			}			if (qqqq.getElementsByTagName && qqqq.getElementsByTagName('li').length == 0) {				qqqq.parentNode.removeChild(qqqq)			}			scroll(0, jQuery(qqq).offset.top)		});

})

function setupnymadder2(i, senseid, wikitext) {

var nymtype2 = nymtype.slice(0, -1).toLowerCase var x = document.getElementById(senseidencoded[i]);

var theform new AdderWrapper(editor, {			'createForm': function {				return theform = newNode('form', { 'style': 'display:inline;' }, newNode('input', {					'name': 'nym'				}), newNode('input', {					'value': 'Add',					'type': 'submit'				}))			},			'fields': {				'nym': util.validateNoWikisyntax(nymtype2, true)			},			'onsubmit': function(values, render) {				theform.getElementsByTagName('input')[0].value = ""				var firstnym = !theform.parentNode.parentNode.getElementsByTagName('a')[0]				var addedwikitext = (firstnym ? '' : ', ') + "{" + "{l|" + senseid[i].split("|")[1] + "|" + values.nym + "}}"				render(addedwikitext, function(res2) { var nodeToInsert = newNode('span') nodeToInsert.innerHTML = res2 editor.addEdit({						edit: function(wikitext) {							// unindent							findnumberofdefs = findnumberofdefs_(qq.parentNode.getElementsByTagName('li')[0])

if (wikitext.substr(wikitext.length - 1, 1) != "\n") { wikitext += "\n" }

if (!wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + ")"), ).replace(RegExp("(\n(=|\\{\\{subst:=\\}\\})={" + (findheaderlevel - 1) + "}[^=][\\s\\S]*$)"), ).match(RegExp(nymtype + "={" + findheaderlevel + "}"))) { wikitext = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + "[\\s\\S]*?(\n(?=(\\{\\{subst:=\\}\\}|=)=+(?=[^=])(?!(" + passtheseheaders + ")))|$))"), "$1{" + "{subst:=}}===" + (findheaderlevel == 4 ? "=" : "") + nymtype + (findheaderlevel == 4 ? "=" : "") + "====\n\n") }

if (firstnym) { var passthesesenseids = []; for (var ii = 0; ii < i; ii++) { passthesesenseids.push("\\* \\{\\{sense\\|" + senseid[ii].split("|")[2] + "\\}\\}") }								wikitext = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}" + findnumberofdefs + "[\\s\\S]*?=" + nymtype + "=+[\\s\\S]*?\n" + (passthesesenseids.length > 0 ? "(?!(" + passthesesenseids.join("|") + ")))" : ")")), "$1* {" + "{sense|" + senseid[i].split("|")[2] + "}} " + addedwikitext + "\n")							} else {								wikitext = wikitext.replace(RegExp("(^[\\s\\S]*?((^|\n)=[\\s\\S]*?){" + findnumberofheaders + "}[\\s\\S]*?=" + nymtype + "=+[\\s\\S]*?\\{\\{sense\\|" + senseid[i].split("|")[2] + "\\}\\}.*)"), "$1" + addedwikitext)							}

return ccc = wikitext;

},						redo: function { theform.parentNode.parentNode.insertBefore(nodeToInsert, theform.parentNode) },						undo: function { theform.parentNode.parentNode.removeChild(nodeToInsert) },						summary: "+" + nymtype2 + " " + values.nym + "" }, nodeToInsert)				}) }		}, x)

// sort the lis var passthesesenseids = []; for (var ii = 0; ii < i; ii++) { passthesesenseids.push(senseid[ii].split("|")[2]) }		for (var xx = x.parentNode.parentNode.nextSibling; xx.nextSibling && !/h\d/i.test(xx.nodeName) && xx.className != "fakesubheader" && xx.nodeName.toUpperCase != "UL"; xx = xx.nextSibling); if (xx.nodeName.toUpperCase == "UL") { var xxx = xx.getElementsByTagName('li') for (var xxxx = xxx.length; xxxx--;) { var xxxxx = xxx[xxxx].getElementsByTagName("span")[3] if (xxxxx && xxxxx.innerHTML == senseid[i].split("|")[2]) { x.parentNode.parentNode.removeChild(x.parentNode); xxx[xxxx].appendChild(x); break; }				if (xxxxx && passthesesenseids.length && RegExp(passthesesenseids.join("|")).test(xxxxx.innerHTML)) { xxx[xxxx + 1] ? xx.insertBefore(x.parentNode, xxx[xxxx]) : xx.appendChild(x.parentNode); break; }			}			if (xxxx == -1) { xx.insertBefore(x.parentNode, xx.firstChild) }		}

}

}

jQuery(document).ready(function {	var disablebutton = document.getElementById('YRDefsideboxes-disable-button');	if (disablebutton) {		disablebutton.innerHTML = "";		var toggle = newNode('span', { click: function { if ($.cookie("DisableYREdit")) { $.cookie("DisableYREdit", null, {						path: "/"					}) toggle.innerHTML = "Disable definition editing options." } else { $.cookie("DisableYREdit", 1, {						expires: 30,						path: "/"					}) toggle.innerHTML = "Enable definition editing options." }			}		}, ($.cookie("DisableYREdit") ? "Enable" : "Disable") + " definition editing options.")		disablebutton.appendChild(toggle);	}	if (mw.config.get('wgAction') == 'view' && (mw.config.get('wgNamespaceNumber') == 0 || mw.config.get('wgPageName') == "Wiktionary:Sandbox") && !/&printable=yes|&diff=|&oldid=/.test(window.location.search) && !$.cookie("DisableYREdit") && !window.DisableYREdit && !window.loadedYREdit) {		window.loadedYREdit = true;		for (var ols = document.getElementsByTagName('ol'), ii = 0; ii < ols.length; ii++) {			if (ols[ii].className != "references") {				for (var lis = ols[ii].getElementsByTagName('li'), i = 0; i < lis.length; i++) {					if (lis[i].parentNode == ols[ii] && ols[ii].parentNode.parentNode.nodeName != "UL") makedefsidebox(lis[i]);				}			}		}

mw.util.addPortletLink('p-tb', 'javascript:addPOSHeader', 'Add part of speech'); defsidebuttons = [0] defeditoptions = { addingPOS: false }	} })