librewolf

This commit is contained in:
4DBug committed 2026-10-18 02:51:04 -05:00
1 parent 74076952e2
commit 08d30a3976
7 files changed
+145 -121

No files matched your search

@@ -0,0 +1,13 @@
const filter = { urls: ["*://*.youtube.com/*", "*://youtu.be/*"] };
// Full page loads (address bar, external links, new tabs).
browser.webRequest.onBeforeRequest.addListener(({ url }) => {
const redirectUrl = redirectFor(url);
if (redirectUrl) return { redirectUrl };
}, { ...filter, types: ["main_frame"] }, ["blocking"]);
// SPAs (e.g. YouTube) navigate via history.pushState, no request.
browser.webNavigation.onHistoryStateUpdated.addListener(({ tabId, frameId, url }) => {
const target = frameId === 0 && redirectFor(url);
if (target) browser.tabs.update(tabId, { url: target });
}, { url: [{ hostSuffix: "youtube.com" }] });
@@ -0,0 +1,17 @@
// Rewrite links just before they're used (click, middle-click, context menu),
// so "open in new tab" / "copy link" already point at the redirect target.
const rewrite = (e) => {
const a = e.target.closest?.("a[href]");
if (!a) return;
const target = redirectFor(new URL(a.href, location.href).href);
if (!target) return;
a.href = target;
if (e.type === "click" && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
e.preventDefault();
e.stopImmediatePropagation();
location.href = target;
}
};
for (const t of ["mousedown", "auxclick", "contextmenu", "click"])
document.addEventListener(t, rewrite, true);
@@ -0,0 +1,14 @@
{
"manifest_version": 2,
"name": "Redirect",
"version": "2.0",
"browser_specific_settings": { "gecko": { "id": "redirect@local" } },
"permissions": ["webRequest", "webRequestBlocking", "webNavigation", "tabs", "*://*.youtube.com/*", "*://youtu.be/*"],
"background": { "scripts": ["rules.js", "background.js"] },
"content_scripts": [{
"matches": ["*://*.youtube.com/*"],
"js": ["rules.js", "content.js"],
"run_at": "document_start",
"all_frames": true
}]
}
@@ -0,0 +1,17 @@
// Site rules: each returns a redirect URL or nothing. Add new sites here
// (and their hosts to manifest.json permissions/matches).
const rules = [
// YouTube -> Invidious
(u) => {
const q = u.search.slice(1);
if (/^(www\.|m\.)?youtube\.com$/.test(u.hostname) && u.pathname === "/watch")
return `https://@domain@/watch?${q}`;
if (u.hostname === "youtu.be" && u.pathname.length > 1)
return `https://@domain@/watch?v=${u.pathname.slice(1)}${q ? "&" + q : ""}`;
},
];
const redirectFor = (url) => {
const u = new URL(url);
for (const r of rules) { const t = r(u); if (t) return t; }
};
+37 -40
View File
@@ -1,44 +1,40 @@
{ lib, ... }: {
{ lib, inputs, ... }: {
flake-file.inputs.catppuccin-userstyles-nix = {
url = "github:4DBug/catppuccin-userstyles-nix";
url = "git+https://git.bug.tools/bug/userstyles";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-file.inputs.bugpass = {
url = "git+https://git.bug.tools/bug/bugpass";
flake = false;
};
den.aspects.software.browsers = {
homeManager = { host, ... }: {
# Redirector has no managed storage schema; import once via its settings.
xdg.configFile."redirector/invidious.json".text = builtins.toJSON {
createdBy = "Redirector v3.5.3";
createdAt = "2026-10-17T00:00:00.000Z";
redirects = map (r: {
error = null;
excludePattern = "";
patternDesc = "";
patternType = "R";
processMatches = "noProcessing";
disabled = false;
grouped = false;
appliesTo = [ "main_frame" ];
} // r) [
{
description = "YouTube to Invidious";
exampleUrl = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
exampleResult = "https://tube.${host.domain}/watch?v=dQw4w9WgXcQ";
includePattern = "^https?://(www\\.|m\\.)?youtube\\.com/watch\\?(.*)$";
redirectUrl = "https://tube.${host.domain}/watch?$2";
}
{
description = "youtu.be to Invidious";
exampleUrl = "https://youtu.be/dQw4w9WgXcQ";
exampleResult = "https://tube.${host.domain}/watch?v=dQw4w9WgXcQ&";
includePattern = "^https?://youtu\\.be/([^?&]+)\\??(.*)$";
redirectUrl = "https://tube.${host.domain}/watch?v=$1&$2";
}
];
homeManager = { host, pkgs, ... }: let
mkExtension = src: vars: extra: rec {
id = (builtins.fromJSON (builtins.readFile "${src}/manifest.json")).browser_specific_settings.gecko.id;
xpi = pkgs.runCommand "${lib.head (lib.splitString "@" id)}.xpi" { nativeBuildInputs = [ pkgs.zip ]; } ''
cp -r ${src} src && chmod -R u+w src && cd src
for f in $(find . -type f); do
substituteInPlace "$f" ${lib.concatStringsSep " " (lib.mapAttrsToList (k: v: "--replace-quiet @${k}@ ${lib.escapeShellArg v}") vars)}
done
${lib.optionalString (extra != null) "cp -r ${extra}/. ."}
zip -r -X $out .
'';
};
bugpass = import "${inputs.bugpass}/build" { inherit pkgs; };
localExtensions = [
(mkExtension ./_extensions/redirect { domain = "tube.${host.domain}"; } null)
(mkExtension "${inputs.bugpass}/extension" { } bugpass.lib)
];
in {
programs.librewolf = {
enable = true;
nativeMessagingHosts = [ bugpass.host ];
settings = {
"browser.startup.homepage" = "https://search.${host.domain}";
"browser.startup.page" = 3;
@@ -63,7 +59,7 @@
"browser.crashReports.unsubmittedCheck.enabled" = false;
"browser.crashReports.unsubmittedCheck.autoSubmit2" = false;
"privacy.resistFingerprinting.letterboxing" = true;
"privacy.resistFingerprinting.letterboxing" = false; # true adds a border around every page (window-size fingerprinting protection)
"privacy.donottrackheader.enabled" = true;
"privacy.globalprivacycontrol.enabled" = true;
"privacy.resistFingerprinting" = false;
@@ -97,6 +93,8 @@
"browser.theme.content-theme" = 0;
"layout.css.prefers-color-scheme.content-override" = 0;
"xpinstall.signatures.required" = false;
};
profiles.default = {
@@ -179,13 +177,13 @@
settings = {
"{7a7a4a92-a2a0-41d1-9fd7-1e92480d612d}" = {
force = true;
/*settings = inputs.catppuccin-userstyles-nix.stylusSettings.${pkgs.stdenv.hostPlatform.system} {
settings = inputs.catppuccin-userstyles-nix.stylusSettings.${pkgs.stdenv.hostPlatform.system} {
global = {
lightFlavor = "mocha";
darkFlavor = "mocha";
accentColor = "mauve";
};
};*/
};
};
};
};
@@ -234,14 +232,13 @@
"uBlock0@raymondhill.net" # ublock-origin
"contact@lesspass.com" # lesspass
"{a6c4a591-f1b2-4f03-b3ff-767e5bedf4e7}" # user-agent-string-switcher
"{762f9885-5a13-4abd-9c77-433dcd38b8fd}" # return-youtube-dislikes
"redirector@einaregilsson.com" # redirector
]);
]) // lib.listToAttrs (map (e: lib.nameValuePair e.id {
install_url = "file://${e.xpi}";
installation_mode = "force_installed";
}) localExtensions);
};
};
};