Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Greasemonkey Script to add "Couch Mode" to YouTube
// ==UserScript==
// @name YouTube Couch Mode
// @author David Wittman <david@wittman.com>
// @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
You can’t perform that action at this time.