Jump to content

User:CALR/dpl.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
addOnloadHook(addCountLinks);

function hidePagesOutsideArticleNamespace(){
  var body = document.getElementById('bodyContent');
  if( !body ){ return; }

  if (document.getElementById('dpl_banner')) { 
    open(document.URL, "_self"); //refresh the page
    return; 
  }

  var lists = body.getElementsByTagName( "ul" );
  for ( var j=0; j<lists.length; j++ ){
    lists[j].style.listStyleType = 'decimal';
  }

  var links = body.getElementsByTagName( "li" );
  for( var i=0; i<links.length; i++ ){
    var link = links[i];
    if( link.innerHTML.toLowerCase().indexOf( '</a> (redirect page)' ) == -1 && 
        ( link.innerHTML.indexOf( 'href="/wiki/Talk:' ) != -1 || 
          link.innerHTML.indexOf( 'href="/wiki/Template talk:' ) != -1 || 
          link.innerHTML.indexOf( 'href="/wiki/Wikipedia:' ) != -1 ||
          link.innerHTML.indexOf( 'href="/wiki/Wikipedia_talk:' ) != -1 ||
          link.innerHTML.indexOf( 'href="/wiki/User:' ) != -1 ||
          link.innerHTML.indexOf( 'href="/wiki/User_talk:' ) != -1 
        )
      ) {
      links[i].style.display = 'none';
    }
  }

  var banner = document.createElement("div");
  banner.id = "dpl_banner";
  banner.style.backgroundColor = "yellow";
  banner.style.fontSize = 'larger';
  banner.innerHTML = "DPL MODE ON";
  body.insertBefore(banner,body.childNodes[0] );

}

function addCountLinks(){
  if (!document.URL.match('Special:Whatlinkshere')) { 
    return; 
  } // only add toolbox link on 'whatlinkshere' pages

  var target = document.getElementById('p-tb').getElementsByTagName( "ul" );
  if( target.length == 0 ){ return; } //no toolbox to hook into

  target = target[0];
  var newTool = document.createElement("li");
  target.appendChild( newTool );
  newTool.innerHTML = '<a href="" onclick="hidePagesOutsideArticleNamespace(); return false;">DPL mode</a>';
}