Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function addTags(tagtype, replacement){
	while ($('#mw-content-text').find('.'+replacement).length !== 0) {
		//console.log('2');
		var tag = $('#mw-content-text .' + replacement).first();
		tag.before('<'+tagtype+'>' + tag.html() + '</'+tagtype+'>');
		tag.remove();
	}
}

function removeTags(tagtype, replacement){
	while ($('#mw-content-text').find(tagtype).length !== 0) {
		//console.log('2');
		var tag = $('#mw-content-text ' + tagtype).first();
		tag.before('<span class="'+replacement+'">' + tag.html() + '</span>');
		tag.remove();
	}
}

var formatting = true;
$(document).ready(function(){
	if( mw.config.get( 'wgIsArticle' )) {//only on non-special view pages
		var portletLink = mw.util.addPortletLink('p-cactions', '#', 'Toggle formatting', 'ca-toggle-fmt', 'Toggle small, large and struck text', '');
		$(portletLink).click(function () {
			if (formatting) {
				removeTags('small', 'toggled_small');
				removeTags('big', 'toggled_big');
				removeTags('s', 'toggled_struck');
				console.log('Cleared formatting');
				formatting = false;
			} else {
				addTags('small', 'toggled_small');
				addTags('big', 'toggled_big');
				addTags('s', 'toggled_struck');
				console.log('Added formatting');
				formatting = true;
			}
		});
	}
});