mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 03:50:02 -04:00
Slightly debloated blacklist domain testing
This commit is contained in:
parent
a829af651d
commit
e19dc1d2ee
1 changed files with 4 additions and 5 deletions
|
@ -35,14 +35,13 @@ const uv = new UVServiceWorker();
|
||||||
let blacklist;
|
let blacklist;
|
||||||
fetch("/assets/json/blacklist.json").then(request => {
|
fetch("/assets/json/blacklist.json").then(request => {
|
||||||
request.json().then(jsonData => {
|
request.json().then(jsonData => {
|
||||||
blacklist = jsonData.map(
|
blacklist = new RegExp(jsonData.map(
|
||||||
domain => new RegExp(
|
domain =>
|
||||||
encodeURIComponent(domain)
|
encodeURIComponent(domain)
|
||||||
.replace(/([()])/g, "\\$1")
|
.replace(/([()])/g, "\\$1")
|
||||||
.replaceAll("*.", "(?:.+\\.)?")
|
.replaceAll("*.", "(?:.+\\.)?")
|
||||||
.replaceAll(".", "\\.")
|
.replaceAll(".", "\\.")
|
||||||
)
|
).join("|"));
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ self.addEventListener("fetch", (event) => {
|
||||||
// The one and only ghetto domain blacklist.
|
// The one and only ghetto domain blacklist.
|
||||||
if (!new URL(event.request.url).pathname.indexOf("/uv/service/")) {
|
if (!new URL(event.request.url).pathname.indexOf("/uv/service/")) {
|
||||||
const url = new URL(uv.config.decodeUrl(new URL(event.request.url).pathname.replace(/^\/uv\/service\//, "")));
|
const url = new URL(uv.config.decodeUrl(new URL(event.request.url).pathname.replace(/^\/uv\/service\//, "")));
|
||||||
if (blacklist.some(domain => domain.test(url.hostname)))
|
if (blacklist.test(url.hostname))
|
||||||
return new Response(new Blob(), {status: 406});
|
return new Response(new Blob(), {status: 406});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue