User:Eithris/common.js: Difference between revisions
Jump to navigation
Jump to search
(Created page with "→Sidebar customization: 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]...") |
No edit summary |
||
Line 62: | Line 62: | ||
const url = tempurl2.split("\?").shift(); | const url = tempurl2.split("\?").shift(); | ||
// adds Special:PrefixIndex to toolbox | // adds Special:PrefixIndex to toolbox | ||
ModifySidebar( 'add', 'navigation', 'Prefix index', 'https:// | ModifySidebar( 'add', 'navigation', 'Prefix index', 'https://trigunwiki.com/w/Special:PrefixIndex?prefix=' + url ); | ||
} | } | ||
jQuery( CustomizeModificationsOfSidebar ); | jQuery( CustomizeModificationsOfSidebar ); |
Revision as of 16:37, 12 April 2024
/* Sidebar customization */
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() {
const tempurl = window.location.href.split("wiki/").pop();
const tempurl2 = tempurl.split("\_\(").shift();
const url = tempurl2.split("\?").shift();
// adds Special:PrefixIndex to toolbox
ModifySidebar( 'add', 'navigation', 'Prefix index', 'https://trigunwiki.com/w/Special:PrefixIndex?prefix=' + url );
}
jQuery( CustomizeModificationsOfSidebar );