Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is what I came up with. It has only been tested in Google Chrome.</p> <pre><code>function changeobj() { objs = document.getElementsByTagName('object'); for (i in objs) { for (o in objs[i].children) { if (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; imgurl = 'http://img.youtube.com/vi/'+vidid+'/default.jpg'; link = document.createElement('a'); link.setAttribute('href',linkurl); link.setAttribute('target','_blank'); img = document.createElement('img'); img.src = imgurl; link.appendChild(img); objs[i].innerHTML = ''; objs[i].appendChild(link); } } } } function changeiframe() { objs = document.getElementsByClassName('youtube-player'); for (i in objs) { console.log(objs[i]); vidid = objs[i].src.split('/')[4].split('?')[0]; linkurl = 'http://www.youtube.com/watch?v='+vidid; imgurl = 'http://img.youtube.com/vi/'+vidid+'/default.jpg'; link = document.createElement('a'); link.setAttribute('href',linkurl); link.setAttribute('target','_blank'); img = document.createElement('img'); img.src = imgurl; link.appendChild(img); objs[i].outerHTML = link.outerHTML; } } window.onload = function () { changeobj(); changeiframe(); } </code></pre> <p>Yes, I know. There is a bug in it. That's why it won't finish. I'm working on it.</p> <p><strong>EDIT:</strong></p> <p>I fixed the original bugs: </p> <pre><code>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; imgurl = 'http://img.youtube.com/vi/'+vidid+'/default.jpg'; link = document.createElement('a'); link.setAttribute('href',linkurl); link.setAttribute('target','_blank'); img = document.createElement('img'); img.src = imgurl; link.appendChild(img); objs[i].innerHTML = ''; objs[i].appendChild(link); } } } } function changeiframe() { objs = document.getElementsByClassName('youtube-player'); for (i in objs) { if (objs[i].src) { vidid = objs[i].src.split('/')[4].split('?')[0]; linkurl = 'http://www.youtube.com/watch?v='+vidid; imgurl = 'http://img.youtube.com/vi/'+vidid+'/default.jpg'; link = document.createElement('a'); link.setAttribute('href',linkurl); link.setAttribute('target','_blank'); img = document.createElement('img'); img.src = imgurl; link.appendChild(img); objs[i].outerHTML = link.outerHTML; } } } window.onload = function () { changeobj(); changeiframe(); } </code></pre> <p>There is another bug that won't load any 4th movie, but I'm sure this should give you enough to make your own version.</p> <p><strong>EDIT:</strong> @evel - If you want to put a play button, you can put something like this into your CSS:</p> <pre><code>.YOUTUBE_VID { background-image: play.png; background-repeat: none; background-postion: center; } </code></pre> <p>And than add it the class to the link:</p> <pre><code>link.className += " .YOUTUBE_VID"; </code></pre> <p><strong>EDIT:</strong> Instead of using the for loop, I'm looping the function. This seems to be working:</p> <pre><code>function changeiframe() { objs = document.getElementsByClassName('youtube-player'); if (!objs[0]){return false;}; if (objs[0]) { vidid = objs[0].src.split('/')[4].split('?')[0]; linkurl = 'http://www.youtube.com/watch?v='+vidid; imgurl = 'http://img.youtube.com/vi/'+vidid+'/default.jpg'; link = document.createElement('a'); link.setAttribute('href',linkurl); link.setAttribute('target','_blank'); img = document.createElement('img'); img.src = imgurl; link.appendChild(img); objs[0].outerHTML = link.outerHTML; } changeiframe(); } </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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