Skip to content

Instantly share code, notes, and snippets.

@johnschult
Last active August 29, 2015 13:59
Show Gist options
  • Save johnschult/10974466 to your computer and use it in GitHub Desktop.
Save johnschult/10974466 to your computer and use it in GitHub Desktop.
Fixed X1 Send to TV bookmarklet JS to transform all YouTube URLs to use HD and auto play in full screen. The original JS only worked on m.youtube URLs and did not use HD or work correctly if you used the bookmarklet on your desktop.
javascript:(function()%7Bvar z%3Ddocument.createElement(%27script%27)%3Bz.src%3D%27https://gist.githubusercontent.com/johnschult/10974466/raw/9aa0dbaaed5cb2c0871766db461e280932f3f2fb/bookmarklet-tv.js%27%3Bdocument.body.appendChild(z)%3B%7D)()
(function() {
var parseOpenGraph = function(el) {
var ns = 'og', data = {};
var metas = document.getElementsByTagName("meta");
ns = ns + ":";
for (i=0; i<metas.length; i++) {
var prop = metas[i].getAttribute('property'), key, value;
if (prop && prop.substring(0, ns.length) === ns) {
key = prop.substring(ns.length);
value = metas[i].getAttribute('content');
data[key] = data[key] || [];
data[key].push(value);
}
}
return data;
};
var ogpJson = parseOpenGraph(document.head);
var videoParams = '';
var ogVideo = ogpJson['video'] || ogpJson['video:url'] || ogpJson['video:secure_url'];
var ogImage = ogpJson['image'] || ogpJson['image:secure_url'];
if (ogVideo && ogImage) {
videoParams = '&videoUrl=' + encodeURIComponent(ogVideo[0]) + '&videoImage=' + encodeURIComponent(ogImage[0]);
} else if (ogVideo){
videoParams = '&videoUrl=' + encodeURIComponent(ogVideo[0]) + '&videoImage=https://sendtotv.x1.comcast.net/media/images/default-video.png'
}
function loadPageVar(sVar) {
return unescape(window.location.href.replace(new RegExp("^(?:.*[&\\?]" + escape(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
}
var url;
if (window.location.href.indexOf("youtube") >= 0 ) {
url = 'http://www.youtube.com/v/' + loadPageVar('v') + '?hd=1&autoplay=1&autohide=1';
} else {
url = window.location.toString();
}
var s = document.createElement('iframe');
s.setAttribute('style','position:fixed; visibility:hidden; top:0px; left:0px; width:100%; height:100%; border:0px; background: rgba(0,0,0,.6); z-index: 2147483647');
s.setAttribute('src', 'https://sendtotv.x1.comcast.net/panel/panel.html?url=' + encodeURIComponent(url) + videoParams);
var loaded = false;
s.onload = function() {
if(loaded) {
document.getElementsByTagName('body')[0].removeChild(s);
}
loaded = true;
s.style.visibility = 'visible';
s.focus();
}
document.getElementsByTagName('body')[0].appendChild(s);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment