User:Akodone/withoutiw.js

// Script for finding articles without interwiki in certain language, you can use it if you want mw.loader.using( 'mediawiki.api', function {	// Check if a page is called User:Your username/withoutinterwiki	const withoutIWpagename='withoutinterwiki';		if ( !(mw.config.get('wgNamespaceNumber')==2 && mw.config.get('wgTitle') == mw.config.get('wgUserName') + '/' + withoutIWpagename) ) {			return;	}	// Remove all noarticletext instances to clean the page	const noarticletext=document.getElementsByClassName('noarticletext');		Array.from( noarticletext ).forEach( function ( i ) { i.remove; });

// Create article structure const contentArea=document.getElementById('mw-content-text');

//first heading const poleWyboruH2=document.createElement('h2'); poleWyboruH2.textContent='Choose language'; contentArea.appendChild(poleWyboruH2); //div for select const poleWyboruDiv=document.createElement('div'); poleWyboruDiv.setAttribute('id', 'polewyborujezykow'); contentArea.appendChild(poleWyboruDiv); //second heading const wynikiH2=document.createElement('h2'); wynikiH2.textContent='Results'; contentArea.appendChild(wynikiH2); //ol for articles list const wynikiOL=document.createElement('ol'); wynikiOL.setAttribute('id', 'bezinterwikilista'); contentArea.appendChild(wynikiOL); // Variables var api = new mw.Api; //Create new api var chosenLanguage; //variable for chosen language //create Select var select=document.createElement('select'); select.setAttribute('id', 'languagechange'); select.setAttribute('name', 'languagechange'); poleWyboruDiv.appendChild(select); //create first option of the select var firstOption=document.createElement('option'); firstOption.setAttribute( 'value', 'none' ); firstOption.textContent='Choose language!'; select.appendChild(firstOption)

//create list of languages api.get({		action: "query",		meta: "siteinfo",		formatversion: "2",		siprop: "interwikimap"	}).done( function ( siteinforesult ) {		//create list of options		siteinforesult.query.interwikimap.forEach( function ( siresult ) { if ( siresult.language ) { var option=document.createElement('option'); option.setAttribute( 'value', siresult.prefix ); option.textContent=siresult.language; select.appendChild(option) }		})		//add Event listener to the select		select.addEventListener('change', function (e) { if (e.target.value!=='none') { chosenLanguage=e.target.value; cleanLi; getLinksWithoutIW(chosenLanguage); }		})	})

//Main function function getLinksWithoutIW (langToCheck, interwikicontinue) { //get list of all pages api.get({			action: "query",			list: "allpages",			formatversion: "2",			aplimit: "max",			apcontinue: interwikicontinue		}).done( function ( allpagesresult ) {			//get langlinks for each page			allpagesresult.query.allpages.forEach( function ( apresult ) { api.get({					action: "query",					prop: "langlinks",					titles: apresult.title,					formatversion: "2",					lllimit: "max"				}).done( function ( interwikiresult ) {								var iwarticle=interwikiresult.query.pages[0];								if(!(iwarticle.langlinks)) {						//if there are no langlinks, log the page						createLi( iwarticle.title );					} else {						//check if chosen language is in interwikis						var hasChosenLanguage;										iwarticle.langlinks.forEach( function ( iwresult ) { if ( iwresult.lang === langToCheck ) { hasChosenLanguage=true; }						})						//if the article has interwikis, but not in chosen language, log it											if (!hasChosenLanguage) {							createLi( iwarticle.title );						}						}				})//close second api call })//close forEach for allpagesresult.query.allpages			if (allpagesresult.continue) {				//call the function again to show all results				getLinksWithoutIW(chosenLanguage, allpagesresult.continue.apcontinue);			} else {				//Inform about updated list				mw.notify( 'List updated successfully!' );			}		})//close first api call }

//create li	function createLi (pagetitle) { var li=document.createElement('li'); li.setAttribute('class', 'bezinterwikilistitem'); li.innerHTML='' + pagetitle + ''; wynikiOL.appendChild(li); }

//function for removing li	function cleanLi { var listItem=document.getElementsByClassName('bezinterwikilistitem'); Array.from( listItem ).forEach( function ( i ) {			i.remove;		}); } } );