Patching Vivaldi with batch scripts
-
Thanks, my post crossed with yours.
-
You have redeemed yourself "in time". The other character will remain on the blacklist for quite some time.
-
-
@barbudo2005 You don't have to change
browser.html
butwindow.html
-
@oudstand Thank you.
I understand that to get the best speed in Vivaldi, this is the correct setting:
-
@barbudo2005 No the other way around - Enable portals by turning that option OFF.
-
@Pathduck Thank you.
-
Since the batch script in the OP is broken now that
window.html
is the one to be modified and notbrowser.html
anymore. And I wasn't able to get any of the newer batch scripts posted here to work on Windows, I modified the script posted by @Christoph142.I just changed all instances of
browser.html
andbrowser.bak.html
towindow.html
andwindow.bak.html
respectively. Which looks to have worked perfectly. Thanks to @debiedowner for the script and @Christoph142 for posting it.Here's the modified script:
:: Author: debiedowner @echo off REM make current directory work when run as administrator cd "%~dp0" set installPath="C:\Users\Steve.Bachand\AppData\Local\Vivaldi\Application\" echo Searching at: %installPath% for /f "tokens=*" %%a in ('dir /a:-d /b /s %installPath%') do ( if "%%~nxa"=="window.html" set latestVersionFolder=%%~dpa ) if "%latestVersionFolder%"=="" ( pause & exit ) else ( echo Found latest version folder: "%latestVersionFolder%" ) if not exist "%latestVersionFolder%\window.bak.html" ( echo Creating a backup of your original window.html file. copy "%latestVersionFolder%\window.html" "%latestVersionFolder%\window.bak.html" ) echo copying js files to custom.js type *.js > "%latestVersionFolder%\custom.js" echo patching window.html file type "%latestVersionFolder%\window.bak.html" | findstr /v "</body>" | findstr /v "</html>" > "%latestVersionFolder%\window.html" echo ^<script src="custom.js"^>^</script^> >> "%latestVersionFolder%\window.html" echo ^</body^> >> "%latestVersionFolder%\window.html" echo ^</html^> >> "%latestVersionFolder%\window.html" pause
-
In the last stable update 6.4.3160.42 or in the previous custom.js stopped working.
My files are:
browser.html:
<!DOCTYPE html> <html> <head> <!-- Keep the styling in sync with ./window.html --> <meta charset="UTF-8" /> <title>Vivaldi</title> <link rel="stylesheet" href="style/common.css" /> <link rel="stylesheet" href="chrome://vivaldi-data/css-mods/css" /> </head> <body> <div id="app" /> <script src="vendor-bundle.js"></script> <script src="background-common-bundle.js"></script> <script src="bundle.js"></script> </body> </html>
window.html
<!-- Vivaldi window document --> <!DOCTYPE html> <html> <head> <!-- Keep the styling in sync with ./browser.html --> <meta charset="UTF-8"> <title>Vivaldi</title> <link rel="stylesheet" href="style/common.css"> <link rel="stylesheet" href="chrome://vivaldi-data/css-mods/css"> </head> <body> <script src="custom.js"></script> </body> </html>
What could be the cause of this problem?
-
@explorerthegeneral this hasn't worked for me. or do i need to put the files in the window file first and then it will work from then on?
-
Windows
Here is a modified Version without the need to edit the Installation Path(If Vivaldi is installed as a user):
:: Author: debiedowner :: Editor: Phobos @echo off REM make current directory work when run as administrator cd "%~dp0" set installPath="%localappdata%\Vivaldi\Application\" echo Searching at: %installPath% for /f "tokens=*" %%a in ('dir /a:-d /b /s %installPath%') do ( if "%%~nxa"=="window.html" set latestVersionFolder=%%~dpa ) if "%latestVersionFolder%"=="" ( echo No window.html found in "%latestVersionFolder%" pause & exit ) else ( echo Found latest version folder: "%latestVersionFolder%" ) if not exist "%latestVersionFolder%\window.bak.html" ( echo Creating a backup of your original window.html file. copy "%latestVersionFolder%\window.html" "%latestVersionFolder%\window.bak.html" ) echo copying js files to custom.js type *.js > "%latestVersionFolder%\custom.js" echo patching window.html file type "%latestVersionFolder%\window.bak.html" | findstr /v "</body>" | findstr /v "</html>" > "%latestVersionFolder%\window.html" echo ^<script src="custom.js"^>^</script^> >> "%latestVersionFolder%\window.html" echo ^</body^> >> "%latestVersionFolder%\window.html" echo ^</html^> >> "%latestVersionFolder%\window.html" pause
-
This doesn't seem to work on Mac. It places the custom script file in the folder, but it doesn't edit the browser.html file.
This is what my custom script looks like:
#!/bin/bash # Original version by Isildur, adapted by luetage # Quit Vivaldi osascript -e 'quit app "Vivaldi.app"' # Find path to Framework folder of current version and save it as variable findPath="`find /Applications/Vivaldi.app -name Vivaldi\ Framework.framework`" # Copy custom js file to Vivaldi.app cp "/Applications/Vivaldi Mods/global-media-controls.js" "$findPath"/Resources/vivaldi/ # Save path to window.html as variable browserHtml="$findPath"/Resources/vivaldi/window.html # Insert references, if not present, and save to temporary file sed 's| </body>| <script src="global-media-controls.js"></script></body>|' "$browserHtml" > "$browserHtml".temp # Backup original file cp "$browserHtml" "$browserHtml".bak # Overwrite mv "$browserHtml".temp "$browserHtml" # Pause script read -rsp $'Press [Enter] to restart Vivaldi...\n' # Open Vivaldi open /Applications/Vivaldi.app
-
@NylaTheWolf Nowadays the
window.html
file is being edited. Things have changed. Editingbrowser.html
doesn’t do anything. That’s not to say you don’t have an issue, but I can’t tell because I’m no longer on macOS. Troubleshoot it.And I don’t know who edited the first post, but they obviously edited the script as well and made it confusing. The variable is still called browserHtml, which makes zero sense.
-
@luetage Yeah but it seems that browserHtml is just a variable for the window.html path, if I'm reading it correctly. Shouldn't it still edit window.html.
-
@NylaTheWolf Variable names notwithstanding, the problem with your patching script is this line:
# Insert references, if not present, and save to temporary file sed 's| </body>| <script src="global-media-controls.js"></script></body>|' "$browserHtml" > "$browserHtml".temp
You should instead have the following:
# Insert references, if not present, and save to temporary file sed 's|</body>| <script src="global-media-controls.js"></script></body>|' "$browserHtml" > "$browserHtml".temp
Notice the lack of space indents between the
|
and</body>
.The problem was that
sed
would fail because it couldn't match on that specified text, since the</body>
tag is no longer indented like before.
Anyways, I will shortly share a modified version of the script by me, the one in the first post is woefully outdated. Stay tuned!
-
@AltCode It worked! Thank you so much!!!
-
macOS
Here is the modified script of @luetage's adaption of @Isildur's original script I am currently using:
#!/bin/sh -eu # Original version by Isildur, adapted by luetage, further modified by AltCode # Save path to custom.js files as a variable jsPath="/PATH/TO/DIR" # Path to dir where your custom.js files are located (e.g. "$HOME/Documents/Vivaldi/mods") # Save name of Vivaldi application as a variable installName="Vivaldi" # installName="Vivaldi Snapshot" # Uncomment this line to apply patch to the snapshot version instead # Save full path to Vivaldi application as a variable installPath="/Applications/$installName.app" # Find path to Framework folder of current version and save it as a variable resourcesPath="$(find "$installPath" -name "Vivaldi Framework.framework")/Resources/vivaldi" # Save full path to window.html as a variable windowHtml="$resourcesPath/window.html" # Ask to reapply patch if already done before if [ -d "$resourcesPath/load" ]; then echo "$installName.app has already been patched before" read -p "Reapply patch anyways? (Y/N): " confirm if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then rm -fr "$resourcesPath/load" cp "$windowHtml.bak" "$windowHtml" else exit fi fi # Close Vivaldi if open if pgrep -qx "$installName"; then echo "Waiting for $installName.app to close..." osascript -e "quit app \"$installName.app\"" # Make sure Vivaldi is fully closed before continuing while pgrep -qx "$installName"; do sleep 1 done else installOpen=0 fi # Backup original window.html file if it has never been backed up before if [ ! -e "$windowHtml.bak" ]; then echo "Creating a backup of window.html..." cp "$windowHtml" "$windowHtml.bak" # sleep 3 fi # Create folder within $resourcesPath to save custom.js files mkdir -p "$resourcesPath/load" # Iterate over custom.js files for customJs in $jsPath/*.js; do # Save custom.js filename and the html patch line as variables jsFilename=$(basename "$customJs") jsLine="<script src=\"load/$jsFilename\"></script>" # Copy custom.js files into Vivaldi and patch window.html echo "Patching $jsFilename..." cp "$customJs" "$resourcesPath/load" sed -i "" -e "s|</body>| $jsLine\n</body>|" "$windowHtml" # sleep 3 done echo "Finished patching window.html" # Reopen Vivaldi if closed if [ "${installOpen:-1}" = 1 ]; then # sleep 2 echo "Reopening $installName.app..." open "$installPath" fi
The
browserHtml
variable is no more! That should hopefully clear the confusions currently seen in the script from the first post.I also added some safeguards so that the script waits on its own for Vivaldi to close before patching it (rather than you waiting for Vivaldi to close before manually finishing the script with the enter key), and so that when you rerun the script (either because you forgot you used it before or you used it again by accident), it will tell you that you don't have to use the script again. But if you do, it won't endlessly add duplicate
<script src="custom.js"></script>
lines into thewindow.html
file every time the script is rerun.The only things that need to be altered in this version is the variable at the very beginning of the script,
jsPath
. The variableinstallName
can also be altered so that the script patches the snapshot version instead of the stable version.
Update: After some pondering, I decided to update the script so that it can patch multiple JS files as opposed to just one. This also means that the script now only requires you to specify the folder where you're saving your JS files.