Fix bug with clicking search suggestions, start working on proper API for hooking into the service worker.
This commit is contained in:
parent
8b3abae5f5
commit
fdae47c9b3
10 changed files with 22543 additions and 42 deletions
2
index.js
2
index.js
|
|
@ -51,7 +51,7 @@ app.use(compression({ threshold: 0, filter: () => true }));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
|
|
||||||
// Set process.env.MASQR_ENABLED to "true" to enable masqr protection.
|
// Set process.env.MASQR_ENABLED to "true" to enable masqr protection.
|
||||||
if (process.env.MASQR_ENABLED == "true") {
|
if (MASQR_ENABLED == "true") {
|
||||||
console.log(chalk.gray("Starting Masqr..."));
|
console.log(chalk.gray("Starting Masqr..."));
|
||||||
app.use(await masqrCheck({ whitelist: whiteListedDomains, licenseServer: LICENSE_SERVER_URL }));
|
app.use(await masqrCheck({ whitelist: whiteListedDomains, licenseServer: LICENSE_SERVER_URL }));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
console.log("Hello World!");
|
|
||||||
36
public/marketplace/adblock/adblocker.sw.js
Normal file
36
public/marketplace/adblock/adblocker.sw.js
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
importScripts("/libcurl/index.js");
|
||||||
|
importScripts("/epoxy/index.js");
|
||||||
|
importScripts("/bare_transport.js");
|
||||||
|
importScripts("/uv/uv.bundle.js");
|
||||||
|
importScripts("/uv.config.js");
|
||||||
|
importScripts(__uv$config.sw);
|
||||||
|
|
||||||
|
const uv = new UVServiceWorker();
|
||||||
|
|
||||||
|
let lowes = [];
|
||||||
|
let loadLowes = async () => {
|
||||||
|
await fetch ("/marketplace/adblock/peterlowes.json")
|
||||||
|
.then(response => response.json()).then(data => {
|
||||||
|
data.rules.forEach((rule) => {
|
||||||
|
lowes.push(rule["remote-domains"]);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
console.log("Loaded Peter Lowes' List!");
|
||||||
|
console.log(lowes)
|
||||||
|
}
|
||||||
|
loadLowes();
|
||||||
|
|
||||||
|
|
||||||
|
self.addEventListener("fetch", (event) => {
|
||||||
|
event.respondWith(
|
||||||
|
(async () => {
|
||||||
|
if (lowes.some((lowe) => __uv$config.decodeUrl(event.request.url).includes(lowe))){
|
||||||
|
return new Response("Blocked by Peter Lowes", {status: 403});
|
||||||
|
}
|
||||||
|
if (event.request.url.startsWith(location.origin + __uv$config.prefix)) {
|
||||||
|
return await uv.fetch(event);
|
||||||
|
}
|
||||||
|
return await fetch(event.request);
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
});
|
||||||
22441
public/marketplace/adblock/peterlowes.json
Normal file
22441
public/marketplace/adblock/peterlowes.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -16,4 +16,4 @@ self.addEventListener("fetch", (event) => {
|
||||||
return await fetch(event.request);
|
return await fetch(event.request);
|
||||||
})()
|
})()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -129,6 +129,30 @@
|
||||||
iframe.classList.add("active");
|
iframe.classList.add("active");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadExtensionScripts() {
|
||||||
|
try {
|
||||||
|
let db = indexedDB.open("AluDB", 1);
|
||||||
|
db.onsuccess = () => {
|
||||||
|
let transaction = db.result.transaction("InstalledExtensions", "readonly");
|
||||||
|
let store = transaction.objectStore("InstalledExtensions");
|
||||||
|
let request = store.getAll();
|
||||||
|
request.onsuccess = () => {
|
||||||
|
let extensions = request.result;
|
||||||
|
console.log(extensions);
|
||||||
|
extensions.forEach((extension: any) => {
|
||||||
|
// Eval the extension script inside of the iframe
|
||||||
|
if (iframe.contentWindow) {
|
||||||
|
console.log(`Evaluating extension "${extension.title}" inside of the iframe.`);
|
||||||
|
(iframe.contentWindow as any).eval(atob(extension.script));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Failed load extension scripts: ${err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function iframeLoad(
|
function iframeLoad(
|
||||||
iframe: HTMLIFrameElement,
|
iframe: HTMLIFrameElement,
|
||||||
loadingContent: HTMLElement,
|
loadingContent: HTMLElement,
|
||||||
|
|
@ -144,6 +168,7 @@
|
||||||
topbar.style.pointerEvents = "auto";
|
topbar.style.pointerEvents = "auto";
|
||||||
document.body.style.overflow = "hidden";
|
document.body.style.overflow = "hidden";
|
||||||
iframe.addEventListener("load", setActive);
|
iframe.addEventListener("load", setActive);
|
||||||
|
iframe.addEventListener("load", loadExtensionScripts);
|
||||||
closeButton.onclick = () => {
|
closeButton.onclick = () => {
|
||||||
iframe.style.opacity = "0";
|
iframe.style.opacity = "0";
|
||||||
topbar.style.opacity = "0";
|
topbar.style.opacity = "0";
|
||||||
|
|
@ -152,7 +177,7 @@
|
||||||
document.body.style.overflow = "auto";
|
document.body.style.overflow = "auto";
|
||||||
iframe.classList.remove("active");
|
iframe.classList.remove("active");
|
||||||
iframe.removeEventListener("load", setActive);
|
iframe.removeEventListener("load", setActive);
|
||||||
|
iframe.removeEventListener("load", loadExtensionScripts);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
iframe.src = "about:blank";
|
iframe.src = "about:blank";
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
@ -203,6 +228,7 @@
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
window.loadFormContent = loadContent;
|
window.loadFormContent = loadContent;
|
||||||
|
window.loadSelectedTransport = loadSelectedTransportScript;
|
||||||
|
|
||||||
function isUrl(val = "") {
|
function isUrl(val = "") {
|
||||||
if (/^http(s?):\/\//.test(val) || (val.includes(".") && val.substr(0, 1) !== " ")) return true;
|
if (/^http(s?):\/\//.test(val) || (val.includes(".") && val.substr(0, 1) !== " ")) return true;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ declare global {
|
||||||
decodeUrl: (url: string) => string;
|
decodeUrl: (url: string) => string;
|
||||||
};
|
};
|
||||||
loadFormContent: Function | null;
|
loadFormContent: Function | null;
|
||||||
|
loadSelectedTransport: Function | null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,7 @@
|
||||||
"title": "Adblocker",
|
"title": "Adblocker",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"image": "/marketplace/adblock/adblock.png",
|
"image": "/marketplace/adblock/adblock.png",
|
||||||
"script": "/marketplace/adblock/adblocker.js"
|
"script": "/marketplace/adblock/adblocker.sw.js",
|
||||||
},
|
"serviceWorkerExtension": true
|
||||||
"dev.wearr.adblock2": {
|
|
||||||
"title": "Adblocker2",
|
|
||||||
"version": "0.0.2",
|
|
||||||
"image": "/marketplace/adblock/adblock.png",
|
|
||||||
"script": "/marketplace/adblock/adblocker.js"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,31 +82,35 @@ export function getStaticPaths() {
|
||||||
await registerSW();
|
await registerSW();
|
||||||
|
|
||||||
async function sendAPIRequest(urlInput: HTMLInputElement, searchSuggestions: HTMLDivElement) {
|
async function sendAPIRequest(urlInput: HTMLInputElement, searchSuggestions: HTMLDivElement) {
|
||||||
if (!urlInput) throw new Error("urlInput is null");
|
try {
|
||||||
if (!searchSuggestions) throw new Error("searchSuggestions is null");
|
if (!urlInput) throw new Error("urlInput is null");
|
||||||
let url = urlInput.value;
|
if (!searchSuggestions) throw new Error("searchSuggestions is null");
|
||||||
let request = await fetch("/search?query=" + url);
|
let url = urlInput.value;
|
||||||
let data = await request.json();
|
let request = await fetch("/search?query=" + url);
|
||||||
searchSuggestions.innerHTML = "";
|
let data = await request.json();
|
||||||
data.map((suggestion: Suggestion) => {
|
searchSuggestions.innerHTML = "";
|
||||||
let suggestionElement = document.createElement("div");
|
data.map((suggestion: Suggestion) => {
|
||||||
// For some reason css classes weren't working T^T.
|
let suggestionElement = document.createElement("div");
|
||||||
suggestionElement.style.cursor = "pointer";
|
// For some reason css classes weren't working T^T.
|
||||||
suggestionElement.style.marginTop = "5px";
|
suggestionElement.style.cursor = "pointer";
|
||||||
suggestionElement.innerText = suggestion.phrase;
|
suggestionElement.style.marginTop = "5px";
|
||||||
suggestionElement.addEventListener("click", async () => {
|
suggestionElement.innerText = suggestion.phrase;
|
||||||
urlInput.value = suggestion.phrase;
|
suggestionElement.addEventListener("click", async () => {
|
||||||
// I can't be bothered to extend the window object, so I'm just going to use any
|
urlInput.value = suggestion.phrase;
|
||||||
(window as any).loadFormContent();
|
if (window.loadSelectedTransport) await window.loadSelectedTransport()
|
||||||
|
if (window.loadFormContent) window.loadFormContent(suggestion.phrase);
|
||||||
|
});
|
||||||
|
searchSuggestions.appendChild(suggestionElement);
|
||||||
});
|
});
|
||||||
searchSuggestions.appendChild(suggestionElement);
|
if (data.length === 0) {
|
||||||
});
|
urlInput.classList.remove("search-results");
|
||||||
if (data.length === 0) {
|
searchSuggestions.style.opacity = "0";
|
||||||
urlInput.classList.remove("search-results");
|
} else {
|
||||||
searchSuggestions.style.opacity = "0";
|
urlInput.classList.add("search-results");
|
||||||
} else {
|
searchSuggestions.style.opacity = "1";
|
||||||
urlInput.classList.add("search-results");
|
}
|
||||||
searchSuggestions.style.opacity = "1";
|
} catch {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ type MarketplaceItem = {
|
||||||
Object.keys(marketplace).map((mp_item) => {
|
Object.keys(marketplace).map((mp_item) => {
|
||||||
const item = (marketplace as { [key: string]: MarketplaceItem })[mp_item];
|
const item = (marketplace as { [key: string]: MarketplaceItem })[mp_item];
|
||||||
const slug = mp_item;
|
const slug = mp_item;
|
||||||
console.log(slug);
|
|
||||||
return (
|
return (
|
||||||
<div class="marketplace-item" data-slug={slug}>
|
<div class="marketplace-item" data-slug={slug}>
|
||||||
<img class="marketplace-item-image" src={item.image} alt={`${item.title} Logo`} />
|
<img class="marketplace-item-image" src={item.image} alt={`${item.title} Logo`} />
|
||||||
|
|
@ -64,7 +63,6 @@ type MarketplaceItem = {
|
||||||
.then((code) => {
|
.then((code) => {
|
||||||
let notifMessage = "";
|
let notifMessage = "";
|
||||||
let timeout = 2000;
|
let timeout = 2000;
|
||||||
console.log(code);
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 0:
|
case 0:
|
||||||
notifMessage = `Installed ${title} Successfully!`;
|
notifMessage = `Installed ${title} Successfully!`;
|
||||||
|
|
@ -100,11 +98,12 @@ type MarketplaceItem = {
|
||||||
version: string | number;
|
version: string | number;
|
||||||
image: string;
|
image: string;
|
||||||
script: string;
|
script: string;
|
||||||
|
scriptBtoa: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getMarketplaceObj(slug: string): Promise<ExtensionMetadata> {
|
async function getMarketplaceObj(slug: string): Promise<ExtensionMetadata> {
|
||||||
const manifest = (marketplaceManifest as { [key: string]: MarketplaceItem })[slug];
|
const manifest = (marketplaceManifest as unknown as { [key: string]: MarketplaceItem })[slug];
|
||||||
manifest.script = btoa(await fetch(manifest.script).then((res) => res.text()));
|
manifest.scriptBtoa = btoa(await fetch(manifest.script).then((res) => res.text()));
|
||||||
return manifest;
|
return manifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,6 +111,7 @@ type MarketplaceItem = {
|
||||||
title: string;
|
title: string;
|
||||||
version: string | number;
|
version: string | number;
|
||||||
script: string;
|
script: string;
|
||||||
|
scriptBtoa: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EXT_RETURN {
|
enum EXT_RETURN {
|
||||||
|
|
@ -137,12 +137,11 @@ type MarketplaceItem = {
|
||||||
slug: slug,
|
slug: slug,
|
||||||
title: ext.title,
|
title: ext.title,
|
||||||
version: ext.version,
|
version: ext.version,
|
||||||
script: ext.script,
|
script: ext.scriptBtoa,
|
||||||
};
|
};
|
||||||
// Check if the key already exists in the IDB
|
// Check if the key already exists in the IDB
|
||||||
let slugCheck = store.get(slug);
|
let slugCheck = store.get(slug);
|
||||||
slugCheck.onsuccess = async () => {
|
slugCheck.onsuccess = async () => {
|
||||||
console.log(slugCheck.result);
|
|
||||||
if (slugCheck.result != undefined) {
|
if (slugCheck.result != undefined) {
|
||||||
resolve(EXT_RETURN.ALREADY_INSTALLED);
|
resolve(EXT_RETURN.ALREADY_INSTALLED);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -173,7 +172,7 @@ type MarketplaceItem = {
|
||||||
request.onerror = (event: Event) => {
|
request.onerror = (event: Event) => {
|
||||||
console.error("Database error: " + (event.target as any).errorCode);
|
console.error("Database error: " + (event.target as any).errorCode);
|
||||||
};
|
};
|
||||||
request.onsuccess = (event) => {
|
request.onsuccess = () => {
|
||||||
console.log("Database opened successfully");
|
console.log("Database opened successfully");
|
||||||
};
|
};
|
||||||
request.onupgradeneeded = (event) => {
|
request.onupgradeneeded = (event) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue