michalpawl / WikiLang

// ==UserScript==
// @name        WikiLang
// @namespace   michalpawl
// @author      MacGyver
// @description Makes your preferred language links easy to find on Wikimedia pages. Config available via Script Commands.
// @icon        data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAAA9CAYAAAAd1W/BAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVRoge17d3hU1fP359y7vSbZZFM2vW56SAhJKKGE3qSjoIIgiiAqKoiKioANBEVAFBEriCjSBKSX0ElISEglvfdsNtvr+8dml4TQ/H6f9/e+f/zO8+xz9969Z87MZ+bMmZlzFvjf9v+uxcnl/hNGJA7+b2gEBnqHJET7y//T/vR/M/h/05YvnPTM0udHHXx6UuqLEcHe0Xq19lRpTbP239BY/caTC1e/Nn3fM5OHvDZmcJ+xcRGB3IaO+rzGRrXxcWmQf886AIA9bmh8lNRNEurnLXV3EYs8hAKeO1/Ik3Yo1OoTF6+998ehS0UP6vzCjLShC54eedDXy1VoZyOvtCb/6D+Z8z7/4eC1x2EgMjKS9cnS8eVJcaFeNhIUAIKGFmVTXnHVn4dOXt+x59CFrEfRYTzsxwUz02aHBXvLnUU8KYfF9GRz2VI2kyUVCnieMi83jpNICBAKhFA9rkKRkPnHoUuT70dz0KBwzwmj+n3dXXhQNKJCAyNcnCWHuCLB0jWbdu1+FOMTB4c90y82xAsAvtuTjbQBAQjyd4Onu0Tq5eG2KKVv5PzZk9NOHD2f+cu2Hw/9CcD6rwD48JWZS+Y9OWwTi8UgDkZ7CUtACOl2tT13dhYNA0ABsNxDlp42LGV7XIS/fMVnl3H2SgsEfCZmT/LF80/1hbeHq3T+rFE7+QJ+9IqPtr97n/6OFhXqs9TOC8DA1IUXsHZZDCaMCAchFIQCATslMXJCct+oCU9NHJpXWFq7a++es1+fyszs6MHQgwaYM3XIRnmwzBcA1Fo9MnJqIPN0BkXRvTROCAVQd+9ZDBbr6Lmsne3t7T0G+2j57DVPT0p9/qd9+djwXQP6JwjAYFDYubcRHK4eSfE+YLM5jITo0IFx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oDpeLvd9N7+Hpcd/T7ARKpdIKoPlfAwAAKzcd+Hj3ly+MyM0rTo2LsS01Jy6UQaE0Y+7MGEdUaB+spqYW9dW3wbSqWncfz9qyceeJzwBow0MDWgghPmIhD1IJD5+uHAI/b1eA0HCVcCAUsvHL10/3yOy6F17aO5S64rJqhAUHdvv9bnmsZx/awQ8ANDc3GgHo/iMAAFhOns1ZPnOS8HRLu4Lv5uqGqeOi8ffJO5B5SRwDG4xGFORmQsjstBYX3Tl8KD373SMncm7bibQrOupBqD5pg4KRlhqGu7vMBPExXnj/dUGXBfUWvrKyEk2NzbdcuCqPjOvnQSgaNIMBirJ9CEXDSkd00H4AAAHISURBVCgwaCZoBhMUgwkmgwMLoWDQ61BdWVB2P8EeOxv84eDVa4FBHjtptmCJ1M0DDCaNd5cOhX0/705pCXSKSmg6Wst2nbq1ftuuM9/inr+pGA2GjNLymrHBQf5dmrkraKTcC66ufNy6XQSTyQgKZlgsBljNRljNRhCLxphVeGf5z4esF3xcXbwYLFrAYTKEDCYloGlaQFFEwKRs31ksmi8WcvkcARdiIRctBrWxqqpu638FAADsOX7pnRB/6bD8ouLIyIhIRITJoNHqUZB/FXyqQ3/5euEPB49nv5+eVdJrrgFAXV3rTb26EZnZShBYQWDpOmRlArEaIXXhIUgiAEURqDR6a3VdW0tHp6ZJrzc25pc2HDudXpRzOr0o5zFYZXh4CJyjAny9RWK2j8ZoqP/ndN6N+734rytC86cNnD5n+uDdGqOAwWSzwaU70dbWem3v35kf/nzg0rFHdKe2fDD74JDk0PEKpUbR3KZuNpqM9RqNoUmjMzR2dOobG1oUDeW1TY3XcqrLGhvbSwH8q7/S/Y+0D5ZM3FB0cq0u58iHyi9XPrWue97/GI0A8AUg/r/E3v9MG5QQHj8kJSj40W/+b/v/uv0fGKCmS/PsrdkAAAAASUVORK5CYII=

// @require     https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_registerMenuCommand

// @match       *://*.wikipedia.org/*
// @match       *://*.wiktionary.org/*
// @match       *://*.wikiquote.org/*
// @match       *://*.wikibooks.org/*
// @match       *://*.wikisource.org/*
// @match       *://*.wikinews.org/*
// @match       *://*.wikiversity.org/*
// @match       *://*.wikivoyage.org/*
// @match       *://*.wikidata.org/*
// @match       *://*.wikimedia.org/*
// @match       *://*.mediawiki.org/*

// @downloadURL https://openuserjs.org/src/scripts/michalpawl/WikiLang.user.js
// @updateURL   https://openuserjs.org/meta/michalpawl/WikiLang.meta.js

// @version     1.0.14

// @license     CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
// @license     GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// ==/UserScript==


const namelist = ['- Select language -','Abkhazian','Achinese','Afar','Afrikaans','Akan','Albanian','Alemannisch','Amharic','Arabic','Aragonese','Aramaic','Armenian','Aromanian','Arpitan','Assamese','Asturian','Avaric','Aymara','Azerbaijani','Bambara','Banjar','Basa Banyumasan','Bashkir','Basque','Bavarian','Belarusian','Bengali','Bhojpuri','Bikol Central','Bishnupriya','Bislama','Bosnian','Breton','Buginese','Bulgarian','Burmese','Buryat','Cantonese','Catalan','Cebuano','Central Kurdish','Chamorro','Chavacanode Zamboanga','Chechen','Cherokee','Cheyenne','Chinese','Chinese (Min Nan)','Choctaw','Church Slavic','Chuvash','Classical Chinese','Colognian','Cornish','Corsican','Cree','Creek','Crimean Turkish','Croatian','Czech','Danish','Divehi','Dutch','Dzongkha','Eastern Mari','Egyptian Arabic','Emiliano-Romagnolo','English','Erzya','Esperanto','Estonian','Ewe','Extremaduran','Faroese','Fiji Hindi','Fijian','Finnish','French','Friulian','Fulah','Gagauz','Galician','Gan Chinese','Ganda','Georgian','German','Gilaki','Goan Konkani','Gothic','Greek','Guarani','Gujarati','Haitian','Hakka Chinese','Hausa','Hawaiian','Hebrew','Herero','Hindi','Hiri Motu','Hungarian','Icelandic','Ido','Igbo','Iloko','Indonesian','Interlingua','Interlingue','Inuktitut','Inupiaq','Irish','Italian','Japanese','Javanese','Kabardian','Kabyle','Kalaallisut','Kalmyk','Kannada','Kanuri','Karachay-Balkar','Kara-Kalpak','Kashmiri','Kashubian','Kazakh','Khmer','Kikuyu','Kinyarwanda','Komi','Komi-Permyak','Kongo','Korean','Kuanyama','Kurdish','Kyrgyz','Ladino','Lak','Lao','Latgalian','Latin','Latvian','Lezghian','Ligurian','Limburgish','Lingala','Lithuanian','Lojban','Lombard','Low German','Low Saxon (Netherlands)','Lower Sorbian','Luxembourgish','Macedonian','Maithili','Malagasy','Malay','Malayalam','Maltese','Manx','Maori','Marathi','Marshallese','Mazanderani','Min Dong Chinese','Minangkabau','Mingrelian','Mirandese','Moksha','Moldovan','Mongolian','Nahuatl','Nauru','Navajo','Ndonga','Neapolitan','Nepali','Newari','Norfuk/Pitkern','Northern Frisian','Northern Luri','Northern Sami','Northern Sotho','Norwegian','Norwegian Nynorsk','Nouormand','Novial','Nyanja','Occitan','Old English','Oriya','Oromo','Ossetic','Palatine German','Pali','Pampanga','Pangasinan','Papiamento','Pashto','Pennsylvania German','Persian','Picard','Piedmontese','Polish','Pontic','Portuguese','Punjabi','Quechua','Romani','Romanian','Romansh','Rundi','Russian','Rusyn','Sakha','Samoan','Samogitian','Sango','Sanskrit','Sardinian','Saterland Frisian','Scots','Scottish Gaelic','Serbian','Serbo-Croatian','Shona','Sichuan Yi','Sicilian','Silesian','Simple English','Sindhi','Sinhala','Slovak','Slovenian','Somali','South Azerbaijani','Southern Sotho','Spanish','Sranan Tongo','Sundanese','Swahili','Swati','Swedish','Tagalog','Tahitian','Tajik','Tamil','Tarantino','Taraskievica','Tatar','Telugu','Tetum','Thai','Tibetan','Tigrinya','Tok Pisin','Tongan','Tsonga','Tswana','Tumbuka','Turkish','Turkmen','Tuvinian','Twi','Udmurt','Ukrainian','Upper Sorbian','Urdu','Uyghur','Uzbek','Venda','Venetian','Veps','Vietnamese','Volapuk','Voro','Walloon','Waray','Welsh','West Flemish','Western Frisian','Western Mari','Western Punjabi','Wolof','Wu Chinese','Xhosa','Yiddish','Yoruba','Zazaki','Zeelandic','Zhuang','Zulu'];
const codelist = ['','ab','ace','aa','af','ak','sq','als','am','ar','an','arc','hy','roa-rup','frp','as','ast','av','ay','az','bm','bjn','map-bms','ba','eu','bar','be','bn','bh','bcl','bpy','bi','bs','br','bug','bg','my','bxr','zh-yue','ca','ceb','ckb','ch','cbk-zam','ce','chr','chy','zh','zh-min-nan','cho','cu','cv','zh-classical','ksh','kw','co','cr','mus','crh','hr','cs','da','dv','nl','dz','mhr','arz','eml','en','myv','eo','et','ee','ext','fo','hif','fj','fi','fr','fur','ff','gag','gl','gan','lg','ka','de','glk','gom','got','el','gn','gu','ht','hak','ha','haw','he','hz','hi','ho','hu','is','io','ig','ilo','id','ia','ie','iu','ik','ga','it','ja','jv','kbd','kab','kl','xal','kn','kr','krc','kaa','ks','csb','kk','km','ki','rw','kv','koi','kg','ko','kj','ku','ky','lad','lbe','lo','ltg','la','lv','lez','lij','li','ln','lt','jbo','lmo','nds','nds-nl','dsb','lb','mk','mai','mg','ms','ml','mt','gv','mi','mr','mh','mzn','cdo','min','xmf','mwl','mdf','mo','mn','nah','na','nv','ng','nap','ne','new','pih','frr','lrc','se','nso','no','nn','nrm','nov','ny','oc','ang','or','om','os','pfl','pi','pam','pag','pap','ps','pdc','fa','pcd','pms','pl','pnt','pt','pa','qu','rmy','ro','rm','rn','ru','rue','sah','sm','bat-smg','sg','sa','sc','stq','sco','gd','sr','sh','sn','ii','scn','szl','simple','sd','si','sk','sl','so','azb','st','es','srn','su','sw','ss','sv','tl','ty','tg','ta','roa-tara','be-x-old','tt','te','tet','th','bo','ti','tpi','to','ts','tn','tum','tr','tk','tyv','tw','udm','uk','hsb','ur','ug','uz','ve','vec','vep','vi','vo','fiu-vro','wa','war','cy','vls','fy','mrj','pnb','wo','wuu','xh','yi','yo','diq','zea','za','zu'];
const selector = 'LI.interlanguage-link.interwiki-';
const windowstyle = 'background-color: #d0e0ff;';
const framestyle = 'height: 75%; max-height: 440px; top: calc(50% - 215px); width: 300px; left: calc(50% - 150px); border: 1px solid #000; border-radius: 4px; margin: 0px; opacity: 1; overflow: auto; padding: 8px; position: fixed; z-index: 65536; display: block; right: auto; bottom: auto;';


function makeDraggable(element, handle)
{
	if (!element) return;
	var mdX = 0, mdY = 0, mdeX = 0, mdeY = 0;
	(handle?handle:element).onmousedown = function(event)
	{
		this.style.MozUserSelect = 'none';
		mdX = event.clientX;
		mdY = event.clientY;
		mdeX = element.offsetLeft;
		mdeY = element.offsetTop;
		onmouseup =()=> 
		{
			onmousemove = null;
			this.style.MozUserSelect = '';
		};
		onmousemove = ev =>
		{
			element.style.left = (mdeX + ev.clientX - mdX) + "px";
			element.style.top  = (mdeY + ev.clientY - mdY) + "px";
		};
	};
}


var settingsfields =
{
	langselect:
	{
		section: ['Language list', 'Choose which links to modify'],
		type: 'select',
		options: namelist,
		default: namelist[0],
		save: false,
	},
    add:
	{
		label: 'Add to list',
		type: 'button',
		click: function()
		{
			const langs = WikiLangConfig_field_languages.value.split(' ').filter(function(e){return(e&&codelist.includes(e));}).join(' ');
			WikiLangConfig_field_languages.value = langs;
			const newlang = GetLangCode(WikiLangConfig_field_langselect.value);
			if ( !newlang )
				alert('Please select which language to add.');
			else if ( langs.split(' ').indexOf(newlang) >= 0 )
				alert(WikiLangConfig_field_langselect.value + ' (' + newlang + ') is already on the list.');
			else
				WikiLangConfig_field_languages.value += langs ? ' '+newlang : newlang;
		},
	},
	languages:
	{
		type: 'text',
		default: 'pl en',
	},
	move_to_top:
	{
		section: ['Actions', 'Set how should the links be modified'],
		label: 'Move to top (in order as on the list above)',
		labelPos: 'right',
		type: 'checkbox',
		default: true,
	},
	apply_style:
	{
		label: 'Apply style:',
		labelPos: 'right',
		type: 'checkbox',
		default: true,
	},
	style:
	{
		type: 'textarea',
		default: 'font-weight: bold;\nfont-size: 120%;',
	},
};


GM_config.init(
{
	id: 'WikiLangConfig',
	title: 'WikiLang Settings',
	fields: settingsfields,
	events:
	{
		open: function()
		{
			makeDraggable(WikiLangConfig, WikiLangConfig_header);
			WikiLangConfig_header.style.cursor = 'move';
		},
		save: function()
		{
			apply();
		},
	},
	frame: document.body.appendChild(document.createElement('div')),
	css: '#WikiLangConfig { ' + windowstyle + ' } #WikiLangConfig_field_style { font-size: 13px; height: 6em; }',
});


function GetLangCode(LangName)
{
	var i = namelist.indexOf(LangName);
	return codelist[i<0?0:i];
}


function apply()
{
	GM_config.set('langselect',namelist[0]);

	const languages = GM_config.get('languages').split(' ');
	const style = GM_config.get('style');
	if ( !languages.length ) return;

	var query_A = GM_getValue('query_A','');
	var A_selected;

	if(query_A)
	{
		A_selected = document.querySelectorAll(query_A);
		for ( let i=0; i<A_selected.length; ++i )
			A_selected[i].removeAttribute('style');
	}

	query_A = selector + languages[languages.length-1] + ' > A';
	if ( GM_config.get('move_to_top') )
	{
		let list = document.querySelector('LI.interlanguage-link').parentElement;
		let elem;
		if ( elem = document.querySelector(selector + languages[languages.length-1]) )
			list.insertBefore(elem, list.children[0]);

		for ( let i=languages.length-2; i>=0; --i )
		{
			query_A = selector + languages[i] + ' > A, ' + query_A;
			if ( elem = document.querySelector(selector + languages[i]) )
				list.insertBefore(elem, list.children[0]);
		}
	}
	else
	{
		for ( let i=languages.length-2; i>=0; --i )
			query_A = selector + languages[i] + ' > A, ' + query_A;
	}

	GM_setValue('query_A',query_A);

	if ( GM_config.get('apply_style') && typeof style == 'string' )
	{
		A_selected = document.querySelectorAll(query_A);
		for ( let i=0; i<A_selected.length; ++i )
			A_selected[i].style = style;
	}
}


function openconfig()
{
	GM_config.open();
	WikiLangConfig.style = framestyle;
}


GM_registerMenuCommand('WikiLang Settings', openconfig);
apply();