^Adjust to Invidious

This commit is contained in:
Nero 2023-06-17 14:12:32 +02:00
parent 312a0664f1
commit 5ea86baf06
3 changed files with 8 additions and 25 deletions

View file

@ -1,12 +1,8 @@
let ausnahme = false;
let w2gRegex = /w2g\.tv/;
// Einstellungen ziehen, ContentScript registrieren // Einstellungen ziehen, ContentScript registrieren
browser.storage.local.get( browser.storage.local.get(
{ {
activated: true, activated: true,
instance: "redirect.invidio.us", instance: "yewtu.be",
} }
).then((storage) => { ).then((storage) => {
if (storage.activated) { if (storage.activated) {
@ -71,25 +67,22 @@ browser.webRequest.onBeforeRequest.addListener(async (details) => {
let activated; let activated;
let instance; let instance;
let proxy;
let imageRedirect;
await browser.storage.local.get({ await browser.storage.local.get({
activated: true, activated: true,
instance: "redirect.invidio.us", instance: "yewtu.be",
imageRedirect: true
}).then((item) => { }).then((item) => {
activated = item.activated; activated = item.activated;
instance = item.instance; instance = item.instance;
imageRedirect = item.imageRedirect;
}); });
if (activated) { if (activated) {
const youtubeRegex = /youtube.com(\/?.*)/; const youtubeRegex = /youtube.com(\/?.*)/;
const youtubeShortRegex = /youtu.be\/.+/; const youtubeShortRegex = /youtu.be\/.+/;
if (imageRedirect && details.url.startsWith("https://img.youtube.com/vi")) { if (details.url.startsWith("https://img.youtube.com/vi")) {
return { redirectUrl: 'https://' + proxy + '/vi/' + details.url.split("/vi/")[1].split("/")[0] + "/hqdefault.jpg?host=i.ytimg.com" } console.log("JOOOOO");
return { redirectUrl: 'https://' + instance + '/vi/' + details.url.split("/vi/")[1].split("/")[0] + "/mqdefault.jpg" }
} }
else if (youtubeRegex.test(details.url)) { else if (youtubeRegex.test(details.url)) {
return { redirectUrl: 'https://' + instance + youtubeRegex.exec(details.url)[1] }; return { redirectUrl: 'https://' + instance + youtubeRegex.exec(details.url)[1] };

View file

@ -81,18 +81,12 @@
</style> </style>
<meta charset="utf-8"> <meta charset="utf-8">
</head> </head>
<body bgcolor="202023"> <body bgcolor="202023" style="padding: 2em">
<form> <form>
<p> <p>
Instance URL: Instance URL:
<input id="instance" class="textfield" placeholder="piped.kavin.rocks"/> <input id="instance" class="textfield" placeholder="piped.kavin.rocks"/>
<br> <br>
<label class="switch">
<input type="checkbox" id="imageRedirect">
<span class="slider" />
</label> Redirect images
<span title="Might cause not every image to be loaded">&#x2753;</span>
<br>
<button id="saveBtn" type="submit">Save</button> <button id="saveBtn" type="submit">Save</button>
</p> </p>
</form> </form>

View file

@ -3,14 +3,12 @@ document.querySelector("form").addEventListener("submit", (e) => {
e.preventDefault(); e.preventDefault();
let instance = document.querySelector("#instance").value.trim(); let instance = document.querySelector("#instance").value.trim();
instance = instance.replace(/^https?:?\/?\/?/, '').replace('\/$'); instance = instance.replace(/^https?:?\/?\/?/, '').replace('\/$');
proxy = proxy.replace(/^https?:?\/?\/?/, '').replace('\/$'); if (!instance) {
if (!instance || !proxy) {
return alert("Please fill out the fields!"); return alert("Please fill out the fields!");
} }
browser.storage.local.set({ browser.storage.local.set({
instance: instance, instance: instance,
imageRedirect: document.querySelector("#imageRedirect").checked
}).then(() => alert("Saved!")); }).then(() => alert("Saved!"));
}); });
@ -18,10 +16,8 @@ document.querySelector("form").addEventListener("submit", (e) => {
// Restore options // Restore options
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
browser.storage.local.get({ browser.storage.local.get({
imageRedirect: true, instance: "yewtu.be",
instance: "redirect.invidio.us",
}).then((item) => { }).then((item) => {
document.querySelector("#instance").value = item.instance; document.querySelector("#instance").value = item.instance;
document.querySelector("#imageRedirect").checked = item.imageRedirect;
}); });
}); });