User:Erutuon/common.js

// // See also m:User:Erutuon/global.js. /* jshint maxerr: 250, moz: true */

if (mw.config.get('wgNamespaceNumber') === 14 && /^[a-z]{2,3}(?:-[a-z]{2,3})*$/.test(mw.config.get('wgTitle'))) { importScript('User:Erutuon/scripts/langCatRedirect.js'); }

(function {

var mwvalues = mw.config.values; if (!mwvalues) throw new TypeError("mwvalues is undefined"); var namespace = mwvalues.wgFormattedNamespaces[mwvalues.wgNamespaceNumber]; var pageName = mwvalues.wgPageName; var contentModel = mw.config.get('wgPageContentModel');

window.loadWikipediaScript = function (pageName) { mw.loader.load('//en.wikipedia.org/w/index.php?title=' + pageName + '&action=raw&ctype=text/javascript'); };

window.withScript = function (pageName, successCallback, failureCallback) { return $.getScript('//en.wiktionary.org/w/index.php?title=' + encodeURIComponent(pageName)		+ '&action=raw&ctype=text/javascript') .done(successCallback) .fail(failureCallback); };

window.copyWikitext = function copyWikitext(title) { window.withScript('User:Erutuon/scripts/apiWrapper.js', function {		apiWrapper.getWikitext(title, function(wikitext) { $('#wpTextbox1').textSelection('setContents', wikitext); $('#wpSummary').val('copy of ' + title + ""); });	}); };

function makeShowHideButton(toHide, precedingElement) { mw.loader.using("oojs-ui").done(function {		const button = new OO.ui.ButtonWidget;		var shown = false;		button.updateLabel = function {			this.setLabel(shown ? hideText : showText);		};		const hideText = 'Hide words with entries',			showText = 'Show words with entries';		precedingElement.before(button.$element);		toHide.toggle(shown);		button.updateLabel;		button.$element.click(function { shown = !shown; toHide.toggle(shown); button.updateLabel; });	}); }

/* Scripts running only on specific pages */ switch (pageName) { case 'Special:WantedCategories': case 'Special:WantedTemplates': importScript('User:Erutuon/scripts/hideUnwantedCategories.js'); //Linkback: User:Erutuon/scripts/hideUnwantedCategories.js Added by Script installer break; case 'Special:Search': { // Add button to retrieve list of titles from search results. mw.loader.using("oojs-ui").done(function {			const button = new OO.ui.ButtonWidget;			const getSearchResultTitles = function  {				return $(".mw-search-result-heading a").get.map(function (e) { return e.textContent; });			};			button.setLabel("Extract list of titles from search results");			button.$element.click(function { const titles = getSearchResultTitles; const pre = $(" ").text(titles.join("\n")).css("clear", "both"); button.$element.replaceWith(pre); });			$(".results-info").after($(" ").append(button.$element));		}); break; }	case 'MediaWiki:Gadgets-definition': importScript('User:Erutuon/scripts/gadgets-definition.js'); break; case 'User:Erutuon/Odyssey_list': case 'User:Erutuon/Odyssey_list_(5-3)': case 'User:Erutuon/Odyssey_twice-used_list': case 'User:Erutuon/Odyssey_nonce_list': { const $hasEntry = $('.mw-parser-output li').has('[lang=grc] a[class!=new]'); makeShowHideButton($hasEntry, $hasEntry.first.parent); break; }	case 'User:Erutuon/Thucydides_words': { const $tableRows = $('.mw-parser-output tr').has('td'); const $withRedLink = $tableRows.not($tableRows.has('.new')); makeShowHideButton($withRedLink, $withRedLink.closest('table')); break; }	case 'User:Erutuon/Classical_Greek_prose': { const $hasEntry = $('.mw-parser-output ul li') .filter(function (_, li) {				const span = li.firstChild;				return span.lang === 'grc' && !span.firstChild.classList.contains('new');			}); makeShowHideButton($hasEntry, $('#toc')); break; }	case 'Special:Watchlist': case 'Special:RecentChanges': case 'Special:RecentChangesLinked': case 'Special:Contributions': case 'Special:WhatLinksHere': importScript('User:Erutuon/scripts/watchlistScriptTagging.js'); //Linkback: User:Erutuon/scripts/watchlistScriptTagging.js Added by Script installer break; case 'Module:accel': case 'Module:accel/documentation': case 'Module:number_list': case 'Module:number_list/documentation': importScript('User:Erutuon/scripts/moduleDocumentation.js'); // Linkback: User:Erutuon/scripts/moduleDocumentation.js break; case 'User:Erutuon/mainspace_headers': { importScript('User:Erutuon/scripts/mainspaceHeaders.js'); // User:Erutuon/scripts/mainspaceHeaders.js break; }	case 'Wiktionary:AutoWikiBrowser/Script': if (mw.config.get('wgAction') === 'view') loadWikipediaScript('User:Joeytje50/JWB.js/load.js'); break; default: if (contentModel === 'javascript') importScript('User:Erutuon/scripts/ScriptInstaller.js');	// User:Erutuon/scripts/ScriptInstaller.js }

window.syntaxHighlighterConfig = { externalLinkColor: '#FFCC66', //orange wikilinkColor:    '#E6FFFF', //cyan };

if ([ 'edit', 'submit' ].includes(mwvalues.wgAction)) { var addApiResultToTextbox = function (funcName) { return function (str) { return withScript('User:Erutuon/scripts/apiWrapper.js', function {				if (!(funcName in apiWrapper))					throw new Error("Function " + funcName + " not in apiWrapper");				apiWrapper[funcName](str, function (result) { var $textbox = $('#wpTextbox1'); try { // avoid error: currSelection is undefined $textbox.textSelection('replaceSelection', result); } catch (e) { $textbox.textSelection('setContents', result); }				});			});		};	};	// Insert expanded wikitext into the text box, as if from // Special:ExpandTemplates. window.insertExpandedTemplate = addApiResultToTextbox('expandTemplates'); // Replace selection in text box with the wikitext of a page. window.insertWikitext = addApiResultToTextbox('getWikitext'); // Keep in sync with Special:AbuseFilter/68. window.noHeadTempRegex = new RegExp("([=]{3,7})[ \t]*(?:" + [ "Abbreviation", "Acronym", "Adjectival noun", "Adjective", "Adnominal", "Adverb", "Affix", "Article", "Circumfix", "Classifier", "Combining form", "Conjunction", "Contraction", "Counter", "Definitions", "Determiner", "Diacritical mark", "Gerund", "Han character", "Hanja", "Hanzi", "Idiom", "Infix", "Initialism", "Interfix", "Interjection", "Kanji", "Letter", "Ligature", "Logogram", "Noun", "Number", "Numeral", "Ordinal number", "Participle", "Particle", "Phrase", "Postposition", "Predicative", "Prefix", "Preposition", "Prepositional phrase", "Pronoun", "Proper noun", "Proverb", "Punctuation mark", "Relative", "Romanization", "Root", "Stem", "Suffix", "Syllable", "Symbol", "Verb", "Verbal noun" ].join("|") + ")[ \t]*\\1[^{]*?#", "g"); const makeTextboxRegexFinder = function (regex) { var textbox = $('#wpTextbox1'); var searched = false; var failed = false; function doSearch { var match = regex.exec(textbox.val); if (match) { textbox.textSelection('setSelection',					{ start: match.index, end: match.index + match[0].length }); textbox.focus; }			return match; }		return function { if (failed) { return; }			if (!searched) { noHeadTempRegex.lastIndex = 0; }			var fromStart = regex.lastIndex === 0; var match = doSearch; if (!fromStart && regex.lastIndex === 0) { match = doSearch; }			searched = Boolean(match); failed = fromStart && !match; };	};	if ( [ "edit", "submit" ].includes(mw.config.get("wgAction"))	&& (namespace === "" || namespace === "Reconstruction")	&& mw.config.get("wgPageContentModel") === "wikitext"	// Not in edit conflict view.	&& !document.querySelector(".mw-twocolconflict-changes-col")	&& noHeadTempRegex.test($('#wpTextbox1').val)) { $.getScript("//en.wiktionary.org/w/index.php?title=User:Erutuon/scripts/CleanupButtons.js&action=raw&ctype=text/javascript") .done(function {			var buttons = new CleanupButtons;			buttons.addButton({ button: { text: "find missing headword-line template" }, func: makeTextboxRegexFinder(noHeadTempRegex), });		});	} }

// importScript('User:Dixtosa/rhyme.js');			// User:Dixtosa/rhyme.js // importScript('User:Dixtosa/expandASADRS.js');	// User:Dixtosa/expandASADRS.js // importScript('User:Dixtosa/skipToPost.js');		// User:Dixtosa/skipToPost.js importScript('User:Erutuon/scripts/sidebar.js'); //Linkback: User:Erutuon/scripts/sidebar.js Added by Script installer importScript('User:Erutuon/scripts/editableHeading.js'); //Linkback: User:Erutuon/scripts/editableHeading.js Added by Script installer // importScript('User:Dixtosa/SearchInTranslations.js'); //Linkback: User:Dixtosa/SearchInTranslations.js Added by Script installer importScript('User:Erutuon/scripts/editTop.js'); //Linkback: User:Erutuon/scripts/editTop.js Added by Script installer

// m:User:SMcCandlish/userinfo.js if (namespace === 'User') mw.loader.load('https://meta.wikimedia.org/w/index.php?title=User:SMcCandlish/userinfo.js&action=raw&ctype=text/javascript');

if (namespace === 'Category') { var autoCatEditSummary = true;						// show edit summary importScript('User:Erutuon/scripts/addAutoCat.js');	// User:Erutuon/scripts/addAutoCat.js if ($(".language-category-info th").length > 0) importScript('User:Erutuon/scripts/showLanguageData.js'); }

// importScript('User:Dixtosa/highlightme.js'); //Linkback: User:Dixtosa/highlightme.js Added by Script installer // importScript('User:Dixtosa/WhoDidThat.js'); //Linkback: User:Dixtosa/WhoDidThat.js Added by Script installer

if (mwvalues.wgCategories		&& mwvalues.wgCategories.includes('Wiktionary-namespace discussion pages')) importScript('User:Erutuon/scripts/discussionNavigation.js');	// User:Erutuon/scripts/discussionNavigation.js

/* Scripts running based on contents of page */ if (document.querySelector('[lang=ru-Latn]') !== null) importScript('User:Erutuon/scripts/modifyRussianTranslit.js'); //Linkback: User:Erutuon/scripts/modifyRussianTranslit.js Added by Script installer

if (namespace === '' && document.querySelector('.translations') !== null) importScript('User:Erutuon/scripts/simpleTranslations.js');		// User:Erutuon/scripts/simpleTranslations.js

if (document.querySelector('[class^=inflection-table]')) importScript('User:Erutuon/scripts/changeCaseOrder.js'); //Linkback: User:Erutuon/scripts/changeCaseOrder.js Added by Script installer

{	const grc = document.querySelectorAll("[lang=grc]"); const wrongApostrophe = /[\'\u1FBD\u1FBF]/; var count = 0; for (var i = 0, len = grc.length; i < len; ++i) { const innerText = grc[i].innerText; if ( innerText && wrongApostrophe.test(innerText) ) { mw.notify("Wrong apostrophe detected in Ancient Greek text: " + innerText + "."); if (++count > 5) break; }	} }

// id="templatesandbox-editform" is always on edit pages, but only on // template and module pages is it in a fieldset tag. var templateSandboxEditform = document.getElementById("templatesandbox-editform"); if (templateSandboxEditform && templateSandboxEditform.tagName === "FIELDSET") { importScript("User:Erutuon/scripts/templatePreview.js"); }

if (namespace == 'Category') { $("div.CategoryTreeTag").find("a.CategoryTreeLabel").html(function(index, content) {		return content.replace( /^Requests for (?:verification|deletion|cleanup) in (.+) entries$/, "$1"		);	});	/*	** On category pages, remove "0 c" or "0 e" from parentheses in listing of ** subcategories. */	document.querySelectorAll('.CategoryTreeItem span').forEach(function (elem) {		if (elem.title.startsWith('Contains')) {			elem.innerHTML = elem.innerHTML				.replace(/(?:, )?0 [ce](?:, )?/, '');		}	}); }

$(":lang(uk-Latn)").html(function(index, content) {	return content.replace(/v/g, "w"); });

var $example4ListItems = $("#example4 ul li"); if ($example4ListItems.length > 0) { var getListItemsToHide = function ($listItems, columnCount, rowsInShowState) { var count = $listItems.length; var itemsPerColumn = Math.ceil(count / columnCount); var $elemsToHide = $; if (itemsPerColumn > rowsInShowState) { for (var i = 0; i < columnCount; ++i) { var columnStart = i * itemsPerColumn; $elemsToHide = $elemsToHide .add($listItems.slice(columnStart + rowsInShowState, columnStart + itemsPerColumn)); }		}		return $elemsToHide; };	getListItemsToHide($example4ListItems, 3, 3) .addClass("vsHide").css('list-style-type',		'"' + String.fromCodePoint(0x1F47B) + '"'); // JSHint doesn't like codepoint escapes ("\u{1F47B}"). }

window.getCodePointNames = function (str) { if (typeof str !== 'string') throw new Error("expected string, got " + typeof str); withScript('User:Erutuon/scripts/apiWrapper', function {		apiWrapper.expandTemplates( '',			function (wikitext) { var names = JSON.parse(wikitext); console.log(names); });		}); };

Object.getPrototypeOf(localStorage).keys = function { return Object.getOwnPropertyNames(this); };

// w:User:Anomie/previewtemplatelastmod.js // loadWikipediaScript('User:Anomie/previewtemplatelastmod.js');

// w:User:קיפודנחש/searchPersistence.js loadWikipediaScript('User:קיפודנחש/searchPersistence.js');

// w:fr:Utilisateur:Od1n/AddLinksJavaScriptPage.js if (contentModel === 'javascript') { mw.loader.using('mediawiki.util', function {		$(function  { var link = document.createElement('a'); // used but not inserted into DOM var stringClasses = [ 's1', 's2' ]; $('.mw-highlight').find('.nx').each(function (_, identifierElement) {				var identifier = identifierElement.textContent;

if (identifier === 'importScript' || identifier === 'importStylesheet') { var parenthesis = identifierElement.nextSibling; var string = parenthesis && parenthesis.nextSibling; if (!(parenthesis && parenthesis.className === 'p'							&& parenthesis.textContent === '(' && string							&& stringClasses.indexOf(string.className) !== -1))						return;					string.innerHTML = string.innerHTML.replace(/^(['"])(.+\.(?:js|css))(['"])$/, function (match, quote1, path, quote2) { link.href = mw.util.getUrl(path); link.textContent = path;

return quote1 + link.outerHTML + quote2; });				}			});

});	}); }

if (contentModel === 'Scribunto' && mw.config.get('wgCurRevisionId') === 0 && /\/sandbox$/.test(pageName)) { $(function {		var sandboxOf = pageName.replace(/\/sandbox$/, );		insertWikitext(sandboxOf);		$('#wpSummary').val('copy of ' + sandboxOf.replace(/_/g,' ') + );	}); }

window.unPercentify = function { location.pathname = decodeURIComponent(location.pathname); };

window.getNameOf = function(obj) { return Object.getPrototypeOf(obj).constructor.name; };

// Adds a button after the 'refresh' link in module testcases produced by // Module:UnitTests to hide all successful testcases (making it easier to // find the failing ones). if (namespace === 'Module') { const $unitTests = $('table.unit-tests'); if ($unitTests.length > 2) { const $hideSuccessesButton = $(' ') .addClass('unit-tests-hide-successes') .css('cursor', 'pointer') .click(function {				this.successesShown = !this.successesShown;				this.showHideFunc;			}) .html('(hide successes)'); hideSuccessesButton = $hideSuccessesButton[0]; hideSuccessesButton.successesShown = true; hideSuccessesButton.showHideFunc = function { $unitTests.toggleClass('unit-tests-hide-passing', !this.successesShown); this.textContent = this.successesShown ? '(hide successes)' : '(show successes)'; };		hideSuccessesButton.showHideFunc; $('.unit-tests-refresh') .closest('p') .append(' ') .append($hideSuccessesButton); } }

window.getSearchTitles = function getSearchTitles { return $('.mw-search-result-heading a').get .map(function (elem) {			return elem.textContent;		}); };

if (mw.config.get('wgNamespaceNumber') === 0 && mw.config.get('wgRevisionId') === 0) importScript('User:Erutuon/scripts/graveToAcuteRedirect.js'); }); // IIFE

// Reduce names of request categories to language name. $(function {	const match = mw.config.get('wgPageName').match(/Category:Requests_for_(.+?)_by_language/);	if (match) {		const regex = new RegExp("Requests for " + match[1].replace(/_/g, " ") + " in (.+?) entries", "g");		$('.CategoryTreeItem a')			.get			.forEach(function(e) { e.textContent = e.textContent.replace(regex, '$1'); });	} });

if ([ "edit", "submit" ].includes(mw.config.get("wgAction"))) { importScript('User:Erutuon/scripts/cleanup.js'); //Linkback: User:Erutuon/scripts/cleanup.js Added by Script installer }

importScript( 'User:So9q/CreateTranslation.js' ); // Backlink: User:So9q/CreateTranslation.js

if (document.querySelector('[lang="mh"]')) { importScript('User:Erutuon/scripts/Marshallese.js'); // User:Erutuon/scripts/Marshallese.js }

window.catfixReconstructedAsterisk = true;

(function findParserReport {	const contentElement = document.getElementById("content");	if (contentElement) {		const iter = document.createNodeIterator(contentElement, NodeFilter.SHOW_COMMENT, function { return NodeFilter.FILTER_ACCEPT; });		var node;		while ((node = iter.nextNode)) {			const value = node.nodeValue;			if (value.includes("NewPP limit report")) {				console.info(value.trim); break;			}		}		} });

// Various fixes for the trees generated by Module:family tree. // This code works with old classes (beginning with familytree) and new classes // (beginning with ft). $(function {	// Show the top toggle.	$('.ft-toptoggle, .familytree-toptoggle').css('display', '');	var customtogglePrefix = 'ft';	// Initialize the text of the toggles.	$('.ftree, .familytree').get.forEach(function (tree) { var isCollapsed = tree.classList.contains('mw-collapsed'); var toggles = $(tree).find('.ft-toggle, .familytree-toggle'); if (toggles[0]) { var customToggleClass = Array.prototype.filter.call(toggles[0].classList, function (className) {				return className.indexOf('mw-customtoggle-' + customtogglePrefix) === 0;			})[0]; if (customToggleClass) { var toggledElement = $('#' + customToggleClass.replace('mw-customtoggle', 'mw-customcollapsible')); if (toggledElement) { toggles.html(toggledElement.data(isCollapsed ? 'expandtext' : 'collapsetext')); }			}		}	});	// Change the text in the custom toggles generated by Module:family tree	// when they are clicked.	$('.mw-collapsible').on('beforeExpand.mw-collapsible beforeCollapse.mw-collapsible', function (event) { if (this.id.indexOf('mw-customcollapsible-' + customtogglePrefix) === 0) { var toggle = $('.' + this.id.replace('mw-customcollapsible', 'mw-customtoggle')); if (event.type === 'beforeExpand') { toggle.html(this.dataset.collapsetext); } else { // beforeCollapse toggle.html(this.dataset.expandtext); }           event.stopPropagation; }   }); });

$(function {	Array.from(document.querySelectorAll('.mw-widget-searchInputWidget .oo-ui-inputWidget-input')).forEach(function(e) { console.log(e.value + "\nhttps://en.wiktionary.org?search=" + encodeURIComponent(e.value)); });   const url = new URL("https:" + mw.config.get("wgServer") + mw.config.get("wgScript"));    const params = url.searchParams;    const pageName = mw.config.get("wgPageName");    params.set("title", "Special:ExpandTemplates");    if (pageName === "Special:ExpandTemplates") {    	["wpContextTitle", "wpInput"].forEach(function(name) { params.set(name, document.getElementsByName(name)[0].value); });   } else {	    params.set("wpContextTitle", pageName);	    params.set( "wpInput", ""	   );    }    console.log("Open wikitext in Special:ExpandTemplates:\n" + url.toString); });

window.GPE = window.GPE || {}; window.GPE.initialDeleteReason = '--explanation of deletion--';

mw.loader.using(['mediawiki.cookie', 'jquery.textSelection']).done(function {   mw.hook('enwiktionary.edittools.addCategory').fire([ {name: 'Polabian', insertBefore: null, html: ' A a Ă ă Å å Ą ą B b B́ b́ C c Ć ć Č č D d Ď ď Ʒ ʒ Ʒ́ ʒ́ E e Ė ė Ĕ ĕ F f G g Ǵ ǵ H h Χ χ Χ́ χ́ I i J j K k Ḱ ḱ L l Ľ ľ M m Ḿ ḿ N n Ń ń O o Ö ö Ǫ ǫ P p Ṕ ṕ R r Ŕ ŕ S s Ś ś Š š T t Ť ť U u Ü ü V v V́ v́ Z z Ź ź Ž ž ai̯ au̯ åi̯ åu̯ oi̯ üi̯ '}, { name: 'Slovincian', insertBefore: 'Polabian', html: '...' } ]); });

window.noDefaultVisibilityToggles = true;

mw.loader.using(['ext.gadget.VisibilityToggles'], function {	importScript('User:Erutuon/scripts/defaultVisibilityToggles.js'); });

function makeLocalScriptUrl(title) { const url = new URL("https:" + mw.config.get("wgServer") + mw.config.get("wgScriptPath")); url.search = new URLSearchParams({		"title": title,		"action": "raw",		"ctype": "text/javascript",	}); return url; }

mw.loader.using([	"ext.gadget.Editor", "ext.gadget.LegacyScriptsNewNode", "mediawiki.cookie",	"ext.gadget.LanguageUtils", "mediawiki.util" ]) .then(function {	importScript("User:Erutuon/scripts/TranslationAdder-Data.js");	importScript('User:Erutuon/scripts/TranslationAdder.js'); }) .fail(console.error);

importScript("User:Erutuon/scripts/todo-lists.js"); importScript('w:User:Jackmcbarn/advancedtemplatesandbox.js'); // Linkback: w:User:Jackmcbarn/advancedtemplatesandbox.js

//

window.accelEverywhere = true;

window.noDefinitionLineFragmentAddition = true;