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 10:44, 25 August 2021 (make all of the buttons do the strikethrough thing). 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" class="crbutton" font-family:"monospace">current</button>');
		$('.mw-pager-navigation-bar').append('&nbsp;<button type="button" id="rollback" class="rbbutton">rollback</button>');
		$('.mw-pager-navigation-bar').append('&nbsp;<button type="button" id="huggle" class="hgbutton">huggle</button>');
		var currenthidden = 0;
		var rollbackhidden = 0;		
		var hugglehidden = 0;		
		// Set toggle variables.
		$('#currentrevs').click(function(e) {
			// Listener for "what to do if the 'current' button is clicked"
			if(currenthidden == 0){
				$( '.mw-contributions-current' ).hide()
				// Hide the diffs.
				x = document.getElementsByClassName('crbutton')[0]
				x.innerHTML = "<strike>current</strike>"
				// Strike out the text on the button.
			} // If toggle is 0, hide them.
			if(currenthidden == 1){
				$( '.mw-contributions-current' ).show();
				// Show the diffs.
				x = document.getElementsByClassName('crbutton')[0]
				x.innerHTML = "current"
				// Unstrike the text on the button.
			} // If toggle is 1, show them.
			currenthidden = (1 - currenthidden);
			// Either way, invert the toggle.
		});
		$('#rollback').click(function(e) {
			// Listener for "what to do if the 'rollback' button is clicked"
			if(rollbackhidden == 0){
				$( '.mw-tag-mw-rollback' ).hide();
				// Hide the diffs.
				x = document.getElementsByClassName('rbbutton')[0]
				x.innerHTML = "<strike>rollback</strike>"
				// Strike out the text on the button.
			} // If toggle is 0, hide them.
			if(rollbackhidden == 1){
				$( '.mw-tag-mw-rollback' ).show();
				// Show the diffs.
				x = document.getElementsByClassName('rbbutton')[0]
				x.innerHTML = "rollback"
				// Unstrike the text on the button.
			} // If toggle is 1, show them.
			rollbackhidden = (1 - rollbackhidden);
			// Either way, invert the toggle.
		});
		$('#huggle').click(function(e) {
			// Listener for "what to do if the 'huggle' button is clicked"
			if(hugglehidden == 0){
				$( '.mw-tag-huggle' ).hide();
				// Hide the diffs.
				x = document.getElementsByClassName('hgbutton')[0]
				x.innerHTML = "<strike>huggle</strike>"
				// Strike out the text on the button.
			} // If toggle is 0, hide them.
			if(hugglehidden == 1){
				$( '.mw-tag-huggle' ).show();
				// Show the diffs.
				x = document.getElementsByClassName('hgbutton')[0]
				x.innerHTML = "huggle"
				// Unstrike the text on the button.
			} // If toggle is 1, show them.
			hugglehidden = (1 - hugglehidden);
			// Either way, invert the toggle.
		});	
    }
} );