Jump to content

User:Ale jrb/Scripts/tophide.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.
	
	function topHideMain() {
		var me = this;

		this.init = function () {
			if ( ( wgAction == 'view' ) && ( wgPageName == 'Special:Contributions' ) ) {
				var bodyContent = document.getElementById ( 'bodyContent' );
				regTest = /class="mw-numlink">500<\/a>\)<\/p><ul>/ig;

				if ( typeof topHideDefault === "undefined" ) topHideDefault = 'hide';
				if ( topHideDefault == 'hide' ) {
					bodyContent.innerHTML = bodyContent.innerHTML.replace ( regTest, "class=\"mw-numlink\">500</a>) (<span id=\"tophider\"><a href=\"#\" onclick=\"topHide.show(); return false;\">show top edits</a></span>)</p><ul>" );
					topHide.hide ();
				} else {
					bodyContent.innerHTML = bodyContent.innerHTML.replace ( regTest, "class=\"mw-numlink\">500</a>) (<span id=\"tophider\"><a href=\"#\" onclick=\"topHide.hide(); return false;\">hide top edits</a></span>)</p><ul>" );
				}

				wa_popups ( 'refresh' );
			}
		}
		
		this.hide = function () {
			if ( ( wgAction == 'view' ) && ( wgPageName == 'Special:Contributions' ) ) {
				document.getElementById ( 'tophider' ).innerHTML = '<a href="#" onclick="topHide.show(); return false;">show top edits</a>';

				var bodyContent = document.getElementById ( 'bodyContent' );
				regTest = /(<li class="">(?!<\/li)(?:.+?)<span class="mw-uctop">\(top\)<\/span>(?:.+?)<\/li>)/ig;
				bodyContent.innerHTML = bodyContent.innerHTML.replace ( regTest, "<!--tophidehide$1endtophide-->" );
				wa_popups ( 'refresh' );
			}
			return false;
		}

		this.show = function () {
			if ( ( wgAction == 'view' ) && ( wgPageName == 'Special:Contributions' ) ) {
				document.getElementById ( 'tophider' ).innerHTML = '<a href="#" onclick="topHide.hide(); return false;">hide top edits</a>';

				var bodyContent = document.getElementById ( 'bodyContent' );
				regTest = /<!--tophidehide(.+?)endtophide-->/ig;
				bodyContent.innerHTML = bodyContent.innerHTML.replace ( regTest, "$1" );
				wa_popups ( 'refresh' );
			}
			return false;
		}
	}
	
	importScript ( 'User:Ale_jrb/Scripts/waLib2.js' );
	var topHide = new topHideMain ();
	hookEvent ( 'load', topHide.init );