User:JJPMaster/prettyImport.js

// This improves the interface of [[Special:Import]]
if (mw.config.get("wgCanonicalNamespace") != "Special") {
	mw.util.addPortletLink("p-tb", `/wiki/Special:Import?page=${mw.config.get("wgPageName")}`, "Import", "p-import", "Import this page from another wiki");
}
var params = new URLSearchParams(window.location.search);
const isNotXMLer = /(transwiki|sysop)/.test(mw.config.get('wgUserGroups').toString());
if (mw.config.get("wgCanonicalSpecialPageName") == "Import") {
	var myDropdown = document.getElementsByClassName('oo-ui-dropdownWidget-handle')[0];
	var myButton = document.getElementsByClassName("oo-ui-buttonElement-button")[0];
	var index = !isNotXMLer ? 3 : 24;
	// Automatically enables "include all revisions"
	document.getElementById(`ooui-php-${index + 1}`).checked = true;
	document.getElementById(`ooui-php-${index + 2}`).checked = !!params.get("cascading");
	// Replaces link names when dropdown is opened
	myDropdown.addEventListener("click", () => {
		replaceLinks();
	});
	myButton.addEventListener("click", (e) => {
		if(document.getElementById(`ooui-php-${index + 2}`).checked)
			if(!confirm("Are you sure you want to import this and all of its transcluded pages?")) e.preventDefault();
	});
	document.getElementById(`ooui-php-${index}`).value = params.get("page");
	document.getElementById(`ooui-php-${index + 4}`).value = params.get("summary");
}
function replaceLinks() {
	var elements = document.getElementById("ooui-6").querySelectorAll('.oo-ui-labelElement-label'); 
	var newElements = ["English Wikipedia", "English Wikisource", "English Wikiquote", "English Wikiversity", "English Wiktionary", "English Wikinews", "Meta-Wiki", "Simple English Wikibooks", "Wikispecies", "Multilingual Wikisource", "Wikimedia Commons"];
	for (var i = 0; i < elements.length; i++) {
		elements[i].innerText = newElements[i];
	}
	return;
}