Skip to content

Instantly share code, notes, and snippets.

@aanand
Created February 2, 2013 18:24
Show Gist options
  • Save aanand/4698693 to your computer and use it in GitHub Desktop.
Save aanand/4698693 to your computer and use it in GitHub Desktop.
Replace all links to audio files with <audio> tags
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>
$(function() {
var a = document.createElement('audio');
if (!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''))) return;
$("a").each(function() {
if (!this.href.match(/\.(mp3|mp4|m4a)$/)) return;
var audio = $('<audio/>').attr({
src: this.href,
controls: 'controls'
});
$(this).replaceWith(audio);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment