User:DannyS712/DYK claim.js

// Install the newest version with: // // or with //  // // If forking this script, please note my contributions / give me credit

mw.loader.using( 'mediawiki.util', function {    $(document).ready( function  { var link = mw.util.addPortletLink ( 'p-views', '#', 'Claim', 'ca-DYK', 'Claim this DYK'); $( '#ca-DYK' ).hide; $( link ).click( function ( event ) {   	    event.preventDefault;        	claim;    	} ); $(document).on( "mousemove", check ); } ); } ); function check{ //$(document).off( "mousemove", check ); if ( (window.location.href.indexOf("Template:Did_you_know_nominations/") > -1) && (mw.config.get( 'wgAction' ) === 'view' || mw.config.get( 'wgAction' ) === 'edit' ) ) { $( '#ca-DYK' ).show; } } function claim{ var get_page = { action: 'raw', title: mw.config.get( 'wgPageName' ), };   $.get( mw.config.get( 'wgScriptPath' ) + '/index.php', get_page, function( got_page ) {    	var new_page = got_page.replace( '', '{' + '{DYK checklist\n\n|newness      = \n|length       = \n|eligibilityother = \n|sourced      = \n|neutral      = \n|plagiarismfree = \n|policyother  = \n|hookcited    = \n|hookinterest = \n|hookother    = \n|picfree      = \n|picused      = \n|picclear     = \n|qpq          = \n|status       = \n|comments     = \n|sign         = ' + '}}');        if ( new_page === got_page ) alert('This DYK review could not be automatically claimed.');		else {	        var send_claim = {	            action: 'edit',	            pageid: mw.config.get( 'wgArticleId' ),	            text: new_page,	            summary: 'DYK claimed!',	            token: mw.user.tokens.get( 'csrfToken' )	        };	        $.when( $.post( mw.config.get( 'wgScriptPath' ) + '/api.php', send_claim, function( claim_response ){ } ) ).done( function { alert('DYK review claimed!'); location.reload; } );		}   } ); }