From f6b708b247f18c1034a2fe31925d82722b910e61 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sat, 5 Mar 2022 17:49:14 +0100 Subject: [PATCH] add kodi demo --- chrome/manifest.json | 2 +- chrome/popup.html | 1 + chrome/script.js | 39 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/chrome/manifest.json b/chrome/manifest.json index c92a2bc..e62b549 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -7,7 +7,7 @@ "48": "icon-48.png", "128": "icon-128.png" }, - "version": "100.0", + "version": "102.0", "manifest_version": 3, "permissions": ["tabs"], "action": { diff --git a/chrome/popup.html b/chrome/popup.html index 6210f3e..a6ed532 100644 --- a/chrome/popup.html +++ b/chrome/popup.html @@ -5,5 +5,6 @@ + diff --git a/chrome/script.js b/chrome/script.js index 369355a..4a80a17 100644 --- a/chrome/script.js +++ b/chrome/script.js @@ -3,11 +3,11 @@ providers.set("www.youtube.com", "youtube"); providers.set("youtube.com", "youtube"); providers.set("youtu.be", "youtube"); providers.set("tv.nrk.no", "nrk"); -providers.set("nx12210.your-storageshare.de", "nextcloud"); +providers.set("seafile.purser.it", "seafile"); document.addEventListener("DOMContentLoaded", () => { - let [button] = document.getElementsByTagName("button"); - button.addEventListener("click", (ev) => { + let [proxyButton, kodiButton] = document.getElementsByTagName("button"); + proxyButton.addEventListener("click", (ev) => { chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { let oldurl = new URL(tabs[0].url); let newurl = new URL("https://stream.purser.it"); @@ -30,4 +30,37 @@ document.addEventListener("DOMContentLoaded", () => { chrome.tabs.create(tab); }); }); + kodiButton.addEventListener("click", (ev) => { + chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { + let oldurl = new URL(tabs[0].url); + let newurl = new URL(tabs[0].url); + let search = new URLSearchParams(); + let hostname = oldurl.hostname.toLowerCase(); + if(hostname.includes("youtube.com")) { + newurl = new URL("plugin://plugin.video.youtube") + search.append("action", "play_video") + let video_id = oldurl.searchParams.get("v"); + if(newpath) { + search.append("videoid", video_id) + } + } + newurl.search = search.toString(); + + let req = { + jsonrpc: "2.0", + method: "Player.Open", + id: secrets.token_hex(), + params: { + item: { + file: newurl.href + } + } + } + + fetch("http://127.0.0.1:8083/jsonrpc", { + method: "POST", + body: JSON.stringify(req) + }).then(resp => console.log(resp)) + }); + }); });