User:Bility/statusupdate.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.
if (mw.config.get('wgPageName')=='User:'+mw.config.get('wgUserName') || mw.config.get('wgPageName')=='User_talk:'+mw.config.get('wgUserName')) {
$(document).ready(function() {
	if (typeof hideStatus == 'undefined') { hideStatus = false; };
	if ($('#user-status')) {
		if (hideStatus) { $('#user-status').attr('style','visibility:visible'); };
		$('#user-status span').attr('style','cursor:pointer');
		$('#user-status span').click(function() {
			var statusText = $(this).html();
			var summ = 'updating status';
			var token;

			$.ajax({
				url: '/w/api.php?action=query&prop=info&intoken=edit&titles=Main_page&format=json',
				success: function(data) { token = data.query.pages[Object.keys(data.query.pages)].edittoken.replace(/\+\\$/g,'%2B%5C'); },
				dataType: 'json',
				async: false
			});

			$.ajax({
				type: 'POST',
				url: '/w/api.php?action=edit&title=User:'+mw.config.get('wgUserName')+'/Status&summary='+summ+'&minor=1&recreate=1&text='+statusText+'&token='+token,
				async: false
			});

			window.location.reload();
		});
	};
});
};