support other services

This commit is contained in:
Roy Olav Purser 2022-03-05 20:04:04 +01:00
parent e8d4f1f329
commit 57decd2fe2
Signed by: roypur
GPG Key ID: E14D26A036F21656
2 changed files with 48 additions and 51 deletions

View File

@ -7,9 +7,9 @@
"48": "icon-48.png", "48": "icon-48.png",
"128": "icon-128.png" "128": "icon-128.png"
}, },
"version": "104.0", "version": "106.0",
"manifest_version": 3, "manifest_version": 3,
"host_permissions": ["http://127.0.0.1:8083/jsonrpc", "http://127.0.0.1:8080/jsonrpc"], "host_permissions": ["http://127.0.0.1:4000/jsonrpc"],
"permissions": ["tabs"], "permissions": ["tabs"],
"action": { "action": {
"default_title": "Proxy Stream", "default_title": "Proxy Stream",

View File

@ -1,50 +1,57 @@
let providers = new Map(); let providers = new Map()
providers.set("www.youtube.com", "youtube"); providers.set("www.youtube.com", "youtube")
providers.set("youtube.com", "youtube"); providers.set("youtube.com", "youtube")
providers.set("youtu.be", "youtube"); providers.set("youtu.be", "youtube")
providers.set("tv.nrk.no", "nrk"); providers.set("tv.nrk.no", "nrk")
providers.set("seafile.purser.it", "seafile"); providers.set("seafile.purser.it", "seafile")
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
let [proxyButton, kodiButton] = document.getElementsByTagName("button"); let [proxyButton, kodiButton] = document.getElementsByTagName("button")
proxyButton.addEventListener("click", (ev) => { proxyButton.addEventListener("click", (ev) => {
chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { chrome.tabs.query({currentWindow: true, active: true}, (tabs) => {
let oldurl = new URL(tabs[0].url); let oldurl = new URL(tabs[0].url)
let newurl = new URL("https://stream.purser.it"); let newurl = new URL("https://stream.purser.it")
let search = new URLSearchParams(); let search = new URLSearchParams()
let hostname = oldurl.hostname.toLowerCase(); let hostname = oldurl.hostname.toLowerCase()
if(providers.has(hostname)) { if(providers.has(hostname)) {
if(hostname.includes("youtube.com")) { if(hostname.includes("youtube.com")) {
let newpath = oldurl.searchParams.get("v"); let newpath = oldurl.searchParams.get("v")
if((newpath instanceof String) || ((typeof newpath) === "string")) { if((newpath instanceof String) || ((typeof newpath) === "string")) {
newurl.pathname = "/" + newpath; newurl.pathname = "/" + newpath
} }
} else { } else {
newurl.pathname = oldurl.pathname; newurl.pathname = oldurl.pathname
} }
search.append("provider", providers.get(hostname)); search.append("provider", providers.get(hostname))
} }
newurl.search = search.toString(); newurl.search = search.toString()
let tab = {}; let tab = {}
tab.url = newurl.href; tab.url = newurl.href
chrome.tabs.create(tab); chrome.tabs.create(tab)
}); })
}); })
kodiButton.addEventListener("click", (ev) => { kodiButton.addEventListener("click", (ev) => {
chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { chrome.tabs.query({currentWindow: true, active: true}, (tabs) => {
let oldurl = new URL(tabs[0].url); let oldurl = new URL(tabs[0].url)
let newurl = new URL(tabs[0].url); let newurl = new URL("https://stream.purser.it")
let search = new URLSearchParams(); let search = new URLSearchParams()
let hostname = oldurl.hostname.toLowerCase(); let hostname = oldurl.hostname.toLowerCase()
if(providers.has(hostname)) {
if(hostname.includes("youtube.com")) { if(hostname.includes("youtube.com")) {
newurl = new URL("plugin://plugin.video.youtube") newurl = new URL("plugin://plugin.video.youtube")
search.append("action", "play_video") search.append("action", "play_video")
let video_id = oldurl.searchParams.get("v"); let video_id = oldurl.searchParams.get("v")
if(video_id) { if(video_id) {
search.append("videoid", video_id) search.append("videoid", video_id)
} }
} else {
search.append("provider", providers.get(hostname))
search.append("raw", "true")
newurl.pathname = oldurl.pathname
} }
newurl.search = search.toString(); }
newurl.search = search.toString()
let req = { let req = {
jsonrpc: "2.0", jsonrpc: "2.0",
@ -56,28 +63,18 @@ document.addEventListener("DOMContentLoaded", () => {
} }
} }
} }
try { try {
fetch("http://127.0.0.1:8080/jsonrpc", { fetch("http://127.0.0.1:4000/jsonrpc", {
method: "POST", method: "POST",
body: JSON.stringify(req), body: JSON.stringify(req),
headers: { headers: {
"Content-Type": "application/json; charset=utf-8" "Content-Type": "application/json charset=utf-8"
} }
}).then(resp => console.log(resp)) }).then(resp => console.log(resp))
} catch(e) { } catch(e) {
console.log(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)
}
});
});
});