User:Kernigh/tagline.js

//

/* * Monobook tagline enchancement script * by Kernigh - public domain * * The purpose of this script is to add "search" and * "what links here" links to the tagline under article heading. */

// extract page title from url of toolbox "What links here" function extractTitle { var listItem = document.getElementById( "t-whatlinkshere" );

if( ! listItem ) return false; if( ! listItem.firstChild ) return false; if( ! listItem.firstChild.getAttribute ) return false;

var url = listItem.firstChild.getAttribute( "href" ); if( ! url ) return false;

url += "&"; var index= url.indexOf( "?target=" ); if( index < 0 ) index = url.indexOf( "&target=" ); if( index < 0 ) return false;

index += 8; // advance to start return( url.substring( index, url.indexOf( "&", index + 1 ) ) ); }

function enhanceTagline { var pageTitle = extractTitle;

if( pageTitle && decodeURIComponent) { var siteSub = document.getElementById( "siteSub" );

if( siteSub && siteSub.appendChild && document.createElement &&        document.createAttribute && document.createTextNode ) { var hyphen1 = document.createTextNode(" - "); var link1  = document.createElement("a"); var href1  = document.createAttribute("href"); var hyphen2 = document.createTextNode(" - "); var link2  = document.createElement("a"); var href2  = document.createAttribute("href");

// point and label links href1.value = scr.wikiUrl + "Special:Search?search=" + pageTitle + "&fulltext=Search"; href2.value = scr.wikiPhp + "?title=Special:Whatlinkshere&target=" + pageTitle; link1.appendChild(         document.createTextNode ( "search for \"" +          decodeURIComponent( pageTitle  )+ "\"" ) ); link2.appendChild( document.createTextNode( "what links here" ) );

// connect everything to document link1.setAttributeNode( href1 ); link2.setAttributeNode( href2 ); siteSub.appendChild( hyphen1 ); siteSub.appendChild( link1 ); siteSub.appendChild( hyphen2 ); siteSub.appendChild( link2 ); } } } addOnloadHook( enhanceTagline );

//