User:JPxG/current-switcher2.js

// 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 )) {    	crct = document.querySelectorAll('.mw-contributions-current').length;    	// Count the number of "current"s    	rbct = document.querySelectorAll('.mw-tag-mw-rollback').length;    	// Count the number of "rollback"s    	hgct = document.querySelectorAll('.mw-tag-huggle').length;    	// Count the number of "huggle"s    	dpct = 0;    	titles=[];    	allcount = document.getElementsByTagName('li');    	// We are going to count all the dupes now.    	for(var asdf in allcount){    		try{    			var title = allcount[asdf].getElementsByClassName('mw-contributions-title')[0].innerHTML;    			//$('.mw-pager-navigation-bar').append(allcount[asdf]);    			if (titles.includes(title)) {    				dpct = dpct + 1;    			}    			titles.push(title); //alert(String(titles)); } catch(e) {console.log(e)} }   	$('.mw-pager-navigation-bar').append('  Toggle:   current '+crct+'  '); $('.mw-pager-navigation-bar').append('  rollback '+rbct+'  '); $('.mw-pager-navigation-bar').append('  huggle '+hgct+'  '); $('.mw-pager-navigation-bar').append('  dupes '+dpct+'  '); document.getElementById("currentrevs").style = "font-family: monospace; padding: 1px; border: 3px; width=8em"; document.getElementById("rollback").style = "font-family: monospace; padding: 1px; border: 3px; width=8em"; document.getElementById("huggle").style = "font-family: monospace; padding: 1px; border: 3px; width=8em"; document.getElementById("dupes").style = "font-family: monospace; padding: 1px; border: 3px; width=8em"; // Add the buttons. var currenthidden = 0; var rollbackhidden = 0; var hugglehidden = 0; var dupeshidden = 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 = " current "+crct+"  "				// 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 "+crct+"  "				// 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 = " rollback "+rbct+"  "				// 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 "+rbct+"  "				// 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 = " huggle "+hgct+"  "				// 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 "+hgct+"  "				// Unstrike the text on the button.			} // If toggle is 1, show them.			hugglehidden = (1 - hugglehidden);			// Either way, invert the toggle.		}); $('#dupes').click(function(e) {			// Listener for "what to do if the 'dupes' button is clicked"			if(dupeshidden == 0){				titles=[];		   	allcount = document.getElementsByTagName('li');    			// We are going to count all the dupes now.    			for(var asdf in allcount){    				try{    					var title = allcount[asdf].getElementsByClassName('mw-contributions-title')[0].innerHTML;    					//$('.mw-pager-navigation-bar').append(allcount[asdf]);    					if (titles.includes(title)) {    						allcount[asdf].style.visibility = "hidden";    					}    					titles.push(title);    				} catch(e) {console.log(e)}    			}				// Hide the diffs.				x = document.getElementsByClassName('dpbutton')[0]				x.innerHTML = "  dupes "+dpct+"  "				// Strike out the text on the button.			} // If toggle is 0, hide them.			if(dupeshidden == 1){				allcount = document.getElementsByTagName('li');    			// We are going to count all the dupes now. for(var asdf in allcount){ try{ var title = allcount[asdf].getElementsByClassName('mw-contributions-title')[0].innerHTML; //$('.mw-pager-navigation-bar').append(allcount[asdf]); if (titles.includes(title)) { allcount[asdf].style.visibility = "visible"; }   					titles.push(title); } catch(e) {console.log(e)} }				// Hide the diffs. // Show the diffs. x = document.getElementsByClassName('dpbutton')[0] x.innerHTML = " dupes "+dpct+"  " // Unstrike the text on the button. } // If toggle is 1, show them. dupeshidden = (1 - dupeshidden); // Either way, invert the toggle. });	   } } );