Skip to content

Instantly share code, notes, and snippets.

@Firsh
Last active March 3, 2023 21:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Firsh/88755fde895baa231af75e88affc19ea to your computer and use it in GitHub Desktop.
Save Firsh/88755fde895baa231af75e88affc19ea to your computer and use it in GitHub Desktop.
Install Vivaldi Custom CSS
@set installhooks_args=%*& set installhooks_self=%~f0& powershell -c "(gc \"%~f0\") -replace '@set installhooks_args.*','#' | Write-Host" | powershell -c -& goto :eof
$srcdir = split-path $env:installhooks_self
$vivpath = "c:\Program Files\Vivaldi\Application\"
Try {
$dstdir = split-path ((Get-ChildItem -path $vivpath -recurse browser.html | Sort-Object -property CreationTime -descending | Select-Object -first 1).FullName)
write-host "Destination directory: $dstdir"
$encoding = (New-Object System.Text.UTF8Encoding($False))
write-host "Checking browser.html"
$html = Get-Content (join-path $dstdir "browser.html") -encoding UTF8
$outhtml = @()
$writeneeded = 0
$break = 0
$html | Where-Object { $break -Eq 0 } | ForEach-Object {
$line = $_
if ($line.tolower().contains('<link rel="stylesheet" href="style/custom.css" />')) {
$break = 1;
} elseif ($line.tolower().contains('</head>')) {
$writeneeded = 1
$outhtml += ' <link rel="stylesheet" href="style/custom.css" />'
}
$outhtml += $_
}
if($writeneeded -eq 1){
write-host "Writing to browser.html"
[System.IO.File]::WriteAllLines( (join-path $dstdir "browser.html"), $outhtml, $encoding)
} else {
write-host "The browser.html already includes reference to custom.css"
}
write-host "Copying files"
copy-item (join-path -path $srcdir -childpath "custom.css") (join-path -path $dstdir -childpath "style") -force
write-host "Done"
}
Catch {
write-host "Error: " $_
}
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment