User:DannyS712 test/DYK.js

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{ if ( (window.location.href.indexOf("Template:Did_you_know_nominations/") > -1) && (mw.config.get( 'wgAction' ) === 'view' || mw.config.get( 'wgAction' ) === 'edit' ) ) { $( '#ca-DYK' ).show; }	$(document).off( "mousemove" ); } function claim{ var get_page = { action: 'query', titles: mw.config.get( 'wgPageName' ), prop: 'revisions', rvpropr: 'content', format: 'jsonfm', formatversion: 2 };   $.get( mw.config.get( 'wgScriptPath' ) + '/api.php', get_page, function( got_page ) {    	console.log ( got_page );    	var text = got_page.query.pages.revisions.content;    	console.log( text );        var new_page = text.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         = DannyS712 test (talk) 00:34, 30 December 2018 (UTC)}}');        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;	        } ); }   } ); }