User:Neitram/common.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// From https://www.mediawiki.org/wiki/Manual:Interface/Sidebar#Add_or_remove_sections_.28JavaScript.29

// The URL for the custom prefilled information template was generated with
// https://commons.wikimedia.org/w/index.php?title=Commons:User_scripts/UploadLink&withJS=MediaWiki:BuildUploadLink.js

function ModifySidebar( action, section, name, link ) {
	try {
		switch ( section ) {
			case 'languages':
				var target = 'p-lang';
				break;
			case 'toolbox':
				var target = 'p-tb';
				break;
			case 'navigation':
				var target = 'p-navigation';
				break;
			default:
				var target = 'p-' + section;
				break;
		}
 
		if ( action == 'add' ) {
			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( 'remove', 'participate', 'Upload file', 'https://commons.wikimedia.org/wiki/Commons:Upload' );
	ModifySidebar( 'add', 'participate', 'Upload own file', 'https://commons.wikimedia.org/w/index.php?title=Special%3AUpload&uselang=en&uploadformstyle=basic&wpLicense=self|GFDL|cc-by-sa-all|migration%3Dredundant&wpUploadDescription={{Information%0A|Description%3D%0A{{de|1%3D}}%0A|Source%3D{{own}}%0A|Date%3D2022-%0A|Author%3D[[User%3ANeitram|Neitram]]%0A|Permission%3D%0A|other_versions%3D%0A}}' );
	ModifySidebar( 'add', 'participate', 'Upload old PD', 'https://commons.wikimedia.org/w/index.php?title=Special%3AUpload&uselang=en&uploadformstyle=basic&wpUploadDescription={{Information%0A|Description%3D%0A{{de|1%3D}}%0A|Source%3D{{own}}%0A|Date%3D%0A|Author%3D%0A|Permission%3D%0A|other_versions%3D%0A}}%0A%0A== {{int:license-header}} ==%0A{{PD-old}}%0A{{PD-1996}}' );
	ModifySidebar( 'add', 'participate', 'Upload Baudenkmal', 'https://commons.wikimedia.org/w/index.php?title=Special%3AUpload&uselang=en&uploadformstyle=basic&wpLicense=self|GFDL|cc-by-sa-all|migration%3Dredundant&wpUploadDescription={{Information%0A|Description%3D{{de|1%3D}}%0A{{Kulturdenkmal|Typ%3D|Ort%3DBayern|Nummer%3D|Kategorie%3D|Kategorie2%3D}}%0A|Source%3D{{own}}%0A|Date%3D2022-%0A|Author%3D[[User%3ANeitram|Neitram]]%0A|Permission%3D%0A|other_versions%3D%0A}}%0A%0A[[Category%3ACultural+heritage+monuments+in+Augsburg]]%0A' );
	ModifySidebar( 'add', 'participate', 'Upload WLE 2017', 'https://commons.wikimedia.org/w/index.php?title=Special%3AUpload&uselang=en&uploadformstyle=basic&wpLicense=self|GFDL|cc-by-sa-all|migration%3Dredundant&wpUploadDescription={{Information%0A|Description%3D%0A{{de|1%3D}}%0A|Source%3D{{own}}%0A|Date%3D2022-%0A|Author%3D[[User%3ANeitram|Neitram]]%0A|Permission%3D%0A|other_versions%3D%0A}}%0A{{Wiki+Loves+Earth+2017|de}}%0A' );
}
 
$( CustomizeModificationsOfSidebar );