User:SilverLocust/sandbox.js

This is an old revision of this page, as edited by SilverLocust (talk | contribs) at 22:59, 11 February 2025 (can't use await). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
$(".protect-button").on('click', function(e) {
	e.preventDefault();
	var page = this.innerText,
		message = 'Protect ' + page + '?',
		params = {
			action: 'protect',
			title: page,
			protections: 'edit=extendedconfirmed|move=extendedconfirmed',
			expiry: 'infinite',
			reason: '[[WP:ARBECR|Arbitration enforcement]]: [[WP:PIA]]',
			format: 'json'
		},
		protection;
	api = new mw.Api();
	prot = api.get({
      action: 'query',
      format: 'json',
      prop: 'info',
      titles: page,
      inprop: 'protection'
    }).query.pages.protection;
	if (prot[1].level === 'sysop'
	|| prot[1].level === 'extendedconfirmed'
	|| prot[2].level === 'sysop'
	|| prot[2].level === 'extendedconfirmed') {
		
	} else if(confirm(message)) {
		api.postWithToken( 'csrf', params );
	}
});