Created
January 9, 2012 19:38
-
-
Save DavidWittman/1584544 to your computer and use it in GitHub Desktop.
Greasemonkey Script to add "Couch Mode" to YouTube
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YouTube Couch Mode | |
// @author David Wittman <[email protected]> | |
// @namespace nowhere | |
// @description Adds a full-screen "Couch Mode" button to YouTube | |
// @include http://www.youtube.com/watch?* | |
// ==/UserScript== | |
// iframe detection | |
// http://stackoverflow.com/questions/1535404/how-to-exclude-iframe-in-greasemonkey | |
if (window.top != window.self) { | |
return; | |
} | |
(function() { | |
var ytBase = 'http://www.youtube.com/v/'; | |
var ytPattern = /&?v=([-_A-z0-9]+)/; | |
var flagBtn = document.getElementById('watch-flag'); | |
var couchMode = document.createElement('button'); | |
var videoId = ytPattern.exec(window.location)[1];; | |
couchMode.innerHTML = '<span class="yt-uix-button-content">Couch Mode</span>'; | |
couchMode.className = 'yt-uix-tooltip-reverse yt-uix-button yt-uix-button-default yt-uix-tooltip'; | |
couchMode.setAttribute('data-tooltip-text', 'Watch in full window'); | |
flagBtn.parentNode.insertBefore(couchMode, flagBtn); | |
bind(couchMode, 'click', function() { | |
window.location = ytBase + videoId; | |
}); | |
function bind(obj, event, fn) { | |
if (obj.addEventListener) { | |
obj.addEventListener(event, fn, false); | |
return true; | |
} | |
else if (obj.attachEvent) { | |
var r = obj.attachEvent("on"+event, fn); | |
return r; | |
} | |
else { | |
return false; | |
} | |
} | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment