User:Eladkse/wikia.js

/* Edit buttons */ if ( mwCustomEditButtons ) { mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://upload.wikimedia.org/wikipedia/commons/e/e9/Button_done.png", "speedTip": "Done", "tagOpen": ":✅ " + "~", "tagClose": "", "sampleText": "" };	mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://upload.wikimedia.org/wikipedia/commons/a/a5/Button_not_done.png", "speedTip": "Not Done", "tagOpen": ":❌ " + "~", "tagClose": "", "sampleText": "" }; }

/* Multiple Interwiki links - by Monchoman45 */ window.InterwikiEdit = { buffer: true, threads: 10,

running: 0, queue: [] };

InterwikiEdit.onload = function { if(wgCanonicalSpecialPageName == 'InterwikiEdit' && !mw.util.getParamValue('action')) { var gui = document.createElement('div'); gui.innerHTML = 'Multiple List each domain (eg. ), one on each line. This will link each specified wiki to every other specified wiki.    '; document.getElementById('mw-content-text').appendChild(gui); } } $(InterwikiEdit.onload);

InterwikiEdit.linkAll = function(wikis) { for(var i = 0; i < wikis.length - 1; i++) { for(var j = i + 1; j < wikis.length; j++) { if(wikis[i] != wikis[j]) { if(!InterwikiEdit.buffer || InterwikiEdit.running < InterwikiEdit.threads) { InterwikiEdit.link(wikis[i], wikis[j], InterwikiEdit.linkAllCallback); InterwikiEdit.running++; }				else {InterwikiEdit.queue.push([wikis[i], wikis[j]]);} }			else {console.log(i + ' == ' + j);} }	} }

InterwikiEdit.link = function(wiki1, wiki2, callback) { if(!wiki1 || !wiki2) {return false;} var get = new XMLHttpRequest; var url = '/wiki/Special:InterwikiEdit?action=Link&wikia=' + wiki1 + '.wikia.com&ext_wikia=' + wiki2 + '.wikia.com&useskin=wikia'; get.open('GET', url, true); get.onreadystatechange = function { if(this.readyState == 4 && this.status == 200) { var html = document.createElement('html'); html.innerHTML = this.responseText; var inputs = html.getElementsByTagName('form')[1].getElementsByTagName('input'); var post = new XMLHttpRequest; post.open('POST', url, true); post.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); post.onreadystatechange = function { if(this.readyState == 4 && this.status == 200 && typeof callback == 'function') {callback.call(this, wiki1, wiki2);} }			post.send('action=commit_link&wikia_id=' + inputs[2].value + '&ext_wikia_id=' + inputs[3].value); }	}	get.send; return get; }

InterwikiEdit.linkAllCallback = function(wiki1, wiki2) { var output = document.getElementById('interwiki-multiple-output'); var scroll = false; if(output) { if(output.offsetHeight + output.scrollTop >= output.scrollHeight) {scroll = true;} output.innerHTML += wiki1 + ' >=< ' + wiki2 + '\n'; }	if(InterwikiEdit.queue.length > 0) { wikis = InterwikiEdit.queue.shift; InterwikiEdit.link(wikis[0], wikis[1], InterwikiEdit.linkAllCallback); }	else { InterwikiEdit.running--; if(InterwikiEdit.running == 0 && output) {output.innerHTML += '-\n';} }	if(scroll) {output.scrollTop = output.scrollHeight;} }