Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.