Last active
March 3, 2023 21:22
-
-
Save Firsh/88755fde895baa231af75e88affc19ea to your computer and use it in GitHub Desktop.
Install Vivaldi Custom CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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