Last active
December 10, 2015 03:18
-
-
Save ide-an/4373618 to your computer and use it in GitHub Desktop.
Webページに埋め込まれたFlash版SoundCloudプレイヤーをHTML5版に置き換える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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