JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
add youtube html5 unembedder
authorJason Woofenden <jason@jasonwoof.com>
Tue, 3 Jan 2012 05:13:41 +0000 (00:13 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Tue, 3 Jan 2012 05:53:46 +0000 (00:53 -0500)
youtube-html5-hider/manifest.json [new file with mode: 0644]
youtube-html5-hider/script.js [new file with mode: 0644]

diff --git a/youtube-html5-hider/manifest.json b/youtube-html5-hider/manifest.json
new file mode 100644 (file)
index 0000000..d1abc0b
--- /dev/null
@@ -0,0 +1,12 @@
+{
+   "content_scripts": [ {
+      "exclude_globs": [ "http://youtube.com/*", "http://www.youtube.com/*" ],
+      "include_globs": [ "*" ],
+      "js": [ "script.js" ],
+      "matches": [ "http://*/*", "https://*/*" ],
+      "run_at": "document_idle"
+   } ],
+   "description": "Replace YouTube's html5 \"embedded\" videos into links",
+   "name": "YouTube html5 unembedder",
+   "version": "1.0"
+}
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);
+               }
+       }
+}());
+