Patching Vivaldi with batch scripts
-
@Kinium running it as administrator sadly didn't change it. Once I saw the
temp.txt
but it wasn't moved to the resources folder. -
@Kinium The content of
browser.html
changes more regularly than one would expect. It should be patched directly, instead of copying an old version of the file to the application. -
Windows
@oudstand That sucks. Try this version. I removed a part I added to create a second .bat file to handle the move. Hope it works.
::::::::::::::::::::::::::::::::::::::::::: :: Script to copy over your Vivaldi mods :: :: by Christoph142 :: ::::::::::::::::::::::::::::::::::::::::::: @echo off setlocal enabledelayedexpansion :: This is a list of your Vivaldi installations' Application folders (you can use the Vivaldi folder, too, but it takes longer to find the file): set installPaths="C:\Users\infec\AppData\Local\Vivaldi\Application\" :: Don't alter anything below this point ;) set nrOfInstalls=0 set "SuccessfulPatched=Couldn't Patch :^(" for %%i in (%installPaths%) do ( <NUL set /p=Searching for newest browser.html in %%~dpi... set /a nrOfInstalls=nrOfInstalls+1 set installPath=%%~dpi set latestVersionFolder= for /f "tokens=*" %%a in ('dir /a:-d /b /s "!installPath!"') do ( if "%%~nxa"=="browser.html" set latestVersionFolder=%%~dpa ) if not defined latestVersionFolder ( set cnt=any echo. echo Couldn't find it. :( echo Is !installPath! the correct Vivaldi Application folder? echo. ) else ( echo Found it. echo. if exist !latestVersionFolder!\browser.bak.html ( echo Backup is already in place. ) else ( echo Creating a backup of your original browser.html file. copy /y "!latestVersionFolder!\browser.html" "!latestVersionFolder!\browser.bak.html" ) echo. findstr /v Compiled_User_JS.js "!latestVersionFolder!\browser.html" > temp0.txt setlocal disabledelayedexpansion ( FOR /F "tokens=*" %%A IN (temp0.txt) DO ( ECHO %%A IF "%%A" EQU "<script src="bundle.js"></script>" ( echo ^<script src="Compiled_User_JS.js"^>^</script^> ) ) ) >temp.txt setlocal enabledelayedexpansion type *.js > !latestVersionFolder!\Compiled_User_JS.js move /y temp.txt !latestVersionFolder!browser.html del temp0.txt echo. echo Copied files^^! set cnt=0 for %%A in (*.js) do set /a cnt+=1 set "SuccessfulPatched=Succesfully Patched" ) ) echo. echo. echo All done^^! :) !SuccessfulPatched! !cnt! .js files^^! echo. echo. pause
@luetage Yeah, that's why I made mine the way it is, so if it maintains that same structure it would still work, and if not, it's easily updated. But yeah, using that standard, this script doesn't work. If you think it's best, I could make a new topic with mine and see if it works for people.
-
Windows
@Kinium said in Windows batch file for patching your mods into Vivaldi:
@oudstand That sucks. Try this version. I removed a part I added to create a second .bat file to handle the move. Hope it works.
It did more but it is still not working a 100%. Now I have a
Compiled_User_JS.js
in the correct location and I still get thebrowser.bak.html
, but thebrowser.html
still looks the same. I've got atemp.txt
in my mods folder which contains the content I would expect in thebrowser.html
.This is what I get in the console:
Searching for newest browser.html in D:\Vivaldi Snapshot\Application\... Found it. Creating a backup of your original browser.html file. 1 Datei(en) kopiert. (English: 1 file copied) open-panels-on-mouse-over.js Syntaxfehler. (English: syntax error) Copied files! All done! :) Succesfully Patched 1 .js files!
-
See if replacing the move command near the end with the xcopy command. That might work.
-
@Kinium said in Windows batch file for patching your mods into Vivaldi:
See if replacing the move command near the end with the xcopy command. That might work.
This leads to the output in the console:
Invalid number of parameters
-
Yeah, now I have no idea. I would suggest you just copy the the temp.txt and paste it on the installation folder and rename it as browser.html
-
@Kinium I've found the problem. My path contained spaces so this is what made it work:
move /Y temp.txt "!latestVersionFolder!browser.html"
-
Oh, nice. Glad you fixed it. Just in time for an update
-
Windows
https://forum.vivaldi.net/topic/10592/windows-batch-file-for-patching-your-mods-into-vivaldi/
I like to keep things brief so it is easy to see what is doing what in one sight, so here's what I use:
@echo off REM make current directory work when run as administrator cd "%~dp0" set installPath="C:\Program Files\Vivaldi\Application\" echo Searching at: %installPath% for /f "tokens=*" %%a in ('dir /a:-d /b /s %installPath%') do ( if "%%~nxa"=="browser.html" set latestVersionFolder=%%~dpa ) if "%latestVersionFolder%"=="" ( pause & exit ) else ( echo Found latest version folder: "%latestVersionFolder%" ) if not exist "%latestVersionFolder%\browser.bak.html" ( echo Creating a backup of your original browser.html file. copy "%latestVersionFolder%\browser.html" "%latestVersionFolder%\browser.bak.html" ) echo copying js files to custom.js type *.js > "%latestVersionFolder%\custom.js" echo patching browser.html file type "%latestVersionFolder%\browser.bak.html" | findstr /v "</body>" | findstr /v "</html>" > "%latestVersionFolder%\browser.html" echo ^<script src="custom.js"^>^</script^> >> "%latestVersionFolder%\browser.html" echo ^</body^> >> "%latestVersionFolder%\browser.html" echo ^</html^> >> "%latestVersionFolder%\browser.html" pause
Naturally, it must be run as administrator if the installation directory is Program Files, as in here. It patches only one installation, so if you use multiple and want to patch them all, each installation will require its own batch file (or you could copy paste inside the same file, to patch different installations in one go).
Unlike the first post, it doesn't require a patched
browser.html
along with the .js files to copy; instead, it patchesbrowser.html
every time, by removing the lines</body>
and</html>
, adding<script src="custom.js"></script>
and then readding</body>
and</html>
. So if Vivaldi changesbrowser.html
in new versions, those changes are kept.All .js files in the same folder as the patch file are combined into that
custom.js
file. If you want to keep the patch batch file somewhere else, just create a shortcut at where you want it to be; I had to create a shortcut anyway, in order to make it run as administrator whenever clicked. But if you really don't want to keep the batch file in the same folder as your mods, you could also specify it separately:@echo off set modPath=C:\Users\debiedowner\Documents\Vivaldi\JS\ set installPath=C:\Program Files\Vivaldi\Application\ echo Searching at: %installPath% for /f "tokens=*" %%a in ('dir /a:-d /b /s "%installPath%"') do ( if "%%~nxa"=="browser.html" set latestVersionFolder=%%~dpa ) if "%latestVersionFolder%"=="" ( pause & exit ) else ( echo Found latest version folder: "%latestVersionFolder%" ) if not exist "%latestVersionFolder%\browser.bak.html" ( echo Creating a backup of your original browser.html file. copy "%latestVersionFolder%\browser.html" "%latestVersionFolder%\browser.bak.html" ) echo copying js files to custom.js type "%modPath%*.js" > "%latestVersionFolder%\custom.js" echo patching browser.html file type "%latestVersionFolder%\browser.bak.html" | findstr /v "</body>" | findstr /v "</html>" > "%latestVersionFolder%\browser.html" echo ^<script src="custom.js"^>^</script^> >> "%latestVersionFolder%\browser.html" echo ^</body^> >> "%latestVersionFolder%\browser.html" echo ^</html^> >> "%latestVersionFolder%\browser.html" pause
But then you would need to modify the script if you ever rename/move your mod folder; the first script above doesn't have that problem.
-
Since we merged the topics for Windows and macOS, I added mentions of the OS version to posts including code.
If you have any questions regarding this, I'm sure @luetage can help.
-
Linux
My batch script has been deleted, so I want to share it here again. Itโs minimal with no failโsafes, so make sure not to run it twice on the same version. It copies over the Javascript file and shows how to do the same for custom page actions, creates the required edit in
browser.html
and gives you write permissions. The second script backs up your custom file, in case you make edits you want to keep.upviv
#!/bin/bash snapshot=/opt/vivaldi-snapshot/resources/vivaldi moddir=$HOME/path/to/dir sudo cp $moddir/custom.js $snapshot sudo cp $moddir/Page_Action.js $snapshot/user_files sudo sed -i -e 's/<\/body>/ <script src="uimod.js"><\/script>\n <\/body>/' "$snapshot/browser.html" sudo chgrp username $snapshot/custom.js sudo chmod g+rw $snapshot/custom.js echo "vivaldi patched"
bakviv
#!/bin/bash cp /opt/vivaldi-snapshot/resources/vivaldi/custom.js $HOME/path/to/dir echo "backup completed"
As mentioned by @jane-n, this topic is for all platforms now. Please include the operating system when sharing a batch script. E.g. in form of a header:
# Windows
. -
Linux
Iโve been looking for a solution to save all CSS and JS files together in one directory and load only the JS files into the application (CSS files already loaded by Vivaldi). This copies all JS files into a dedicated directory and then links them to
browser.html
.#!/bin/bash snapshot=/opt/vivaldi-snapshot/resources/vivaldi moddir=$HOME/path/to/directory sudo mkdir -p $snapshot/load sudo chgrp USERNAME $snapshot/load sudo chmod g+rw $snapshot/load for FILE in $moddir/*.js do cp $FILE $snapshot/load sudo sed -i -e "s,</body>, <script src=\"load/$(basename $FILE)\"></script>\n </body>," "$snapshot/browser.html" done echo "vivaldi patched"
-
masOS Ventura
I'm trying to use the batch script for macOS by @luetage (see here).
It works fine for Stable.
That's what I'm using:#!/bin/bash # 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 /PATH TO FILE/custom.js "$findPath"/Resources/vivaldi/ # Save path to browser.html as variable browserHtml="$findPath"/Resources/vivaldi/browser.html # Insert references, if not present, and save to temporary file sed 's| </body>| <script src="custom.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
I'm unable to make it work for Snapshot.
I tried this:#!/bin/bash # Quit Vivaldi osascript -e 'quit app "Vivaldi Snapshot.app"' # Find path to Framework folder of current version and save it as variable findPath="`find /Applications/Vivaldi\ Snapshot.app -name Vivaldi\ Framework.framework`" # Copy custom js file to Vivaldi.app cp /PATH TO FILE/custom.js "$findPath"/Resources/vivaldi/ # Save path to browser.html as variable browserHtml="$findPath"/Resources/vivaldi/browser.html # Insert references, if not present, and save to temporary file sed 's| </body>| <script src="custom.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\ Snapshot.app
and that:
#!/bin/bash # Quit Vivaldi osascript -e 'quit app "Vivaldi Snapshot.app"' # Find path to Framework folder of current version and save it as variable findPath="`find /Applications/Vivaldi\ Snapshot.app -name Vivaldi\ Framework.framework`" # Copy custom js file to Vivaldi.app cp /PATH TO FILE/custom.js "$findPath"/Resources/vivaldi/ # Save path to browser.html as variable browserHtml="$findPath"/Resources/vivaldi/browser.html # Insert references, if not present, and save to temporary file sed 's| </body>| <script src="custom.js"></script></body>|' "$browserHtml" # Pause script read -rsp $'Press [Enter] to restart Vivaldi...\n' # Open Vivaldi open /Applications/Vivaldi\ Snapshot.app
In both cases,
browser.html
is not patched,<script src="custom.js"></script>
is not inserted (though thecustom.js
file is copied to Vivaldi Snapshot.app &browser.html.bak
is created in the first case).So, what am I doing wrong?
๏ฃฟ MacBook Air M1 2020 | macOS 13.3.1 Ventura | 5.7.2921.65 & 5.8.2978.3
Edit It was an issue with my
browser.html
file on snapshot, not with the script. -
@hlehyaric Not on MacOS here of course, so no idea how the file structure works there, but the general troubleshooting tip for shell scripts is to add some
echo
's and see if something pops upAfter variables are set do:
echo $findPath
echo $browserHtml
Maybe do
sed --debug
Could check the return code (
$?
) for thecp
as well, but you say it works so prolly not necessary -
@Pathduck Thanks for your reply.
I'm just an average user, I didn't write the script , I barely know how to use a terminal.
When & where should I use those
echo
s?Anyway, it's very kind of you to take your time to reply to me.
-
@hlehyaric And here I thought all you Mac users were Bash experts!
After all, you have this most excellent terminal available and don't even have to fiddle with LinuxReplace this bit:
# Find path to Framework folder of current version and save it as variable findPath="`find /Applications/Vivaldi\ Snapshot.app -name Vivaldi\ Framework.framework`" echo "findPath=$findPath"
And
# Save path to browser.html as variable browserHtml="$findPath"/Resources/vivaldi/browser.html echo "browserHtml=$browserHtml"
My guess is one of those vars will be blank/unset and the script will fail.
-
@Pathduck Bash is not a terminal and the default shell is zsh nowadays. And macOS always tried to keep its users away from the console. Troubleshooting is needed, because the script used to work, but suddenly doesnโt. Something has changed, but Iโm not on macOS anymore, therefore we have to wait on someone who is willing to check it out.
-
And here I thought all you Mac users were Bash experts!
Are you kidding? Many users don't even know what ยซTerminalยป is & Apple tries its best to let them ignore it.
@luetage @Pathduck I miserably failed. It was an issue with
browser.html
on my Snapshot . I'm a dumb. The script runs smoothly.
Thanks to both for your patience & your kind help.
I sincerely apologize for wasting your time. -
@hlehyaric I guess they are set, but also containing spaces which generally tends to make mess of shell scripts, depending on how it's handled by the shell.
Oh and I saw your edit, that's cool