User:SilverLocust/sandbox.js

This is an old revision of this page, as edited by SilverLocust (talk | contribs) at 23:08, 11 February 2025 (check later). 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'
    });
	if(confirm(message)) {
		prot = prot.query.pages[0].protection
		if (prot[0].level !== 'sysop'
		&& prot[0].level !== 'extendedconfirmed'
		&& prot[1].level !== 'sysop'
		&& prot[1].level !== 'extendedconfirmed') {
			api.postWithToken( 'csrf', params );
		}
	}
});