Jump to content

User:Werdna/nofakemessages.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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( function() {
    var content = document.getElementById( "content" );
    
    var rx = new RegExp( wgUserName );
    
    var newmassages = getElementsByClass( 'usermessage', content, null );
    
    for each (massage in newmassages) {
        
        //alert("Detected prompt"+massage.innerHTML);
        
        if (!(rx.test(massage.innerHTML))) {
            massage.parentNode.removeChild(massage);
        }
    }
} );

function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}