Jump to content

User:JPxG/current-switcher.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by JPxG (talk | contribs) at 09:37, 25 August 2021 (hmm, that explains a lot). 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.
// This is a very simple script. Basically, what it does is add buttons to "contributions" pages, like Special:Contributions/JPxG or Special:MyContributions, which allow you to toggle displaying current contributions.
// It's useful if you participate in a lot of discussions, and you want to see which of them have been responded to (i.e. which of your comments are no longer the current revision).
// - JPxG, 2021 08 24

$( function() {
    if( (window.location.href.indexOf( "Special:Contributions/" ) >= 0 ) || (window.location.href.indexOf( "Special%3AContributions" ) >= 0 )) {
    	$('.mw-pager-navigation-bar').append('&nbsp;&nbsp;Toggle: <button type="button" id="currentrevs">current</button>');
		$('.mw-pager-navigation-bar').append('&nbsp;<button type="button" id="rollback">rollback</button>');
		var currenthidden = 0;
		var rollbackhidden = 0;		
		// Set toggle variables.
		$('#currentrevs').click(function(e) {
			// Listener for "what to do if the 'current' button is clicked"
			if(rollbackhidden == 0){
				$( '.mw-tag-mw-rollback' ).hide();
			} // If toggle is 0, hide them.
			if(rollbackhidden == 1){
				$( '.mw-tag-mw-rollback' ).show();
			} // If toggle is 1, show them.
			rollbackhidden = (1 - rollbackhidden);
			// Either way, invert the toggle.
		});
		$('#rollback').click(function(e) {
			// Listener for "what to do if the 'rollback' button is clicked"
			if(currenthidden == 0){
				$( '.mw-contributions-current' ).hide();
			} // If toggle is 0, hide them.
			if(currenthidden == 1){
				$( '.mw-contributions-current' ).show();
			} // If toggle is 1, show them.
			rollbackhidden = (1 - rollbackhidden);
			// Either way, invert the toggle.
		});
    }
} );