33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
|
let providers = new Map();
|
||
|
providers.set("www.youtube.com", "youtube");
|
||
|
providers.set("youtube.com", "youtube");
|
||
|
providers.set("youtu.be", "youtube");
|
||
|
|
||
|
document.addEventListener("DOMContentLoaded", () => {
|
||
|
let [button] = document.getElementsByTagName("button");
|
||
|
button.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");
|
||
|
let search = new URLSearchParams();
|
||
|
search.append("render", "true");
|
||
|
let hostname = oldurl.hostname.toLowerCase();
|
||
|
if(providers.has(hostname)) {
|
||
|
if(hostname.includes("youtube.com")) {
|
||
|
let newpath = oldurl.searchParams.get("v");
|
||
|
if((newpath instanceof String) || ((typeof newpath) === "string")) {
|
||
|
newurl.pathname = "/" + newpath;
|
||
|
}
|
||
|
} else {
|
||
|
newurl.pathname = oldurl.pathname;
|
||
|
}
|
||
|
search.append("provider", providers.get(hostname));
|
||
|
}
|
||
|
newurl.search = search.toString();
|
||
|
let tab = {};
|
||
|
tab.url = newurl.href;
|
||
|
chrome.tabs.create(tab);
|
||
|
});
|
||
|
});
|
||
|
});
|