Note that there are some explanatory texts on larger screens.

plurals
  1. POReplace an embed or iframe youtube video by an tumbnail + link to vídeo
    primarykey
    data
    text
    <p>I need an javascript that can be placed on header that recognizes an youtube embed or iframe player and replaces it by a tumbnail linked to the vídeo on youtube.</p> <p>The script should identifies an code like this ones:</p> <pre><code>&lt;object width="560" height="340"&gt;&lt;param name="movie" value="http://www.youtube.com/v/J4oJWUJpbLY?fs=1&amp;amp;hl=pt_BR&amp;amp;hd=1&amp;amp;color1=0x5d1719&amp;amp;color2=0xcd311b"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/J4oJWUJpbLY?fs=1&amp;amp;hl=pt_BR&amp;amp;hd=1&amp;amp;color1=0x5d1719&amp;amp;color2=0xcd311b" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"&gt;&lt;/embed&gt;&lt;/object&gt; &lt;iframe title="YouTube video player" class="youtube-player" type="text/html" width="560" height="345" src="http://www.youtube.com/embed/J4oJWUJpbLY?hd=1" frameborder="0"&gt;&lt;/iframe&gt; </code></pre> <p>And replace by it:</p> <pre><code>&lt;a href="http://www.youtube.com/watch?v=n1VCUF2xqKk" target="_blank"&gt;&lt;img src="http://img.youtube.com/vi/n1VCUF2xqKk/default.jpg" alt="" /&gt;&lt;/a&gt; </code></pre> <p>Look that the variable is the video ID.</p> <p>It is possible?</p> <p><strong>UPDATE</strong> [Code whith big thumbs and play icon)</p> <pre><code>//FUNC OBJECT function changeobj() { objs = document.getElementsByTagName('object'); for (i in objs) { for (o in objs[i].children) { if (objs[i].children[o].getAttribute &amp;&amp; objs[i].children[o].getAttribute('name') == 'movie') { vidid = objs[i].children[o].getAttribute('value').split('/')[4].split('?')[0]; linkurl = 'http://www.youtube.com/watch?v='+vidid; bgurl = 'http://img.youtube.com/vi/'+vidid+'/0.jpg'; imgurl = 'playsh.png'; link = document.createElement('a'); link.setAttribute('href',linkurl); link.setAttribute('target','_blank'); link.style.backgroundImage = 'url('+bgurl+')'; link.className += "youvid"; img = document.createElement('img'); img.src = imgurl; link.appendChild(img); objs[i].innerHTML = ''; objs[i].appendChild(link); } } } } //FUNC IFRAME function changeiframe() { objs = document.getElementsByTagName('iframe'); for (i in objs) { if (objs[i].src) { vidid = objs[i].src.split('/')[4].split('?')[0]; linkurl = 'http://www.youtube.com/watch?v='+vidid; bgurl = 'http://img.youtube.com/vi/'+vidid+'/0.jpg'; imgurl = 'playsh.png'; link = document.createElement('a'); link.setAttribute('href',linkurl); link.setAttribute('target','_blank'); link.style.backgroundImage = 'url('+bgurl+')'; link.className += "youvid"; img = document.createElement('img'); img.src = imgurl; link.appendChild(img); objs[i].outerHTML = link.outerHTML; } } } window.onload = function () { changeobj(); changeiframe(); } </code></pre> <p>The CSS:</p> <pre><code>.youvid { background-repeat: no-repeat; position: relative; display: block; text-align: center; background-position: center; } </code></pre> <p>One bug still remais, the changeiframe function only replaces the odd ones (1st, 3rd, 5th...).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload