Jump to content

User:Saintrain/J/deSpamWiki.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.
//<pre>
//================  deSpamWiki  ============================================================
function deSpamWiki()
{
var GBUG = false;
var  BUG = GBUG;

var SpamObj = { id:"", class:"", clsNdx:0,   act:"" };

var spamList = new Array();

var sndx  = 0;
///-m- spamList[sndx] = SpamObj = { id : "newarticletext",         act : "delete node" };  sndx++;
///-m- spamList[sndx] = SpamObj = { id : "userinvalidcssjstitle",  act : "delete node" };  sndx++;
///-m- spamList[sndx] = SpamObj = { id : "editpage-copywarn",      act : "delete node" };  sndx++;
///-m- spamList[sndx] = SpamObj = { id : "editpage-copywarn2",     act : "delete node" };  sndx++;
///-m- spamList[sndx] = SpamObj = { id : "editpage-copywarn3",     act : "delete node" };  sndx++;
spamList[sndx] = SpamObj = { id : "editpage-specialchars",  act : "hide node" };    sndx++;
///-m- spamList[sndx] = SpamObj = { id : "talkpagetext",           act : "delete node" };  sndx++;

for(var s=0; s<spamList.length; s++) {
  if(BUG)console.log('dSW: spamList[',s,'].id={',spamList[s].id,'}  .class={',spamList[s].class,'}  .act={',spamList[s].act,'} ');
  var spamStr;
  with( spamList[s] ) {
    if( "" != id ) {
      spamStr = id;
      var spam = document.getElementById( id );
      }
     else if( "" != class ) {
      spamStr = class;
      var hits = document.getElementsByClass( class, null, null );
      if( hits )
        var spam = hits[clsNdx];  // this is silly!  just use 1st.
      }
     else { if(BUG)console.log('dSW: spamList[s][',s,'].id == .class == "" '); continue; }

    if ( !spam ) { if(BUG)console.log('dSW: NO FIND spam={',spamStr,'}' ); continue; }

    switch( act ) {
      case "delete node":  //==========  "delete node"  =======================================
        if( !GBUG ) BUG = false;
        var spamMom = spam.parentNode;
        if ( !spamMom ) { if(BUG)console.log('dSW: NO FIND spam={',spamStr,'}.parentNode' ); continue; }
        spamMom.removeChild( spam );
        spam = null;
        break;

      case "hide node":  //==========  "hide node"  =======================================
        if( !GBUG ) BUG = false;
        var spamMom = spam.parentNode;
        if ( !spamMom ) { if(BUG)console.log('dSW: NO FIND spam={',spamStr,'}.parentNode' ); continue; }
  
        var hndx = 666 + s;  // bump index so as not to interfere with "legit" navframe stuff
  
        var NavFrame = document.createElement("div");
        NavFrame.setAttribute('id', 'NavFrame' + hndx );
        NavFrame.className = 'NavFrame';
        spamMom.insertBefore( NavFrame, spam );
  
        var NavHead = document.createElement( "div" );
        NavHead.textContent = spamStr;
        NavHead.className = 'NavHead';
        NavFrame.appendChild( NavHead );
  
        var NavToggle = document.createElement("a");
        NavHead.appendChild( NavToggle );
        NavToggle.className = 'NavToggle';
        NavToggle.setAttribute('id', 'NavToggle' + hndx );
        NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + hndx + ');');
        NavToggle.textContent = "[hide]";
  
        spam.id = "NavFrame" + hndx;
        spam.className += " NavContent";
        NavFrame.appendChild( spam );  // re-parents "spam"
  
        toggleNavigationBar( hndx );
        break;
  

      case "delete last kids":  //==========  "delete last kids"  =======================================
        if( !GBUG ) BUG = false;
        if( ! spam.hasChildNodes()) { if(BUG)console.log('dSW: NO FIND spam={',spamStr,'}.hasChildNodes()' ); continue; }
        var c0 = spam.firstChild;
          if(BUG)console.log('dSW: LEAVING: tagName={',c0.tagName,'}, name={',c0.name,'}, kid=',c0 );
          if(BUG)console.log('  innerHTML={',c0.innerHTML,'}' );
        while( 1 < spam.childNodes.length ) {
        var lc = spam.lastChild;
          if(BUG)console.log('dSW: removing: tagName={',lc.tagName,'}, name={',lc.name,'}, kid=',lc );
          if(BUG)console.log('  innerHTML={',lc.innerHTML,'}' );
          spam.removeChild( spam.lastChild ); 
          if(BUG)console.log(' ');
          }
        break;
  
      case "delete last tags":  //==========  "delete last tags"  =======================================
        if( !GBUG ) BUG = false;      
        if( ! spam.hasChildNodes()) { if(BUG)console.log('dSW: NO FIND spam={',spamStr,'}.hasChildNodes()' ); continue; }
        var it0 = -1;
        for(k=0; k<spam.childNodes.length; k++) {
          if( spam.childNodes[k].tagName ) {  // 1st tag
            it0 = k + 1; 
            break;
            }
          }
        if( it0 < 0 )  // no tags
          break;
        var tag0 = spam.childNodes[it0];
          if(BUG)console.log('dSW: LEAVING: tagName={',tag0.tagName,'}, name={',tag0.name,'}, kid=',tag0 );
          if(BUG)console.log('  innerHTML={',tag0.innerHTML,'}' );
        while( it0 < spam.childNodes.length ) {
          var lc = spam.lastChild;
            if(BUG)console.log('dSW: removing: tagName={',lc.tagName,'}, name={',lc.name,'}, kid=',lc );
            if(BUG)console.log('  innerHTML={',lc.innerHTML,'}' );
          spam.removeChild( spam.lastChild ); 
            if(BUG)console.log(' ');
          }
        break;
  
      default:
        if(BUG)console.log('dSW: UNKNOWN act[',s,'] = {',act,'}.' ); 
        continue; 
      }  // switch
    }  // with( spam )
  BUG = GBUG;
  }  // for(s)
}
//============================================================================
addOnloadHook( deSpamWiki);



//</pre>