// ==UserScript==
// @name           Disable Embed Autoplay
// @namespace      http://dev.thewheatfield.org/userscripts
// @description    Disables Embed Tags Autoplay for 
//                      self embeded media
//                      imeem.com audio
//                      myflashfetis.com audio
// @include        *
// ==/UserScript==

function createReplacement(elementToReplace, attributeNameToChange, newAttributeValue)
{
    var embedReplacement = elementToReplace.cloneNode(true);
    embedReplacement.setAttribute(attributeNameToChange, newAttributeValue);
    elementToReplace.parentNode.replaceChild(embedReplacement, elementToReplace);
}

var list = document.getElementsByTagName('embed');
if (list.length) 
{
    for(i = 0; i < list.length; i++)
    {
        var msg = '';
        var embed = list[i];
        var autostart = embed.getAttribute("autostart");
        var src = embed.getAttribute("src");
        
        // self embeded linking to media file
        // <embed src="annoying.mp3" autostart="true">
        if (autostart != null)
        {
            createReplacement(embed, "autostart", 0);
        }
        // imeem.com
        // add "/aus=false/" to the end of the src
        if (src.indexOf("imeem.com") != -1)
        {
            if (src.indexOf("aus=false") == -1)
            {
                createReplacement(embed, "src", src + '/aus=false/');
            }
        }
        // myflashfetish.com
        // change autostart or autoplay to "false" in flashvars attribute
        // <embed src="http://assets.myflashfetish.com/swf/mp3/minime.swf?myid=15422885&path=2008/11/23" quality="high" wmode="transparent" flashvars="mycolor=27081D&mycolor2=47232C&mycolor3=66997B&autoplay=true&rand=0&f=4&vol=100&pat=0&grad=false" width="160" height="68" name="myflashfetish" align="middle"type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" border="0" style="visibility:visible;width:160px;height:68px;"></embed>
        else if (src.indexOf("myflashfetish.com")  != -1)
        {
            var flashvars = embed.getAttribute("flashvars");
            flashvars = flashvars.replace(/autoStart=true/,"autoStart=false");
            flashvars = flashvars.replace(/autoplay=true/,"autoplay=false");
            createReplacement(embed, "flashvars", flashvars);
        }
    }
} 

