MediaWiki

Difference between revisions of "Gadget-RecentNonAudio.js"

 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
/* ************************************************************************** */
 
/* ************************************************************************** */
/* Edit toolbox ************************************************************ */
+
// 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)]]  */
 
/* Sources: [[:mw:Manual:Interface/Sidebar#Add_or_remove_toolbox_sections_(JavaScript)]]  */
  
 
function ModifySidebar( action, section, name, link ) {
 
function ModifySidebar( action, section, name, link ) {
console.log("1:", action,section, name, link);
+
//console.log("1:", action,section, name, link);
 
try {
 
try {
 
var target='';
 
var target='';
Line 23: Line 24:
  
 
if ( action == 'add' ) {
 
if ( action == 'add' ) {
console.log(action,section, name, link);
+
//console.log(action,section, name, link);
 
var node = document.getElementById( target );
 
var node = document.getElementById( target );
 
//   .getElementsByTagName( 'div' )[0]
 
//   .getElementsByTagName( 'div' )[0]
Line 64: Line 65:
  
 
function CustomizeModificationsOfSidebar() {
 
function CustomizeModificationsOfSidebar() {
ModifySidebar( "add", "toolbox", "Recent (non-audio)", "https://lingualibre.org/wiki/Special:RecentChanges?namespace=0&invert=1" );
+
ModifySidebar( "add", "toolbox", "Recent (non-audio)", mw.util.getUrl( 'Special:RecentChanges', { limit: 2500, namespace: 0, invert: 1 } ) );
 
}
 
}
  
 
$( CustomizeModificationsOfSidebar );
 
$( CustomizeModificationsOfSidebar );

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 );