User:CBM/shortambox.js

function getTableElementsByClassName(className) { var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)"); var allElements = document.getElementsByTagName("table"); var results = [];

var element; for (var i = 0; (element = allElements[i]) != null; i++) { var elementClass = element.className; if (elementClass && elementClass.indexOf(className) != -1                     &&  hasClassName.test(elementClass)) { results.push(element); } }  return results; }

function shortenAmbox(b,c) { b.innerHTML=c; b.style.marginLeft = '1em'; b.style.marginRight = '1em'; b.style.cssFloat = 'right'; }

$(function {  if ( wgNamespaceNumber > 0 ) { return; }  var citing = new RegExp("Wikipedia:Citing_sources");  var orphan = new RegExp("Wikipedia:Orphan");  var results = getTableElementsByClassName('ambox');  for( var i in results ) {     if ( results[i].innerHTML ) {       var content = results[i].innerHTML;      // alert(content);      if ( citing.test(content) ) {         if (( typeof(noUnreferenced) === 'undefined')  || (noUnreferenced == 0) ) {           shortenAmbox(results[i], "Unreferenced");        } else {          results[i].style.display= 'none';         }       } else if ( orphan.test(content) ) {         shortenAmbox(results[i], "Orphan");      }    }  } });