User:Dominic/common.js

From Test Wiki
Revision as of 04:22, 16 May 2018 by Cy (talk | contribs) (Created page with "// Diblok if(mw.config.get("wgRelevantUserName")){ var username = mw.config.get("wgRelevantUserName"); var link = mw.util.addPortletLink( 'p-personal', '#',...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.
// Diblok 
if(mw.config.get("wgRelevantUserName")){
	var username = mw.config.get("wgRelevantUserName");
	var link = mw.util.addPortletLink(
    	'p-personal',
    	'#',
    	'Diblok4',
    	'pt-diblok4link',
	 	'Add tag diblok4'
	);
mw.util.addPortletLink(
    'p-cactions',
    mw.util.getUrl("Special:Block/" + username),
    'Blokir',
    'pt-abuseloglink',
    'View the Abuse Log',
    null,
    '#pt-watchlist'
);
}

$(link).click(function(){
	check = confirm("Do you want to give " + username + "tag?");
	if (check) {
		alertUser(username);
	}
});

function alertUser(username) {
	//If page already exists
	$.ajax( {
	    url: mw.util.wikiScript( 'api' ),
    	type: 'POST',
        dataType: 'json',
        data: {
	        format: 'json',
	        action: 'edit',
            title: 'User talk:' + username,
            summary: 'Add Welcome User',
            nocreate: 1,
            appendtext: '\n\n{{subst:' + 'Diblok4}}',
            token: mw.user.tokens.get( 'csrfToken' )
        }
    } ).done(console.log( "Add tag diblok: " + username )
    ).fail( function ( e, data ){
    	console.log( e.message );
    	console.log( JSON.stringify( data ) );
    });
    
    //If pages does not exist
    $.ajax( {
	    url: mw.util.wikiScript( 'api' ),
    	type: 'POST',
        dataType: 'json',
        data: {
	        format: 'json',
	        action: 'edit',
            title: 'User talk:' + username,
            summary: 'Welcome to User: ' + username,
            create: 1,
            text: '{{subst:' + 'welcome}}',
            token: mw.user.tokens.get( 'csrfToken' )
        }
    } ).done(console.log( "add tag diblok: " + username )
    ).fail( function ( e, data ){
    	console.log( e.message );
    	console.log( JSON.stringify( data ) );
    });
}