From 601ff195ff33a7c72f1b37e6185f1c1c1b584df6 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sat, 5 Mar 2022 19:10:41 +0100 Subject: [PATCH] add headers --- chrome/manifest.json | 3 ++- chrome/script.js | 31 ++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/chrome/manifest.json b/chrome/manifest.json index e62b549..462ce43 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -7,8 +7,9 @@ "48": "icon-48.png", "128": "icon-128.png" }, - "version": "102.0", + "version": "104.0", "manifest_version": 3, + "host_permissions": ["http://127.0.0.1:8083/jsonrpc", "http://127.0.0.1:8080/jsonrpc"], "permissions": ["tabs"], "action": { "default_title": "Proxy Stream", diff --git a/chrome/script.js b/chrome/script.js index 4a80a17..fb7fcb8 100644 --- a/chrome/script.js +++ b/chrome/script.js @@ -40,7 +40,7 @@ document.addEventListener("DOMContentLoaded", () => { newurl = new URL("plugin://plugin.video.youtube") search.append("action", "play_video") let video_id = oldurl.searchParams.get("v"); - if(newpath) { + if(video_id) { search.append("videoid", video_id) } } @@ -49,18 +49,35 @@ document.addEventListener("DOMContentLoaded", () => { let req = { jsonrpc: "2.0", method: "Player.Open", - id: secrets.token_hex(), + id: 12345, params: { item: { file: newurl.href } } } - - fetch("http://127.0.0.1:8083/jsonrpc", { - method: "POST", - body: JSON.stringify(req) - }).then(resp => console.log(resp)) + try { + fetch("http://127.0.0.1:8080/jsonrpc", { + method: "POST", + body: JSON.stringify(req), + headers: { + "Content-Type": "application/json; charset=utf-8" + } + }).then(resp => console.log(resp)) + } catch(e) { + console.log(e) + } + try { + fetch("http://127.0.0.1:8083/jsonrpc", { + method: "POST", + body: JSON.stringify(req), + headers: { + "Content-Type": "application/json; charset=utf-8" + } + }).then(resp => console.log(resp)) + } catch(e) { + console.log(e) + } }); }); });