Skip to content

Instantly share code, notes, and snippets.

@ide-an
Last active December 10, 2015 03:18
Show Gist options
  • Save ide-an/4373618 to your computer and use it in GitHub Desktop.
Save ide-an/4373618 to your computer and use it in GitHub Desktop.
Webページに埋め込まれたFlash版SoundCloudプレイヤーをHTML5版に置き換える
var replaceSoundPlayer = function(obj_element){
var url=obj_element.getElementsByTagName("embed")[0].src,
el = document.createElement("iframe"),
parent = obj_element.parentNode;
el.src=url.replace(/^https?:\/\/player.soundcloud.com\/player.swf/,location.protocol+"//w.soundcloud.com/player/");
el.width = obj_element.width;
el.height = obj_element.height;
parent.insertBefore(el,obj_element.nextSibling);
parent.removeChild(obj_element);
};
var replaceAllSoundPlayer = function(){
[].slice.call(document.getElementsByTagName("object"))
.forEach(function(el){
var embeds=el.getElementsByTagName("embed");
if(embeds.length>0 && embeds[0].src && /^https?:\/\/player.soundcloud.com/.test(embeds[0].src)){
console.log(el.innerHTML);
replaceSoundPlayer(el);
}
});
};
// replaceAllSoundPlayer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment