Add configuration files for system settings and browser preferences

- Create registry.csv to define various Windows registry settings for privacy, telemetry, and UI preferences.
- Add betterfoxoverrides.js for Firefox to restore login manager, address and credit card manager, and customize new tab page settings.
- Introduce smoothfox.js for Firefox to enable smooth scrolling and adjust mouse wheel settings.
- Establish registry.yaml to organize and document registry paths and values for system, appearance, search, privacy, and application settings.
This commit is contained in:
2026-05-17 23:22:39 +08:00
parent fb01c80ee0
commit c553fbdba5
6 changed files with 727 additions and 332 deletions

View File

@@ -70,22 +70,34 @@ if (-not ($systemPathReference -split ";" | Where-Object { $_ -eq $forgeScriptsP
# Define the base Firefox profiles directory
$profilesDir = "$env:APPDATA\Mozilla\Firefox\Profiles"
# Define the source user.js file
$sourceFile = "$scriptDir\Firefox\user.js" # Use absolute path based on script location
# Download latest Betterfox user.js and append overrides
Write-Host "Downloading latest Betterfox user.js..."
$betterfoxUrl = "https://raw.githubusercontent.com/yokoffing/Betterfox/main/user.js"
$betterfoxContent = (Invoke-WebRequest -Uri $betterfoxUrl -UseBasicParsing).Content
# Check if the source file exists
if (-not (Test-Path -Path $sourceFile)) {
Write-Error "Source user.js file not found at $sourceFile"
exit
# Read local override files
$overridesFile = "$scriptDir\Firefox\betterfoxoverrides.js"
$smoothfoxFile = "$scriptDir\Firefox\smoothfox.js"
$overridesContent = Get-Content -Path $overridesFile -Raw
$smoothfoxContent = Get-Content -Path $smoothfoxFile -Raw
# Insert overrides at the marked sections in Betterfox
$personalMarker = "// Enter your personal overrides below this line:"
$scrollingMarker = "// Enter your scrolling overrides below this line:"
if ($betterfoxContent -match [regex]::Escape($personalMarker)) {
$betterfoxContent = $betterfoxContent -replace [regex]::Escape($personalMarker), "$personalMarker`n$overridesContent"
}
if ($betterfoxContent -match [regex]::Escape($scrollingMarker)) {
$betterfoxContent = $betterfoxContent -replace [regex]::Escape($scrollingMarker), "$scrollingMarker`n$smoothfoxContent"
}
# Loop through all subdirectories in the profiles folder
# Deploy to all Firefox profiles
Get-ChildItem -Path $profilesDir -Directory | ForEach-Object {
$profilePath = $_.FullName
$destinationFile = Join-Path -Path $profilePath -ChildPath "user.js"
# Copy the user.js file to the profile directory
Copy-Item -Path $sourceFile -Destination $destinationFile -Force
Set-Content -Path $destinationFile -Value $betterfoxContent -Force
Write-Host "user.js has been placed in: $profilePath"
}
@@ -93,27 +105,25 @@ Write-Host "Operation completed for all Firefox profiles."
# Path to the CSV file
$csvFilePath = "$scriptDir\registry.csv"
$entries = Import-Csv -Path $csvFilePath
# Path to the YAML registry file
$yamlFilePath = "$scriptDir\registry.yaml"
$yamlContent = Get-Content -Path $yamlFilePath -Raw
foreach ($entry in $entries) {
# Trim fields to remove extra spaces
$registryPath = $entry.registryPath.Trim()
$propertyName = $entry.propertyName.Trim()
$propertyType = $entry.propertyType.Trim()
$propertyValue = $entry.propertyValue.Trim()
# Install powershell-yaml if not already available
if (-not (Get-Module -ListAvailable -Name powershell-yaml)) {
Write-Host "Installing powershell-yaml module..."
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null
Install-Module -Name powershell-yaml -Force -Scope CurrentUser
}
Import-Module powershell-yaml
# Validate required fields
if (-not $registryPath -or -not $propertyName -or -not $propertyType -or -not $propertyValue) {
Write-Warning "Skipping row with incomplete data: $($entry | Out-String)"
continue
}
$blocks = ConvertFrom-Yaml $yamlContent
# Print debug info
#Write-Host "Processing: Path=$registryPath Name=$propertyName Type=$propertyType Value=$propertyValue"
foreach ($block in $blocks) {
$registryPath = $block.path
$defaultType = $block.type # May be null if values use long form
# Check if registry path exists, create if necessary
# Ensure the registry path exists
if (-not (Test-Path $registryPath)) {
try {
New-Item -Path $registryPath -Force | Out-Null
@@ -124,12 +134,37 @@ foreach ($entry in $entries) {
}
}
# Set the registry property
try {
Set-ItemProperty -Path $registryPath -Name $propertyName -Type $propertyType -Value $propertyValue
# Write-Host "Successfully set $propertyName in $registryPath to $propertyValue."
} catch {
Write-Warning "Failed to set $propertyName in $registryPath. $_"
foreach ($item in $block.values) {
if ($block.values -is [System.Collections.IList]) {
# Long form: list of {name, type, value}
$propName = $item.name
$propType = $item.type
$propValue = $item.value
} else {
# Short form: dictionary - foreach over a dict gives KeyValuePair
break
}
try {
Set-ItemProperty -Path $registryPath -Name $propName -Type $propType -Value $propValue
} catch {
Write-Warning "Failed to set $propName in $registryPath. $_"
}
}
# Handle short form: values is a dictionary/hashtable
if ($block.values -isnot [System.Collections.IList]) {
foreach ($key in $block.values.Keys) {
$propName = $key
$propType = $defaultType
$propValue = $block.values[$key]
try {
Set-ItemProperty -Path $registryPath -Name $propName -Type $propType -Value $propValue
} catch {
Write-Warning "Failed to set $propName in $registryPath. $_"
}
}
}
}