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());
|
||||
|
||||
// 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..."));
|
||||
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);
|
||||
})()
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -129,6 +129,30 @@
|
|||
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(
|
||||
iframe: HTMLIFrameElement,
|
||||
loadingContent: HTMLElement,
|
||||
|
|
@ -144,6 +168,7 @@
|
|||
topbar.style.pointerEvents = "auto";
|
||||
document.body.style.overflow = "hidden";
|
||||
iframe.addEventListener("load", setActive);
|
||||
iframe.addEventListener("load", loadExtensionScripts);
|
||||
closeButton.onclick = () => {
|
||||
iframe.style.opacity = "0";
|
||||
topbar.style.opacity = "0";
|
||||
|
|
@ -152,7 +177,7 @@
|
|||
document.body.style.overflow = "auto";
|
||||
iframe.classList.remove("active");
|
||||
iframe.removeEventListener("load", setActive);
|
||||
|
||||
iframe.removeEventListener("load", loadExtensionScripts);
|
||||
setTimeout(() => {
|
||||
iframe.src = "about:blank";
|
||||
}, 500);
|
||||
|
|
@ -203,6 +228,7 @@
|
|||
}, 200);
|
||||
}
|
||||
window.loadFormContent = loadContent;
|
||||
window.loadSelectedTransport = loadSelectedTransportScript;
|
||||
|
||||
function isUrl(val = "") {
|
||||
if (/^http(s?):\/\//.test(val) || (val.includes(".") && val.substr(0, 1) !== " ")) return true;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ declare global {
|
|||
decodeUrl: (url: string) => string;
|
||||
};
|
||||
loadFormContent: Function | null;
|
||||
loadSelectedTransport: Function | null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,7 @@
|
|||
"title": "Adblocker",
|
||||
"version": "0.0.1",
|
||||
"image": "/marketplace/adblock/adblock.png",
|
||||
"script": "/marketplace/adblock/adblocker.js"
|
||||
},
|
||||
"dev.wearr.adblock2": {
|
||||
"title": "Adblocker2",
|
||||
"version": "0.0.2",
|
||||
"image": "/marketplace/adblock/adblock.png",
|
||||
"script": "/marketplace/adblock/adblocker.js"
|
||||
"script": "/marketplace/adblock/adblocker.sw.js",
|
||||
"serviceWorkerExtension": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,31 +82,35 @@ export function getStaticPaths() {
|
|||
await registerSW();
|
||||
|
||||
async function sendAPIRequest(urlInput: HTMLInputElement, searchSuggestions: HTMLDivElement) {
|
||||
if (!urlInput) throw new Error("urlInput is null");
|
||||
if (!searchSuggestions) throw new Error("searchSuggestions is null");
|
||||
let url = urlInput.value;
|
||||
let request = await fetch("/search?query=" + url);
|
||||
let data = await request.json();
|
||||
searchSuggestions.innerHTML = "";
|
||||
data.map((suggestion: Suggestion) => {
|
||||
let suggestionElement = document.createElement("div");
|
||||
// For some reason css classes weren't working T^T.
|
||||
suggestionElement.style.cursor = "pointer";
|
||||
suggestionElement.style.marginTop = "5px";
|
||||
suggestionElement.innerText = suggestion.phrase;
|
||||
suggestionElement.addEventListener("click", async () => {
|
||||
urlInput.value = suggestion.phrase;
|
||||
// I can't be bothered to extend the window object, so I'm just going to use any
|
||||
(window as any).loadFormContent();
|
||||
try {
|
||||
if (!urlInput) throw new Error("urlInput is null");
|
||||
if (!searchSuggestions) throw new Error("searchSuggestions is null");
|
||||
let url = urlInput.value;
|
||||
let request = await fetch("/search?query=" + url);
|
||||
let data = await request.json();
|
||||
searchSuggestions.innerHTML = "";
|
||||
data.map((suggestion: Suggestion) => {
|
||||
let suggestionElement = document.createElement("div");
|
||||
// For some reason css classes weren't working T^T.
|
||||
suggestionElement.style.cursor = "pointer";
|
||||
suggestionElement.style.marginTop = "5px";
|
||||
suggestionElement.innerText = suggestion.phrase;
|
||||
suggestionElement.addEventListener("click", async () => {
|
||||
urlInput.value = suggestion.phrase;
|
||||
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");
|
||||
searchSuggestions.style.opacity = "0";
|
||||
} else {
|
||||
urlInput.classList.add("search-results");
|
||||
searchSuggestions.style.opacity = "1";
|
||||
if (data.length === 0) {
|
||||
urlInput.classList.remove("search-results");
|
||||
searchSuggestions.style.opacity = "0";
|
||||
} else {
|
||||
urlInput.classList.add("search-results");
|
||||
searchSuggestions.style.opacity = "1";
|
||||
}
|
||||
} catch {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ type MarketplaceItem = {
|
|||
Object.keys(marketplace).map((mp_item) => {
|
||||
const item = (marketplace as { [key: string]: MarketplaceItem })[mp_item];
|
||||
const slug = mp_item;
|
||||
console.log(slug);
|
||||
return (
|
||||
<div class="marketplace-item" data-slug={slug}>
|
||||
<img class="marketplace-item-image" src={item.image} alt={`${item.title} Logo`} />
|
||||
|
|
@ -64,7 +63,6 @@ type MarketplaceItem = {
|
|||
.then((code) => {
|
||||
let notifMessage = "";
|
||||
let timeout = 2000;
|
||||
console.log(code);
|
||||
switch (code) {
|
||||
case 0:
|
||||
notifMessage = `Installed ${title} Successfully!`;
|
||||
|
|
@ -100,11 +98,12 @@ type MarketplaceItem = {
|
|||
version: string | number;
|
||||
image: string;
|
||||
script: string;
|
||||
scriptBtoa: string | null;
|
||||
};
|
||||
|
||||
async function getMarketplaceObj(slug: string): Promise<ExtensionMetadata> {
|
||||
const manifest = (marketplaceManifest as { [key: string]: MarketplaceItem })[slug];
|
||||
manifest.script = btoa(await fetch(manifest.script).then((res) => res.text()));
|
||||
const manifest = (marketplaceManifest as unknown as { [key: string]: MarketplaceItem })[slug];
|
||||
manifest.scriptBtoa = btoa(await fetch(manifest.script).then((res) => res.text()));
|
||||
return manifest;
|
||||
}
|
||||
|
||||
|
|
@ -112,6 +111,7 @@ type MarketplaceItem = {
|
|||
title: string;
|
||||
version: string | number;
|
||||
script: string;
|
||||
scriptBtoa: string | null;
|
||||
}
|
||||
|
||||
enum EXT_RETURN {
|
||||
|
|
@ -137,12 +137,11 @@ type MarketplaceItem = {
|
|||
slug: slug,
|
||||
title: ext.title,
|
||||
version: ext.version,
|
||||
script: ext.script,
|
||||
script: ext.scriptBtoa,
|
||||
};
|
||||
// Check if the key already exists in the IDB
|
||||
let slugCheck = store.get(slug);
|
||||
slugCheck.onsuccess = async () => {
|
||||
console.log(slugCheck.result);
|
||||
if (slugCheck.result != undefined) {
|
||||
resolve(EXT_RETURN.ALREADY_INSTALLED);
|
||||
} else {
|
||||
|
|
@ -173,7 +172,7 @@ type MarketplaceItem = {
|
|||
request.onerror = (event: Event) => {
|
||||
console.error("Database error: " + (event.target as any).errorCode);
|
||||
};
|
||||
request.onsuccess = (event) => {
|
||||
request.onsuccess = () => {
|
||||
console.log("Database opened successfully");
|
||||
};
|
||||
request.onupgradeneeded = (event) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue