From bca922e0a1c1c161188dc2a6f415e6e60be2f8b4 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Wed, 10 Jul 2024 11:03:10 +0700 Subject: [PATCH] feat: userChrome.css for Floorp --- .ff-chrome/userChrome.css | 37 ++++++++++++++++++ user-chrome-setup.py | 79 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 .ff-chrome/userChrome.css create mode 100755 user-chrome-setup.py diff --git a/.ff-chrome/userChrome.css b/.ff-chrome/userChrome.css new file mode 100644 index 0000000..595f65c --- /dev/null +++ b/.ff-chrome/userChrome.css @@ -0,0 +1,37 @@ +/** + * Better Floorp vertical tabs + * + * This makes Floorp's (expanded) vertical tabs not affecting sites' width, + * which can cause lag on heavy websites like Twitch and YouTube. + * + * This also fixed vertical tabs' width breaking when some preference related + * to browser's "head" is changed + * + * Based on my changes fpr Pulse, but Pulse is dead. + * REF: https://github.com/null2264/pulse/commit/fce966a110c2987b08d35bcd04c5992655b24b13 + */ +:root { + /* from Floorp source code, too big for me */ + /*--hoverd-verticaltab-width: 20em;*/ + + --hoverd-verticaltab-width: 16em; +} + +@charset "UTF-8"; +@-moz-document url(chrome://browser/content/browser.xhtml) { +#TabsToolbar { + position: relative !important; + transition: all 300ms !important; + min-width: var(--default-verticaltab-width) !important; + max-width: var(--default-verticaltab-width) !important; + z-index: 1; /* Probably not needed, since Floorp already handle this */ +} + +#TabsToolbar:hover { + transition: all 300ms !important; + min-width: var(--hoverd-verticaltab-width) !important; + max-width: var(--hoverd-verticaltab-width) !important; + z-index: 2; /* Probably not needed, since Floorp already handle this */ + margin-right: calc((var(--hoverd-verticaltab-width) - var(--default-verticaltab-width)) * -1) !important; +} +} diff --git a/user-chrome-setup.py b/user-chrome-setup.py new file mode 100755 index 0000000..b4b3228 --- /dev/null +++ b/user-chrome-setup.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +""" +Install userChrome.css to $BROWSER's folder. + +Written in Python because I'm too lazy to deal with INI parser using bash. +""" + +import configparser +import os +import pathlib +import sys +from subprocess import run + +def bool_from_string(string: str | None, default: bool | None = None) -> bool: + lowered = (string or "").lower() + + if lowered in ("yes", "y", "true", "t", "1", "enable", "on"): + return True + elif lowered in ("no", "n", "false", "f", "0", "disable", "off"): + return False + + if default is not None: + return default + raise ValueError("Invalid Input") + +def die(message: str | None = None) -> None: + if message: + print(message, file=sys.stderr) + exit(1) + +config = configparser.ConfigParser() +home = os.getenv("HOME") +browser = os.getenv("BROWSER") +dotfiles = os.getenv("ZI_DOTFILES") + +if not dotfiles: + die("Please run pre-bootstrap first!") + +if not browser: + die("$BROWSER is not set!") + +tmp = run([browser, "--version"], capture_output=True, text=True) +if not tmp.stdout.startswith("Mozilla"): + die("Chrome-based browser is not supported!") + +if not "floorp" in tmp.stdout.lower(): + die("This script currently only support Floorp") + +browser_path = f"{home}/.{browser}" + +# Firefox doesn't support XDG path (yet?) +try: + # Firefox doesn't support XDG path (yet?) + config.read(f"{browser_path}/profiles.ini") +except: + die("Unable to read profile list") + +prompt = input("NOTE: Currently only support installing userChrome.css to default profile, continue anyway? [y/N] ") +if not bool_from_string(prompt, False): + exit(0) + +# profiles = [p for p in config.sections() if p.startswith("Profile")] +# default = next(config[p] for p in profiles if str(config[p].get("Default", "0")) == "1") + +_install = [p for p in config.sections() if p.startswith("Install")] +default_path = next(config[p] for p in _install) +profile_path = f"{browser_path}/{default_path['Default']}" +chrome_path = pathlib.Path(f"{profile_path}/chrome") +chrome_path.mkdir(parents=True, exist_ok=True) +user_chrome_path = chrome_path / "userChrome.css" +try: + user_chrome_path.symlink_to(f"{dotfiles}/.ff-chrome/userChrome.css") +except FileExistsError: + prompt = input("Overwrite existing userChrome.css? [y/N] ") + if not bool_from_string(prompt, False): + exit(0) + user_chrome_path.unlink() + user_chrome_path.symlink_to(f"{dotfiles}/.ff-chrome/userChrome.css") +print("userChrome.css has successfully installed.")