MediaWiki

Difference between revisions of "Gadget-RecentNonAudio.js"

(Improve description)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
/* ************************************************************************** */
 
/* ************************************************************************** */
/* Edit toolbox ************************************************************ */
 
 
// Description: adds within the toolbox (bottom) a link toward recent changes, hidding the flow of recordings.
 
// Description: adds within the toolbox (bottom) a link toward recent changes, hidding the flow of recordings.
// Special:Preferences#mw-prefsection-gadgets > select "RecentNonAudio"
+
// Usage : open Special:Preferences#mw-prefsection-gadgets > select "RecentNonAudio"
 
/* Sources: [[:mw:Manual:Interface/Sidebar#Add_or_remove_toolbox_sections_(JavaScript)]]  */
 
/* Sources: [[:mw:Manual:Interface/Sidebar#Add_or_remove_toolbox_sections_(JavaScript)]]  */
  

Latest revision as of 21:47, 6 January 2022

/* ************************************************************************** */
// Description: adds within the toolbox (bottom) a link toward recent changes, hidding the flow of recordings.
// Usage : open Special:Preferences#mw-prefsection-gadgets > select "RecentNonAudio"
/* Sources: [[:mw:Manual:Interface/Sidebar#Add_or_remove_toolbox_sections_(JavaScript)]]  */

function ModifySidebar( action, section, name, link ) {
			//console.log("1:", action,section, name, link);
	try {
		var target='';
		switch ( section ) {
			case 'languages':
				target = 'p-lang';
				break;
			case 'toolbox':
				target = 'toolbox'; // mediawiki: "p-tb" ; wikibase: "toolbox" and then remove lines selecting children div and ul
				break;
			case 'navigation':
				target = 'p-navigation';
				break;
			default:
				target = 'p-' + section;
				break;
		}

		if ( action == 'add' ) {
			//console.log(action,section, name, link);
			var node = document.getElementById( target );
//							   .getElementsByTagName( 'div' )[0]
//							   .getElementsByTagName( 'ul' )[0];

			var aNode = document.createElement( 'a' );
			var liNode = document.createElement( 'li' );

			aNode.appendChild( document.createTextNode( name ) );
			aNode.setAttribute( 'href', link );
			liNode.appendChild( aNode );
			liNode.className = 'plainlinks';
			node.appendChild( liNode );
		}

		if ( action == 'remove' ) {
			var list = document.getElementById( target );
	//						   .getElementsByTagName( 'div' )[0]
//							   .getElementsByTagName( 'ul' )[0];

			var listelements = list.getElementsByTagName( 'li' );

			for ( var i = 0; i < listelements.length; i++ ) {
				if (
					listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
					listelements[i].getElementsByTagName( 'a' )[0].href == link
				)
				{
					list.removeChild( listelements[i] );
				}
			}
		}


	} catch( e ) {
		// let's just ignore what's happened
		return;
	}
}

function CustomizeModificationsOfSidebar() {
	ModifySidebar( "add", "toolbox", "Recent (non-audio)", mw.util.getUrl( 'Special:RecentChanges', { limit: 2500, namespace: 0, invert: 1 } ) );
}

$( CustomizeModificationsOfSidebar );