From 1a1758419ddbc539601bed53edde3a82532c0ca9 Mon Sep 17 00:00:00 2001 From: Bauke Date: Fri, 22 Dec 2023 14:50:21 +0100 Subject: [PATCH] Make TRX capable of running in a locally hosted Tildes for development. --- source/build.ts | 2 +- source/manifest.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/build.ts b/source/build.ts index a3081f9..1e2eff6 100644 --- a/source/build.ts +++ b/source/build.ts @@ -35,7 +35,7 @@ const sourceDir = toAbsolutePath("../source"); await fsp.mkdir(outDir, {recursive: true}); // Write the WebExtension manifest file. -const manifest = createManifest(browser); +const manifest = createManifest(browser, dev); await fsp.writeFile( path.join(outDir, "manifest.json"), JSON.stringify(manifest), diff --git a/source/manifest.ts b/source/manifest.ts index 3901319..6fc8c19 100644 --- a/source/manifest.ts +++ b/source/manifest.ts @@ -6,9 +6,13 @@ import {type Manifest} from "webextension-polyfill"; * Creates the WebExtension manifest based on the browser target. * * @param browser The browser target ("firefox" or "chromium"). + * @param dev Is this for development or production. * @returns The WebExtension manifest. */ -export function createManifest(browser: string): Manifest.WebExtensionManifest { +export function createManifest( + browser: string, + dev: boolean, +): Manifest.WebExtensionManifest { const manifest: Manifest.WebExtensionManifest = { manifest_version: Number.NaN, name: "Tildes ReExtended", @@ -29,6 +33,13 @@ export function createManifest(browser: string): Manifest.WebExtensionManifest { ], }; + if (dev) { + // Add the localhost permissions in development so TRX can run on a locally + // hosted Tildes. + manifest.permissions!.push("*://localhost/*"); + manifest.content_scripts![0].matches.push("https://*.localhost/*"); + } + const icons: Manifest.IconPath = { 128: "tildes-reextended.png", };