Hello everyone.
I have made a few changes to the greasemonkey script so that it works in Chrome.
This is the first time I have played around with greasmonkey scripts, so there might be better ways of doing this.
It would appear that using "http://url.tld" does not work in Chrome. To fix this, I changed this to:
Code:
// @include http://youtube.com/*
// @include http://youtube.com.*/*
// @include http://*.youtube.com/*
// @include http://*.youtube.com.*/*
This is obviously not as robust as it could be, but this works for me as it allows
http://youtube.com /.com.au, as well as
http://www.youtube.com / .com.au
Depending on which country you are in, you might want to add .co.uk or .co.* or whatever other TLDs you use for YouTube.
Again, as this is my first time working with a Chrome userscript, there might be a proper way of including any TLD.
The other changes that I made was to remove unsupported Chrome functions for setting the xbmc_host variable, removing the line "window" as it appears to be a syntax error and forcing the script to run after the page has loaded (@runat document_end).
Full script is here:
Code:
// ==UserScript==
// @name Chrome YouTube XBMC
// @namespace chrome_youtube_xbmc
// @run_at document_end
// @include http://youtube.com/*
// @include http://youtube.com.*/*
// @include http://*.youtube.com/*
// @include http://*.youtube.com.*/*
// ==/UserScript==
var xbmc_host = 'xbmc:xbmc@host:8080';
var xbmc_url = 'http://' + xbmc_host + '/jsonrpc';
function stopPlaying(){
GM_xmlhttpRequest({
method: 'GET',
url: xbmc_url + 'Stop()'
});
}
function pausePlaying(){
GM_xmlhttpRequest({
method: 'GET',
url: xbmc_url + 'Pause()'
});
}
function playMedia(){
setTimeout(function(){
querystring = window.location.search.substring(1);
queryarray = querystring.split("&");
for (i=0;i<queryarray.length;i++) {
query = queryarray[i].split("=");
if (query[0] == "v") {
GM_xmlhttpRequest({
method: 'POST',
url: xbmc_url,
headers: 'Content-type: application/json',
data: '{"jsonrpc": "2.0", "method": "XBMC.Play", "params":{ "file" : "plugin://plugin.video.youtube/?action=play_video&videoid=' + query[1] + '" }, "id" : 1}'
});
}
}
},
250
);
}
setTimeout(function () {
GM_addStyle("#xbmc_div {border-top: 1px solid #CCCCCC; " +
"margin: 0px 5px; padding: 5px; color: #666666; " +
"font-weight: bold; text-align: center}");
try{
//window
var xbmc_play_link = document.createElement('button');
xbmc_play_link.addEventListener('click', playMedia, false);
xbmc_play_link.innerHTML = '<span class="yt-uix-button-content">Play on XBMC</span>';
xbmc_play_link.setAttribute("id", "playXBMC");
xbmc_play_link.setAttribute("class", "yt-uix-button yt-uix-tooltip");
xbmc_play_link.setAttribute("type", "button");
xbmc_play_link.setAttribute("title", "Play this video on your XBMC");
xbmc_play_link.setAttribute("data-tooltip-title", "Play this video on your XBMC");
xbmc_play_link.setAttribute("data-tooltip-timer", "170");
document.getElementById('watch-headline-user-info').appendChild(xbmc_play_link);
}catch(e){
console.log(e)
}
},
10);