// ==UserScript==
// @name Transparent flash removal
// @author Andrew Walker 
// @namespace http://www.moddular.org/log 
// @version 1.0
// @description  Removes transparent flash animations.
// @ujs:category general: enhancements
// @ujs:published 2005-08-24 18:47
// @ujs:modified 2005-09-19 09:19
// @ujs:documentation http://userjs.org/scripts/general/enhancements/remove-transparent-flash 
// @ujs:download http://userjs.org/scripts/download/general/enhancements/remove-transparent-flash.js
// ==/UserScript==

/* 
 * Copyright © 2005 by Andrew Walker
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */


(function () {
    var display = true;
    var removed = 0;
    var obj = document.getElementsByTagName('object');
    for (var i in obj) {
       if (!obj[i].getElementsByTagName) {
           continue;
       }
       var params = obj[i].getElementsByTagName('param');
       for (var j in params) {
           if (!params[j].getAttribute) {
               continue;
           }
           if (params[j].getAttribute('name').toLowerCase() == 'wmode' && params[j].getAttribute('value').toLowerCase() == 'transparent') {
               while (obj[i].hasChildNodes()) {
                   obj[i].removeChild(obj[i].firstChild);
               }
               obj[i].parentNode.removeChild(obj[i]);
               ++removed;
               break; //the object has been deleted, no need to keep checking parameters
           }
       }
    }
    // are there any embed tags that were not inside an object tag?
    var embed = document.getElementsByTagName('embed');
    for (var i in embed) {
        if (embed[i].getAttribute && embed[i].getAttribute('wmode').toLowerCase() == 'transparent') {
               embed[i].parentNode.removeChild(embed[i]);
               ++removed;
        }
    }

    if (display && removed > 0) {
        var d = document.createElement('div');
        d.appendChild(document.createTextNode('Removed ' + removed + ' ' + ((removed == 1) ? 'object' : 'objects')));
        d.style.position = 'absolute';
        d.style.right = '0px';
        d.style.bottom = '0px';
        d.style.padding = '3px';
        d.style.backgroundColor = '#eeeeee';
        document.getElementsByTagName('body')[0].appendChild(d);
        d.addEventListener('click', function(e) { e.target.parentNode.removeChild(e.target); }, false);
    }
    
})();
