mirror of
https://codeberg.org/LibRedirect/libredirect.git
synced 2025-02-09 08:38:40 +01:00
Added hard cancel requests, will be more improved
This commit is contained in:
parent
f69ff24201
commit
23be155b20
@ -5,9 +5,11 @@ import commonHelper from '../common.js'
|
|||||||
window.browser = window.browser || window.chrome;
|
window.browser = window.browser || window.chrome;
|
||||||
|
|
||||||
const targets = [
|
const targets = [
|
||||||
|
"studio.youtube.com",
|
||||||
"m.youtube.com",
|
"m.youtube.com",
|
||||||
"youtube.com",
|
"youtube.com",
|
||||||
"img.youtube.com",
|
"img.youtube.com",
|
||||||
|
"i.ytimg.com",
|
||||||
"www.youtube.com",
|
"www.youtube.com",
|
||||||
"youtube-nocookie.com",
|
"youtube-nocookie.com",
|
||||||
"www.youtube-nocookie.com",
|
"www.youtube-nocookie.com",
|
||||||
@ -243,7 +245,7 @@ function redirect(url, initiator, type) {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (url.host.split(".")[0] === "studio") return null;// Avoid `studio.youtube.com`
|
if (url.host.split(".")[0] === "studio") return null;// Avoid `studio.youtube.com`
|
||||||
|
|
||||||
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return null; // Don't redirect YouTube Player API.
|
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return null; // Don't redirect YouTube Player API.
|
||||||
|
|
||||||
if (frontend == 'freeTube' && type === "main_frame")
|
if (frontend == 'freeTube' && type === "main_frame")
|
||||||
@ -271,8 +273,6 @@ function redirect(url, initiator, type) {
|
|||||||
|
|
||||||
let randomInstance = commonHelper.getRandomInstance(redirects.piped.normal);
|
let randomInstance = commonHelper.getRandomInstance(redirects.piped.normal);
|
||||||
|
|
||||||
console.log(" redirects.invidious.normal.includes(url.hostname)", redirects.invidious.normal.includes(url.hostname))
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
url.hostname.endsWith("youtube.com") ||
|
url.hostname.endsWith("youtube.com") ||
|
||||||
url.hostname.endsWith("youtube-nocookie.com") ||
|
url.hostname.endsWith("youtube-nocookie.com") ||
|
||||||
@ -284,6 +284,7 @@ function redirect(url, initiator, type) {
|
|||||||
return `${randomInstance}/watch?v=${url.pathname.substring(1)}`;
|
return `${randomInstance}/watch?v=${url.pathname.substring(1)}`;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return 'CANCEL';
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -58,8 +58,14 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||||||
else if (wikipediaHelper.isWikipedia(url)) newUrl = wikipediaHelper.redirect(url, initiator);
|
else if (wikipediaHelper.isWikipedia(url)) newUrl = wikipediaHelper.redirect(url, initiator);
|
||||||
|
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
console.info("Redirecting", url.href, "=>", newUrl);
|
if (newUrl == 'CANCEL') {
|
||||||
return { redirectUrl: newUrl };
|
console.log(`Canceled ${url}`);
|
||||||
|
return { cancel: true };
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.info("Redirecting", url.href, "=>", newUrl);
|
||||||
|
return { redirectUrl: newUrl };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user