Initial commit
This commit is contained in:
commit
3454be6cf7
12 changed files with 302 additions and 0 deletions
3
scripts/background.js
Normal file
3
scripts/background.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { createSpaces } from "./spaces.mjs";
|
||||
|
||||
createSpaces();
|
11
scripts/listeners.mjs
Normal file
11
scripts/listeners.mjs
Normal file
|
@ -0,0 +1,11 @@
|
|||
export { changeUserAgent };
|
||||
|
||||
function changeUserAgent(details) {
|
||||
for (const header of details.requestHeaders) {
|
||||
if (header.name.toLowerCase() === "user-agent") {
|
||||
header.value = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return { requestHeaders: details.requestHeaders };
|
||||
}
|
49
scripts/spaces.mjs
Normal file
49
scripts/spaces.mjs
Normal file
|
@ -0,0 +1,49 @@
|
|||
import { changeUserAgent } from "./listeners.mjs";
|
||||
import { getApps, storeApps } from "./storage.mjs";
|
||||
|
||||
export { createSpaces, removeSpaces, hashSpaceName };
|
||||
|
||||
function hashSpaceName(url) {
|
||||
return btoa(url).replaceAll("=", "");
|
||||
}
|
||||
|
||||
async function createSpaces() {
|
||||
const apps = await getApps();
|
||||
|
||||
if (apps.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const urls = [];
|
||||
|
||||
apps.forEach(async (app) => {
|
||||
urls.push(app.url);
|
||||
await browser.spaces.create(app.name, app.url, {
|
||||
title: app.title,
|
||||
defaultIcons: app.icon,
|
||||
});
|
||||
});
|
||||
|
||||
const matchUrls = urls.map((url) => {
|
||||
return url.replace(/^(https?:\/\/).*((?<=[\/\.])[^\/\.?]*\.[^\/\.?]*)[\/?]?.*$/g, "$1*.$2/*");
|
||||
});
|
||||
|
||||
if (browser.webRequest.onBeforeSendHeaders.hasListener(changeUserAgent)) {
|
||||
browser.webRequest.onBeforeSendHeaders.removeListener(changeUserAgent);
|
||||
}
|
||||
|
||||
browser.webRequest.onBeforeSendHeaders.addListener(changeUserAgent, { urls: matchUrls }, [
|
||||
"requestHeaders",
|
||||
"blocking",
|
||||
]);
|
||||
}
|
||||
|
||||
async function removeSpaces() {
|
||||
const spaces = await browser.spaces.query({ isSelfOwned: true });
|
||||
|
||||
spaces.forEach(async (space) => {
|
||||
await browser.spaces.remove(space.id);
|
||||
});
|
||||
|
||||
await storeApps([]);
|
||||
}
|
17
scripts/storage.mjs
Normal file
17
scripts/storage.mjs
Normal file
|
@ -0,0 +1,17 @@
|
|||
export { storeApps, getApps };
|
||||
|
||||
async function storeApps(apps) {
|
||||
await browser.storage.sync.set({
|
||||
apps: apps,
|
||||
});
|
||||
}
|
||||
|
||||
async function getApps() {
|
||||
const res = await browser.storage.sync.get("apps");
|
||||
|
||||
if (res.apps === undefined) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return res.apps;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue