var videoEmbed = { invoke: function(){ $('body').html(function(i, html) { return videoEmbed.convertVideo(html); }); }, convertVideo: function(html){ var pattern1 = /(?:http?s?:\/\/)?(?:www\.)?(?:vimeo\.com)\/?(.+)/g; var pattern2 = /(?:http?s?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g; if(pattern1.test(html)){ console.log("html", html); var replacement = '<iframe width="420" height="345" src="//player.vimeo.com/video/$1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'; var html = html.replace(pattern1, replacement); } if(pattern2.test(html)){ console.log("html", html); var replacement = '<iframe width="420" height="345" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>'; var html = html.replace(pattern2, replacement); } return html; } } setTimeout(function(){ videoEmbed.invoke(); },3000);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter