User:Nardog/ToggleBlocked.js

mw.config.get('wgAction') === 'history' && $.when($.ready, mw.loader.using(['mediawiki.util', 'mediawiki.storage'])).then( => {	if (!document.getElementById('p-tb')) return;	mw.loader.addStyleTag('.notblocked-hidden .mw-contributions-list > li:has(.history-user > .userlink:not(.user-blocked-indef, .user-blocked-partial, .user-blocked-temp)), .blocked-hidden .mw-contributions-list > li:has(.history-user > :is(.user-blocked-indef, .user-blocked-partial, .user-blocked-temp)){display:none}');	let data = mw.storage.session.getObject('toggleblocked');	let state = data?.[0] === mw.config.get('wgArticleId') && data[1] || 0;	let toggle = isInit => {		let bcl = document.body.classList;		switch (state) {			case 0:				if (isInit) return;				bcl.remove('blocked-hidden');				portlet.textContent = 'Hide not blocked';				break;			case 1:				bcl.add('notblocked-hidden');				portlet.textContent = 'Hide blocked';				break;			case 2:				bcl.replace('notblocked-hidden', 'blocked-hidden'); portlet.textContent = 'Show blocked'; }		if (isInit) return; mw.storage.session.setObject('toggleblocked', [mw.config.get('wgArticleId'), state]); };	let portlet = mw.util.addPortletLink('p-tb', '#', 'Hide not blocked', 't-toggleblocked').firstElementChild; portlet.addEventListener('click', function (e) {		e.preventDefault;		state = (state + 1) % 3;		toggle;	}); toggle(true); });