MediaWiki:Gadget-Mabel.js

From AIOWiki
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
function getCat() {
    var cat = "";
    var cByAPattern=new RegExp("Episodes with (.)+ voiced by (.)+");

    if ($("#wpTextbox1").val() != "") return "";
    if (wgCanonicalNamespace == 'Category') {
		if (wgTitle.search(/Episodes written by/i) >= 0)                    cat = 'episode writers category}}';
		else if (wgTitle.search(/Actors who have voiced/i) >= 0)            cat = 'Actors who voiced}}';
		else if (wgTitle.search(/Episodes directed by/i) >= 0)  		    cat = 'Episode directors category}}';
		else if (wgTitle.search(/Episodes produced by/i) >= 0)			    cat = 'episode producers category}}';
		else if (wgTitle.search(/Episodes with sound design by/i) >= 0)	    cat = 'episode sound designers category}}';
		else if (wgTitle.search(/Episodes with music by/i) >= 0)			cat = 'episode music category}}';
		else if (wgTitle.search(/Episodes with theme of/i) >= 0)    		cat = 'episode theme category}}';
		else if (wgTitle.search(/Episodes with quote/i) >= 0)			    cat = 'Episode quotes by character}}';
		else if (wgTitle.search(/Episodes with acting by/i) >= 0)		    cat = 'Episode actors category}}';
    	else if (wgTitle.search(/Episodes with mention of/i) >= 0)		    cat = 'Episode mentioned character by character}}';
        else if (wgTitle.search(/Episodes with references from/i) >= 0)    	cat = 'Scripture category}}';
		else if (wgTitle.search(/Character category tracking for/i) >= 0)   cat = 'Character tracking}}';
		else if (wgTitle.search(/Episodes in/i) >= 0)       			    cat = 'Episodes in album category}}';
		else if (wgTitle.search(/Actor category tracking for/i) >= 0)		cat = 'Actor tracking}}';
        else if (wgTitle.search(/Episodes that mention/i) >=0)              cat = 'Episode character mention category}}';
		else if (cByAPattern.test(wgTitle))			                        cat = 'Episode character by actor category}}';
		else if (wgTitle.search(/Episodes with/i) >= 0)			            cat = 'episode character category}}';
    	else if (wgTitle.search(/Actors in/i) >= 0)			                cat = 'Actors in category}}';
    	else if (wgTitle.search(/Characters in/i) >= 0)			            cat = 'Characters in category}}';
        else if (wgTitle.search(/Documentaries with/i) >=0)                 cat = 'Documentary appearances category}}';
 		else if (wgTitle.search(/Podcasts with/i) >=0)                 		cat = 'podcast guest category}}';
	}
    
    //check if a category was found
    if (cat != "") {
        document.editform.wpSummary.value = "Page created with Mabel";
        $("#wpTextbox1").val('{{'+cat);
        $("#wpSave").click()
    }
}

var customizeToolbar = function() {
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        section: 'main',
        group: 'format',
    	tools: {
    		"mabel": {
    			label: 'Mabel',
    			type: 'button',
    			icon: 'https://www.aiowiki.com/w/images/thumb/7/7d/Eugenehead.gif/25px-Eugenehead.gif',
    			action: {
    				type: 'encapsulate',
    				options: {
    					pre: getCat(),
    				}
    			}
    		}
    	}
    } );
};

if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
	mw.loader.using( 'user.options' ).then( function () {
		// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ), $.ready
			).then( customizeToolbar );
		}
	} );
}