Skip to content

Instantly share code, notes, and snippets.

@Bolukan
Last active October 24, 2018 14:18
Show Gist options
  • Save Bolukan/267b9b6236df0182b34f7f96f2e2f4ef to your computer and use it in GitHub Desktop.
Save Bolukan/267b9b6236df0182b34f7f96f2e2f4ef to your computer and use it in GitHub Desktop.
Open Youtube video on KODI
// ==UserScript==
// @name Open Youtube on KODI
// @namespace https://github.com/Bolukan/
// @version 0.2
// @date 2018-10-24
// @description Open current youtube video on KODI
// @author Bollie
// @copyright 2018, Bollie
// @homepage https://github.com/Bolukan/
// @compatible chrome
// @compatible firefox
// @compatible opera
// @compatible safari
// @license MIT https://opensource.org/licenses/MIT
// @match *://*.youtube.com/*
// ==/UserScript==
(function() {
'use strict';
if (document.getElementById("polymer-app") || document.getElementById("masthead") || window.Polymer) {
setInterval(function() {
if (window.location.href.indexOf("watch?v=") < 0) {
return false;
}
if (document.getElementById("count") && document.getElementById("PlayOnKodi") === null) {
Addytpolymer();
}
}, 100);
}
function Addytpolymer() {
var sid=window.location.href.substring(window.location.href.indexOf("watch?v=")+8);
var buttonDiv = document.createElement("span");
buttonDiv.style.width = "100%";
buttonDiv.id = "PlayOnKodi";
var addButton = document.createElement("a");
addButton.appendChild(document.createTextNode("Play on KODI"));
addButton.style.width = "100%";
addButton.style.backgroundColor = "#15388c";
addButton.style.color = "white";
addButton.style.textAlign = "center";
addButton.style.padding = "5px 10px";
addButton.style.margin = "0px 10px";
addButton.style.fontSize = "14px";
addButton.style.border = "0";
addButton.style.cursor = "pointer";
addButton.style.borderRadius = "2px";
addButton.style.fontFamily = "Roboto, Arial, sans-serif";
addButton.style.textDecoration = "none";
addButton.href = "http://192.168.1.60/jsonrpc?request="+encodeURIComponent('{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"plugin://plugin.video.youtube/play/?video_id='+sid+'"}},"id":1}');
addButton.target = "_blank";
buttonDiv.appendChild(addButton);
var targetElement = document.querySelectorAll("[id='count']");
for (var i = 0; i < targetElement.length; i++) {
if (targetElement[i].className.indexOf("ytd-video-primary-info-renderer") > -1) {
targetElement[i].appendChild(buttonDiv);
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment