User:Kurniasan/vector.js

/* (function(lang) {	var api = new mw.Api;	var view = null;	function getView {		if (view === null) {			view = document.createElement('div');			view.setAttribute('id', 'lang-view');			view.style.backgroundColor = 'yellow';			view.style.padding = '4px 10px';			view.style.position = 'absolute';			var dv1 = document.createElement('div');			dv1.setAttribute('style', 'font-size: x-small; font-weight: bold; color: #dadada;');			view.appendChild(dv1);			var dv2 = document.createElement('div');			view.appendChild(dv2);			view.setLocal = function(s) {				dv1.textContent = s;			};			view.setForeign = function(s) {				dv2.textContent = s;			};			document.querySelector('#bodyContent').appendChild(view);		}		return view;	}	function show(a, title) {		var vw = getView;		vw.style.top = (a.offsetTop + a.offsetHeight) + 'px';		vw.style.left = a.offsetLeft + 'px';		vw.style.display = 'block';		vw.setLocal(a.title); vw.setForeign(title); }	function doneCallback(a) { return function(data) { if (data.query == null) return; for (var pgId in data.query.pages) { var lls = data.query.pages[pgId].langlinks; for (var i=0; i<lls.length; i++) { var ll = lls[i]; if (ll.lang == lang) { a.tmptitle = a.title; a.title = ''; setTimeout(function {							show(a, ll['*']);						}, 500); break; }				}				break; }		};	}	function getLangLink(e) { hideView(e); api.get({			action: 'query',			titles: this.title,			prop: 'langlinks',			lllimit: 500		}).done(doneCallback(this)).fail(function (e) {			console.log(e);		}); }	function hideView(e) { var vw = getView; vw.style.display = 'none'; if (e.target != null && e.target.tmptitle != null) { e.target.title = e.target.tmptitle; }	}	if (mw.config.get('wgNamespaceNumber') !== 0) return; var links = document.querySelectorAll('#mw-content-text a'); var pfx = '/wiki/'; for (var i=0; i<links.length; i++) { var a = links[i]; if (a.classList.contains('external') || !a.getAttribute('href').startsWith(pfx)) continue; a.addEventListener('mouseover', getLangLink); a.addEventListener('mouseout', hideView); } })('ms');