old.parentNode.removeChild(old);
}
- var iframes = document.getElementsByTagName('iframe');
- for (var i = iframes.length - 1; i >= 0; --i) {
- var iframe = iframes[i];
- var match = iframe.src.match(/^http:\/\/www.youtube.com\/embed\/([^?]*)/)
- if (match) {
- var div = document.createElement('div');
- div.innerHTML = '<a href="http://www.youtube.com/watch?v=' + match[1] + '" style="display: block; width: 200px; height: 20px; padding: 20px; margin: 0; border: 2px dotted #f00; background: #fdd !important; text-align: center; font-size: 16px; font-weight: bold; color: #000">YouTube: ' + match[1] + '</a>';
- replace(iframe, div);
+ var embed_types = [
+ {tag: 'iframe', attr: 'src'},
+ {tag: 'object', attr: 'data'},
+ {tag: 'embed', attr: 'src'}
+ ];
+
+ var i;
+ for(i = 0; i < embed_types.length; ++i) {
+ var tag_type = embed_types[i].tag;
+ var attr = embed_types[i].attr
+
+ var tags = document.getElementsByTagName(tag_type);
+ for(var j = tags.length - 1; j >= 0; --j) {
+ var tag = tags[j];
+ if(tag[attr]) {
+ var match = tag[attr].match(/^http:\/\/www.youtube(-nocookie)?.com\/(embed|v)\/([^?]*)/)
+ if(match) {
+ var div = document.createElement('div');
+ div.innerHTML = '<a href="http://www.youtube.com/watch?v=' + match[3] + '" style="display: block; width: 200px; height: 20px; padding: 20px; margin: 0; border: 2px dotted #f00; background: #fdd !important; text-align: center; font-size: 16px; font-weight: bold; color: #000">YouTube: ' + match[3] + '</a>';
+ replace(tag, div);
+ }
+ }
}
}
}());