User:Xbony2/common/translatation admins toolbar.js

/** * Creates a new button in WikiEditor, for FTB Wiki translation mark-up. This is only for translation administrators. * * Don't use Internet Explorer btw. * * @author User:Xbony2 * Based off of: * * mw:Extension:WikiEditor/Toolbar customization * */ var customizeToolbar = function{ $('#wpTextbox1').wikiEditor('addToToolbar', {		'section': 'main',		'group': 'insert',		'tools': {			'mark-up': {				label: 'Translation markup',				type: 'button',				icon: '//hydra-media.cursecdn.com/ftb.gamepedia.com/c/c8/Icon_String.png',				action: {					type: 'callback',					execute: function(context){						var wikitext = document.getElementById('wpTextbox1').innerHTML;						wikitext = wikitext.replace(/\[\[Category:.+\]\]/g, function(match){ return match.replace(/\]\]/g, ']]'); });						['br', 'languages'].forEach(function(element){ wikitext = wikitext.replace(new RegExp('&lt;' + element + '\/&gt;', 'g'), '&lt;' + element + ' \/&gt;'); });						var formattedNamespaces = mw.config.get('wgFormattedNamespaces');						var namespaces = [];						for(var key in formattedNamespaces){							namespaces.push(formattedNamespaces[key]);						}						wikitext = wikitext.replace(/\[\[.+\]\]/g, function(match){ console.log(match); var found = false; namespaces.forEach(function(namespace){								if(match.startsWith(namespace, 2)){									found = true; //TODO: fix shit								}							}); if(!found) return match.replace(/\[\[/g, ""); else return match; });						document.getElementById('wpTextbox1').innerHTML = wikitext;					}				}			}		}	}); };

/* Check if view is in edit mode and adds toolbar.*/ if($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1){ mw.loader.using('user.options', function{		if(mw.user.options.get('usebetatoolbar') == 1){			$.when(mw.loader.using('ext.wikiEditor.toolbar'), $.ready).then(customizeToolbar);		}	}); }