Patching Vivaldi with batch scripts
-
@rseiler Where does this piece goes in the code?
-
@novaviper I don't use the batch at the top of the page because it wasn't there in complete form when I first found this thread, so I was forced to roll my own. If you wanted to plug it into the existing batch, it could go right before the end.
Note that the way I have it, the batch actually cd's into the Vivaldi application directory first thing (that part's not shown above). You could instead specify the path in the MOVE command, and also specify the path for browser.html in the FOR, but it was cleaner just to cd.
-
@rseiler Hm.. I'm trying to figure out how to incorporate it into the batch script above within that FOR loop they made; but it's a bit hard since the bottom part of the code is actually doing the moving (and because I don't really know batch, I'm more used to Powershell :/).
I actually might go and create a Powershell script, I'll post more info once I got it ready (or at least what I have so far)
-
Windows
@novaviper In case it helps to triangulate, this is mine:
@ECHO OFF REM Updates browser.html and copies custom.css REM Must be run with admin privileges if Vivaldi is in Program Files. REM Find the Vivaldi folder with the highest version number. FOR /F "tokens=*" %%I in ('dir /b /ad /on "%programfiles%\Vivaldi\Application" ^| findstr /R "^[0-9]"') DO ( SET highdir=%%I ) c: CD "%programfiles%\Vivaldi\Application\%highdir%\resources\vivaldi" REM Add the custom.css and custom.js lines to browser.html and then copy files. REM Original lines that are searched for: REM <link rel="stylesheet" href="style/common.css" /> REM <script src="bundle.js"></script> ( FOR /F "tokens=*" %%A IN (browser.html) DO ( ECHO %%A IF "%%A" EQU "<link rel="stylesheet" href="style/common.css" />" ( ECHO ^<link rel="stylesheet" href="style/custom.css" /^> ) IF "%%A" EQU "<script src="bundle.js"></script>" ( ECHO ^<script src="custom.js"^>^</script^> ) ) ) > temp.html MOVE /y temp.html browser.html COPY /y f:\stuff\custom.css "%programfiles%\Vivaldi\Application\%highdir%\resources\vivaldi\style" COPY /y f:\stuff\custom.js "%programfiles%\Vivaldi\Application\%highdir%\resources\vivaldi" pause
-
@rseiler Thanks a bunch! That did clarify some components I need for my Powershell Script.. however, I'm not sure an alternative way to retrieve the browser's version folder (the line where the script locates the Vivaldi folder with the highest version number) on Powershell
-
Can the mod files be located somewhere in the Vivaldi folder chain, as long as they're above the version folder? Or does it all get replaced?
Edit: It only seems to replace the version # folder and below.
-
@jack9 While not sure, I suspect that misc files in the root of the "Application" folder will survive, because I see that, in addition to three Vivaldi files there that are replaced, I also have an old debug.log there. So I doubt whatever else you put in there will be replaced.
-
Hey,
As far as I understand, this batch file is for Windows only.
So, I wondered, shouldn't this thread be pinned instead of this one ? Mod's manager is a far more advanced tool -
@rseiler If your lines are just added on to the existing batch file, won't the rest of the batch file have already replaced the new browser.html (from the newly installed Vivaldi version) with the old backed up one one, before your lines can get to the new one to edit it? It seems the bat file would need to be modified with your lines merged in instead of just tacked on.
-
@Christoph142 I tried using the batch file (without rseiler's code), and it said it was successful, and it renamed my browser.html in my mod files folder to browser.bak.html, but didn't actually copy it or my custom.js file into the application folder. Paths in my bat file are:
set "modFolder=C:\Users\Jack\AppData\Local\Vivaldi\Application\my mod files"
set installPaths="C:\Users\Jack\AppData\Local\Vivaldi\Application"My browser.html and custom.js files are in "my mod files".
Also, what's the point of renaming the modded browser.html file into browser.bak.html? Or is that not how it's supposed to work?
Maybe instead it's supposed to move the modded browser.html into the application folder, and move the new browser.html from the install from the application folder into the mods folder (and rename it)? If so, that's not ideal since the modded browser.html file is then missing for next time. So neither of these methods make sense to me.
It should instead keep the modded file in the mod folder, copy instead of move it to the application folder, and take the new one and rename it with 'bak', 'new', etc and it could just be left it in the application folder. -
@Jack9 Just for clarification, what I posted is meant to work on its own, not in conjunction with the original. It still works.
-
@rseiler I was just going by your earlier post:
https://forum.vivaldi.net/post/183262
"If you wanted to plug it into the existing batch, it could go right before the end." -
That was a long time ago. Not sure what that was about, or even what the existing batch was back then, but it was in reference to the snippet, not the entire file that I posted later. In any case, there's no point in combining.
-
@Jack9 said in Windows batch file for patching your mods into Vivaldi:
@Christoph142 I tried using the batch file (without rseiler's code), and it said it was successful, and it renamed my browser.html in my mod files folder to browser.bak.html, but didn't actually copy it or my custom.js file into the application folder. Paths in my bat file are:
set "modFolder=C:\Users\Jack\AppData\Local\Vivaldi\Application\my mod files"
set installPaths="C:\Users\Jack\AppData\Local\Vivaldi\Application"My browser.html and custom.js files are in "my mod files".
Also, what's the point of renaming the modded browser.html file into browser.bak.html? Or is that not how it's supposed to work?
Maybe instead it's supposed to move the modded browser.html into the application folder, and move the new browser.html from the install from the application folder into the mods folder (and rename it)? If so, that's not ideal since the modded browser.html file is then missing for next time. So neither of these methods make sense to me.
It should instead keep the modded file in the mod folder, copy instead of move it to the application folder, and take the new one and rename it with 'bak', 'new', etc and it could just be left it in the application folder.Well does anyone else know?
-
@Jack9 I did mention that the original script and the one I posted are two separate things. Don't try to combine. Use one or the other, depending on what you want to do.
-
macOS
I wanted to share my current setup. Don't know how many Vivaldi modders are out there using macOS, but I hope it will help at least some of you automate the most repetitive tasks. Following a complete rundown of the steps required:
Get your files ready. Personally I'm using 3 individual ones.
upviv.sh
to patch the application whenever an update has finished installing.modviv.sh
to startup Vivaldi when you want to inspect its UI.bakviv.sh
to backup the files you are currently working on outside the browser
The files use the extension
.sh
so they get opened by your default text editor automatically. I keep them on Dropbox just likecustom.css
andcustom.js
for backup. To run these scripts we will have to make them executable and change the file extension.- In Terminal open the directory you have saved the bash scripts to and issue following commands:
chmod +x upviv.sh
chmod +x modviv.sh
chmod +x bakviv.sh
- Now copy them and change the extension to
.command
instead of.sh
. By default this will run them in your Terminal.
We could leave it like that and just double click the files to execute, but a more elegant solution is to run them directly from the terminal as commands…
- After making each file executable copy all of them to this directory
/usr/local/bin/
- Delete the filename extension
.sh
- Optionally tag each file so you can find it more easily.
Now each command can be run from terminal by just typing its name.
Below are the example files. Exchange
PATH_TO_FILE
for your own path. To get a full path you can drag and drop a file into terminal. Adapt these examples to your needs, make your own.upviv.sh
#!/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 files to Vivaldi.app cp /PATH_TO_FILE/custom.css "$findPath"/Resources/vivaldi/style/ 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| </head>| <link rel="stylesheet" href="style/custom.css" /></head>|;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 custom files in text editor open "$findPath"/Resources/vivaldi/style/custom.css open "$findPath"/Resources/vivaldi/custom.js # Open Vivaldi open /Applications/Vivaldi.app --args --debug-packed-apps --silent-debugger-extension-api
modviv.sh
#!/bin/bash osascript -e 'quit app "Vivaldi.app"' read -rsp $'Press [Enter] to restart Vivaldi...\n' open /Applications/Vivaldi.app --args --debug-packed-apps --silent-debugger-extension-api
bakviv.sh
#!/bin/bash findPath="`find /Applications/Vivaldi.app -name Vivaldi\ Framework.framework`" cp "$findPath"/Resources/vivaldi/style/custom.css /PATH_TO_FILE/custom.css cp "$findPath"/Resources/vivaldi/custom.js /PATH_TO_FILE/custom.js echo Backup completed.
-
Windows
@Christoph142 Thanks for your script! I've got the problem, that the browser.html file is found and also a backup is created, but there is no browser.html file after executing the script but only browser.bak.html. Do you have an idea why this happens?
As you can see it says invalid path. But the backup is still created, what surprises me ^^
This are the changed lines:
:: This is the folder that contains your modded files (make sure it uses similar folder structure): set "modFolder=D:\Vivaldi Snapshot\Mods - JS\" :: 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="D:\Vivaldi Snapshot\Application\"
-
macOS
I'd like to share mine too... actually, is a "fork" from @luetage 's approach, but using hard links, which doesn't require a backup step, since the original file will remain intact in case of deleting.
viv-inspec.sh
(Used for open Vivaldi in "develop mode")#!/bin/bash osascript -e 'quit app "Vivaldi.app"' read -rsp $'Press [Enter] to restart Vivaldi...\n' open /Applications/Vivaldi.app --args --debug-packed-apps --silent-debugger-extension-api
viv-patch.sh
(Used for patching the custom files on the current version of Vivaldi)#!/bin/bash # Quit Vivaldi osascript -e 'quit app "Vivaldi.app"' # Find current path here=$(pwd) # Find path to Framework folder of current version and save it as variable findPath="`find /Applications/Vivaldi.app -name Vivaldi\ Framework.framework`" # Copy custom files to Vivaldi.app ln "$here"/files/custom.css "$findPath"/Resources/vivaldi/style/ ln "$here"/files/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| </head>| <link rel="stylesheet" href="style/custom.css" /></head>|;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
modEdit: added OS info
-
Is there a functioning script that copies the modfiles to Vivaldi currently? Can’t test because I’m not on Windows.
-
Windows
@luetage I just made one for myself, using a couple of the stuff from here. I'm sure someone can make a cleaner code, but it's what I managed to make for myself.
Just drop this in a folder with your active .js mods and name it name.bat, whichever name you want. Just switch the installPaths to where vivaldi is installed on your PC.
It'll put all your mods into a single file, copy it over to the installation directory and patch the browser.html file to include the compiled file.
Any problems, I probably won't be able to solve, but I'll give it my best.
::::::::::::::::::::::::::::::::::::::::::: :: 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 set "command=type *.js ^> !latestVersionFolder!\Compiled_User_JS.js" echo !command! > temp.bat echo move /y temp.txt !latestVersionFolder!browser.html >> temp.bat echo del temp0.txt >> temp.bat echo exit >> temp.bat start temp.bat 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 del temp.bat