JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
add youtube html5 unembedder
[userscripts.git] / youtube-html5-hider / script.js
diff --git a/youtube-html5-hider/script.js b/youtube-html5-hider/script.js
new file mode 100644 (file)
index 0000000..444afd1
--- /dev/null
@@ -0,0 +1,29 @@
+// ==UserScript==
+// @name          YouTube html5 unembedder
+// @namespace     http://jasonwoof.com/
+// @description   Replace YouTube html5 embedds with links
+// @include       *
+// @exclude       http://youtube.com/*
+// @exclude       http://www.youtube.com/*
+// ==/UserScript==
+
+// Copyright Jason Woofenden 2012. Use as you wish (CC0)
+
+(function() {
+       var replace = function(old, replacement) {
+               old.parentNode.appendChild(replacement);
+               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);
+               }
+       }
+}());
+