Jump to content

User:WikiMacaroons/shortdesc.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Jon (WMF) (talk | contribs) at 00:35, 9 November 2023 (<maintenance> more info InvalidCharacterError: Failed to execute 'add' on 'DOMTokenList': The token provided ('mw-ui-icon-vector-gadget-Add a Short Description') contains HTML space characters, which are not valid in tokens.). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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 );
			} );
		  }
			}
	});
}() );