JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
extend youtube blocker
[userscripts.git] / youtube-html5-hider / script.js
1 // ==UserScript==
2 // @name          YouTube html5 unembedder
3 // @namespace     http://jasonwoof.com/
4 // @description   Replace YouTube html5 embedds with links
5 // @include       *
6 // @exclude       http://youtube.com/*
7 // @exclude       http://www.youtube.com/*
8 // ==/UserScript==
9
10 // Copyright Jason Woofenden 2012. Use as you wish (CC0)
11
12 (function() {
13         var replace = function(old, replacement) {
14                 old.parentNode.appendChild(replacement);
15                 old.parentNode.removeChild(old);
16         }
17
18         var iframes = document.getElementsByTagName('iframe');
19         for (var i = iframes.length - 1; i >= 0; --i) {
20                 var iframe = iframes[i];
21                 var match = iframe.src.match(/^http:\/\/www.youtube(-nocookie)?.com\/embed\/([^?]*)/)
22                 if (match) {
23                         var div = document.createElement('div');
24                         div.innerHTML = '<a href="http://www.youtube.com/watch?v=' + match[2] + '" 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[2] + '</a>';
25                         replace(iframe, div);
26                 }
27         }
28
29         var objects = document.getElementsByTagName('object');
30         for (var i = objects.length - 1; i >= 0; --i) {
31                 var object = objects[i];
32                 var match = object.data.match(/^http:\/\/www.youtube(-nocookie)?.com\/embed\/([^?]*)/)
33                 if (match) {
34                         var div = document.createElement('div');
35                         div.innerHTML = '<a href="http://www.youtube.com/watch?v=' + match[2] + '" 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[2] + '</a>';
36                         replace(object, div);
37                 }
38         }
39 }());
40