Jump to content

User:WikiMacaroons/shortdesc.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
( function () {
	var shortdesc = $(mw.util.addPortletLink('p-personal','#','Short Description','Add-a-Short-Description','Add a Short Description','','#pt-mytalk'));
	$( shortdesc ).click( function() {
		if(document.getElementById("mw-content-text").innerHTML.includes('<div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">')){
			alert("This page already has a short description.");
		}
		else{
			var shortd = prompt("Enter Short Description", "");
		  if (shortd === null || shortd === "") {
		    
		  } else {
			   var params = {
					action: 'edit',
					title: mw.config.get("wgPageName"),
					prependtext: `{{Short description|"+shortd+"}}
					`,
					summary: 'Short Description automatically added with [[User:WikiMacaroons/AutoShortDesc|AutoShortDesc]]',
					format: 'json'
				};
				api = new mw.Api();
			
			api.postWithToken( 'csrf', params ).done( function ( data ) {
				//alert( data );
			} );
		  }
			}
	});
}() );