MediaWiki:Gadget-ContestHelper.js

From Nookipedia, the Animal Crossing wiki

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
 * Provides a pop-up dialog box to allow for easy submission of revisions to one of Nookipedia's contests.
 * Created by Jake on Nookipedia (https://nookipedia.com/wiki/User:Jake)
 * Licensed under CC BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0/)
 * (However, likely not applicable for use outside of Nookipedia)
 **/

// Check if revision eligible for contest submission
if(mw.config.get('wgPostEdit') == 'saved'){
    $.getJSON("/page/contest-api/?action=latest_revision", function(latest_revision){
        if(mw.config.get('wgRevisionId') == latest_revision.revision_id){
        	displayContestPrompt();
        }
    });
}

// Display prompt for eligible revision
function displayContestPrompt(){
	mw.notify( $( '<p style="font-weight:bold;">Would you like to submit this edit to the currently running edit contest?</p><button id="submit-button" style="margin-right:5px;">Yes</button><button id="hide-button" style="margin-right:5px;">No</button><button id="skip-button" style="margin-right:5px;">Later</button>', { autoHideSeconds: 20 } ) );
	$("#submit-button").click(submitRevision);
	$("#hide-button").click(hideRevision);
}

// Handle callbacks
function submitRevision(){
	var revision_data = {"revision_id":mw.config.get('wgRevisionId'), "hidden":0};
	var data = $.post('/page/contest-api/?action=submit_revision', revision_data, function(data, textStatus){
		if(data.status == 1){
			mw.notify( 'Your edit has been submitted successfully!' );
		}else{
			alert('There was a problem when submitting your edit. Please try your submission again using the contest dashboard.');
		}
	}, "json");
}

function hideRevision(){
	var revision_data = {"revision_id":mw.config.get('wgRevisionId'), "hidden":1};
	var data = $.post('/page/contest-api/?action=submit_revision', revision_data, function(data, textStatus){
		if(data.status == 1){
			mw.notify( 'Your edit has been hidden from this contest.' );
		}else{
			alert('There was a problem when hiding your edit. Please try hiding your submission again using the contest dashboard.');
		}
	}, "json");
}