mirror of
				https://github.com/arkenfox/user.js.git
				synced 2025-11-03 23:35:26 +01:00 
			
		
		
		
	Updater 4.3
Changes: -The script doesn't touch the user.js file until it really has to. -The merge function is a bit smarter parsing files, at no significant cost. See examples below. -Minor syntactic changes here and there. Additions: -New -multiBackups argument. I personally intend to use it to compare files and quickly review changes.
This commit is contained in:
		
							
								
								
									
										101
									
								
								updater.bat
									
									
									
									
									
								
							
							
						
						
									
										101
									
								
								updater.bat
									
									
									
									
									
								
							@@ -3,7 +3,7 @@ TITLE ghacks user.js updater
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
REM ## ghacks-user.js updater for Windows
 | 
					REM ## ghacks-user.js updater for Windows
 | 
				
			||||||
REM ## author: @claustromaniac
 | 
					REM ## author: @claustromaniac
 | 
				
			||||||
REM ## version: 4.2
 | 
					REM ## version: 4.3
 | 
				
			||||||
REM ## instructions: https://github.com/ghacksuserjs/ghacks-user.js/wiki/3.3-Updater-Scripts
 | 
					REM ## instructions: https://github.com/ghacksuserjs/ghacks-user.js/wiki/3.3-Updater-Scripts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SET _myname=%~n0
 | 
					SET _myname=%~n0
 | 
				
			||||||
@@ -16,6 +16,7 @@ IF /I "%~1"=="-logp" (SET _log=1 & SET _logp=1)
 | 
				
			|||||||
IF /I "%~1"=="-multioverrides" (SET _multi=1)
 | 
					IF /I "%~1"=="-multioverrides" (SET _multi=1)
 | 
				
			||||||
IF /I "%~1"=="-merge" (SET _merge=1)
 | 
					IF /I "%~1"=="-merge" (SET _merge=1)
 | 
				
			||||||
IF /I "%~1"=="-updatebatch" (SET _updateb=1)
 | 
					IF /I "%~1"=="-updatebatch" (SET _updateb=1)
 | 
				
			||||||
 | 
					IF /I "%~1"=="-multibackups" (SET _multibackups=1)
 | 
				
			||||||
SHIFT
 | 
					SHIFT
 | 
				
			||||||
GOTO parse
 | 
					GOTO parse
 | 
				
			||||||
:endparse
 | 
					:endparse
 | 
				
			||||||
@@ -76,14 +77,14 @@ ECHO:
 | 
				
			|||||||
ECHO:                ########################################
 | 
					ECHO:                ########################################
 | 
				
			||||||
ECHO:                ####  user.js Updater for Windows   ####
 | 
					ECHO:                ####  user.js Updater for Windows   ####
 | 
				
			||||||
ECHO:                ####       by claustromaniac        ####
 | 
					ECHO:                ####       by claustromaniac        ####
 | 
				
			||||||
ECHO:                ####             v4.2               ####
 | 
					ECHO:                ####             v4.3               ####
 | 
				
			||||||
ECHO:                ########################################
 | 
					ECHO:                ########################################
 | 
				
			||||||
ECHO:
 | 
					ECHO:
 | 
				
			||||||
SET /A "_line=0"
 | 
					SET /A "_line=0"
 | 
				
			||||||
IF NOT EXIST user.js (
 | 
					IF NOT EXIST user.js (
 | 
				
			||||||
	CALL :message "user.js not detected in the current directory."
 | 
						CALL :message "user.js not detected in the current directory."
 | 
				
			||||||
) ELSE (
 | 
					) ELSE (
 | 
				
			||||||
	FOR /F "skip=1 tokens=1,2 delims=:" %%G IN (user.js) DO (
 | 
						FOR /F "skip=1 tokens=1,* delims=:" %%G IN (user.js) DO (
 | 
				
			||||||
		SET /A "_line+=1"
 | 
							SET /A "_line+=1"
 | 
				
			||||||
		IF !_line! GEQ 4 (GOTO exitloop)
 | 
							IF !_line! GEQ 4 (GOTO exitloop)
 | 
				
			||||||
		IF !_line! EQU 1 (SET _name=%%H)
 | 
							IF !_line! EQU 1 (SET _name=%%H)
 | 
				
			||||||
@@ -123,17 +124,12 @@ IF DEFINED _log (
 | 
				
			|||||||
	ECHO:##################################################################
 | 
						ECHO:##################################################################
 | 
				
			||||||
	CALL :message "%date%, %time%"
 | 
						CALL :message "%date%, %time%"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
IF EXIST user.js.old.bak (DEL /F user.js.old.bak)
 | 
					IF EXIST user.js.new (DEL /F "user.js.new")
 | 
				
			||||||
IF EXIST user.js (
 | 
					 | 
				
			||||||
	IF EXIST user.js.bak (REN user.js.bak user.js.old.bak)
 | 
					 | 
				
			||||||
	REN user.js user.js.bak
 | 
					 | 
				
			||||||
	CALL :message "Current user.js file backed up."
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
CALL :message "Retrieving latest user.js file from github repository..."
 | 
					CALL :message "Retrieving latest user.js file from github repository..."
 | 
				
			||||||
(
 | 
					(
 | 
				
			||||||
	powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/ghacksuserjs/ghacks-user.js/raw/master/user.js', 'user.js')"
 | 
						powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/ghacksuserjs/ghacks-user.js/raw/master/user.js', 'user.js.new')"
 | 
				
			||||||
) >nul 2>&1
 | 
					) >nul 2>&1
 | 
				
			||||||
IF EXIST user.js (
 | 
					IF EXIST user.js.new (
 | 
				
			||||||
	IF DEFINED _multi (
 | 
						IF DEFINED _multi (
 | 
				
			||||||
		FORFILES /P user.js-overrides /M *.js >nul 2>&1
 | 
							FORFILES /P user.js-overrides /M *.js >nul 2>&1
 | 
				
			||||||
		IF NOT ERRORLEVEL 1 (
 | 
							IF NOT ERRORLEVEL 1 (
 | 
				
			||||||
@@ -141,45 +137,49 @@ IF EXIST user.js (
 | 
				
			|||||||
				CALL :message "Merging..."
 | 
									CALL :message "Merging..."
 | 
				
			||||||
				COPY /B /V /Y user.js-overrides\*.js user-overrides-merged.js
 | 
									COPY /B /V /Y user.js-overrides\*.js user-overrides-merged.js
 | 
				
			||||||
				CALL :merge user-overrides-merged.js
 | 
									CALL :merge user-overrides-merged.js
 | 
				
			||||||
				COPY /B /V /Y user.js+user-overrides-merged.js user.js
 | 
									COPY /B /V /Y user.js.new+user-overrides-merged.js user.js.new
 | 
				
			||||||
				CALL :merge user.js
 | 
									CALL :merge user.js.new
 | 
				
			||||||
			) ELSE (
 | 
								) ELSE (
 | 
				
			||||||
				CALL :message "Appending..."
 | 
									CALL :message "Appending..."
 | 
				
			||||||
				COPY /B /V /Y user.js+"user.js-overrides\*.js" user.js
 | 
									COPY /B /V /Y user.js.new+"user.js-overrides\*.js" user.js.new
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
		) ELSE (CALL :message "No override files found.")
 | 
							) ELSE (CALL :message "No override files found.")
 | 
				
			||||||
		ECHO:
 | 
							ECHO:
 | 
				
			||||||
	) ELSE (
 | 
						) ELSE (
 | 
				
			||||||
		IF EXIST "user-overrides.js" (
 | 
							IF EXIST "user-overrides.js" (
 | 
				
			||||||
			COPY /B /V /Y user.js+"user-overrides.js" "user.js"
 | 
								COPY /B /V /Y user.js.new+"user-overrides.js" "user.js.new"
 | 
				
			||||||
			IF DEFINED _merge (
 | 
								IF DEFINED _merge (
 | 
				
			||||||
				CALL :message "Merging user-overrides.js..."
 | 
									CALL :message "Merging user-overrides.js..."
 | 
				
			||||||
				CALL :merge user.js
 | 
									CALL :merge user.js.new
 | 
				
			||||||
			) ELSE (
 | 
								) ELSE (
 | 
				
			||||||
				CALL :message "user-overrides.js appended."
 | 
									CALL :message "user-overrides.js appended."
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
		) ELSE (CALL :message "user-overrides.js not found.")
 | 
							) ELSE (CALL :message "user-overrides.js not found.")
 | 
				
			||||||
		ECHO:
 | 
							ECHO:
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	CALL :message "Handling backups..."
 | 
						IF EXIST user.js (
 | 
				
			||||||
	SET "changed="
 | 
							FC user.js.new user.js >nul && SET "_changed=false" || SET "_changed=true"
 | 
				
			||||||
	IF EXIST user.js.bak (
 | 
					 | 
				
			||||||
		FC user.js.bak user.js >nul && SET "changed=false" || SET "changed=true"
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	IF "!changed!"=="true" (
 | 
						IF "!_changed!"=="true" (
 | 
				
			||||||
		IF EXIST user.js.old.bak DEL /F user.js.old.bak
 | 
							CALL :message "Backing up..."
 | 
				
			||||||
 | 
							IF DEFINED _multibackups (
 | 
				
			||||||
 | 
						                MOVE /Y user.js "user-backup-!date:/=-!_!time::=.!.js" >nul
 | 
				
			||||||
 | 
							) ELSE (
 | 
				
			||||||
 | 
								MOVE /Y user.js user.js.bak >nul
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
							REN user.js.new user.js
 | 
				
			||||||
		CALL :message "Update complete."
 | 
							CALL :message "Update complete."
 | 
				
			||||||
	) ELSE (
 | 
						) ELSE (
 | 
				
			||||||
		IF "!changed!"=="false" (
 | 
							IF "!_changed!"=="false" (
 | 
				
			||||||
			DEL /F user.js.bak
 | 
								DEL /F user.js.new >nul
 | 
				
			||||||
			IF EXIST user.js.old.bak REN user.js.old.bak user.js.bak
 | 
					 | 
				
			||||||
			CALL :message "Update completed without changes."
 | 
								CALL :message "Update completed without changes."
 | 
				
			||||||
		) ELSE (CALL :message "Update complete.")
 | 
							) ELSE (
 | 
				
			||||||
 | 
								REN user.js.new user.js
 | 
				
			||||||
 | 
								REN CALL :message "Update complete."
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	ECHO:
 | 
						ECHO:
 | 
				
			||||||
) ELSE (
 | 
					) ELSE (
 | 
				
			||||||
	IF EXIST user.js.bak (REN user.js.bak user.js)
 | 
					 | 
				
			||||||
	IF EXIST user.js.old.bak (REN user.js.old.bak user.js.bak)
 | 
					 | 
				
			||||||
	CALL :message "Update failed. Make sure PowerShell is allowed internet access."
 | 
						CALL :message "Update failed. Make sure PowerShell is allowed internet access."
 | 
				
			||||||
	ECHO:   No changes were made.
 | 
						ECHO:   No changes were made.
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -200,27 +200,31 @@ REM ############ Merge function ############
 | 
				
			|||||||
:merge
 | 
					:merge
 | 
				
			||||||
SETLOCAL DisableDelayedExpansion
 | 
					SETLOCAL DisableDelayedExpansion
 | 
				
			||||||
(
 | 
					(
 | 
				
			||||||
	FOR /F "tokens=1,* delims=," %%G IN ('FINDSTR /B /I /C:"user_pref" "%~1"') DO (SET "%%G=%%H")
 | 
						FOR /F tokens^=2^,^*^ delims^=^'^" %%G IN ('FINDSTR /B /R /C:"user_pref.*\)" "%~1"') DO (
 | 
				
			||||||
 | 
							IF NOT "%%G"=="" (
 | 
				
			||||||
 | 
								IF NOT "%%H"=="" (SET "%%G=%%H")
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
	FOR /F "tokens=1,* delims=:" %%I IN ('FINDSTR /N "^" "%~1"') DO (
 | 
						FOR /F "tokens=1,* delims=:" %%I IN ('FINDSTR /N "^" "%~1"') DO (
 | 
				
			||||||
		IF ""=="%%J" (
 | 
							SET "_temp=%%J"
 | 
				
			||||||
			ECHO:
 | 
							SETLOCAL EnableDelayedExpansion
 | 
				
			||||||
 | 
							IF "!_temp:)=!"=="!_temp!" (
 | 
				
			||||||
 | 
								ENDLOCAL & ECHO:%%J
 | 
				
			||||||
		) ELSE (
 | 
							) ELSE (
 | 
				
			||||||
			FOR /F "delims=," %%K IN ("%%J") DO (
 | 
								IF NOT "!_temp:~0,9!"=="user_pref" (
 | 
				
			||||||
				IF NOT [user_pref("_user.js.parrot"]==[%%K] (
 | 
									ENDLOCAL & ECHO:%%J
 | 
				
			||||||
					IF DEFINED %%K (
 | 
								) ELSE (
 | 
				
			||||||
						SETLOCAL EnableDelayedExpansion
 | 
									ENDLOCAL
 | 
				
			||||||
						FOR /F "delims=" %%L IN ("!%%K!") DO (
 | 
									FOR /F tokens^=2^ delims^=^'^" %%K IN ("%%J") DO (
 | 
				
			||||||
							ENDLOCAL
 | 
										IF NOT "_user.js.parrot"=="%%K" (
 | 
				
			||||||
							IF NOT "%%L"=="ALREADY MERGED" (
 | 
											IF DEFINED %%K (
 | 
				
			||||||
								ECHO:%%K,%%L
 | 
												SETLOCAL EnableDelayedExpansion
 | 
				
			||||||
								SET "%%K=ALREADY MERGED"
 | 
												FOR /F "delims=" %%L IN ("!%%K!") DO (
 | 
				
			||||||
 | 
													ENDLOCAL & ECHO:user_pref("%%K"%%L
 | 
				
			||||||
 | 
													SET "%%K="
 | 
				
			||||||
							)
 | 
												)
 | 
				
			||||||
						)
 | 
											)
 | 
				
			||||||
					) ELSE (
 | 
										) ELSE (ECHO:%%J)
 | 
				
			||||||
						ECHO:%%J
 | 
					 | 
				
			||||||
					)
 | 
					 | 
				
			||||||
				) ELSE (
 | 
					 | 
				
			||||||
					ECHO:%%J
 | 
					 | 
				
			||||||
				)
 | 
									)
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
@@ -231,7 +235,7 @@ ENDLOCAL
 | 
				
			|||||||
GOTO :EOF
 | 
					GOTO :EOF
 | 
				
			||||||
REM ############### Help ##################
 | 
					REM ############### Help ##################
 | 
				
			||||||
:showhelp
 | 
					:showhelp
 | 
				
			||||||
MODE 80,43
 | 
					MODE 80,46
 | 
				
			||||||
CLS
 | 
					CLS
 | 
				
			||||||
CALL :message "Available arguments (case-insensitive):"
 | 
					CALL :message "Available arguments (case-insensitive):"
 | 
				
			||||||
CALL :message "  -log"
 | 
					CALL :message "  -log"
 | 
				
			||||||
@@ -239,7 +243,7 @@ ECHO:     Write the console output to a logfile (user.js-update-log.txt)
 | 
				
			|||||||
CALL :message "  -logP"
 | 
					CALL :message "  -logP"
 | 
				
			||||||
ECHO:     Like -log, but also open the logfile after updating.
 | 
					ECHO:     Like -log, but also open the logfile after updating.
 | 
				
			||||||
CALL :message "  -merge"
 | 
					CALL :message "  -merge"
 | 
				
			||||||
ECHO:     Merge overrides instead of appending them. One-line comments and
 | 
					ECHO:     Merge overrides instead of appending them. Single-line comments and
 | 
				
			||||||
ECHO:     _user.js.parrot lines are appended normally. Overrides for inactive
 | 
					ECHO:     _user.js.parrot lines are appended normally. Overrides for inactive
 | 
				
			||||||
ECHO:     user.js prefs will be appended. When -Merge and -MultiOverrides are used
 | 
					ECHO:     user.js prefs will be appended. When -Merge and -MultiOverrides are used
 | 
				
			||||||
ECHO:     together, a user-overrides-merged.js file is also generated in the root
 | 
					ECHO:     together, a user-overrides-merged.js file is also generated in the root
 | 
				
			||||||
@@ -248,6 +252,9 @@ ECHO:     override files and can be safely discarded after updating, or used as
 | 
				
			|||||||
ECHO:     new user-overrides.js. When there are conflicting records for the same
 | 
					ECHO:     new user-overrides.js. When there are conflicting records for the same
 | 
				
			||||||
ECHO:     pref, the value of the last one declared will be used. Visit the wiki
 | 
					ECHO:     pref, the value of the last one declared will be used. Visit the wiki
 | 
				
			||||||
ECHO:     for usage examples and more detailed information.
 | 
					ECHO:     for usage examples and more detailed information.
 | 
				
			||||||
 | 
					CALL :message "  -multiBackups"
 | 
				
			||||||
 | 
					ECHO:     Don't overwrite previous backups. New backups are still created only
 | 
				
			||||||
 | 
					ECHO:     when the updated user.js is different from the previous one.
 | 
				
			||||||
CALL :message "  -multiOverrides"
 | 
					CALL :message "  -multiOverrides"
 | 
				
			||||||
ECHO:     Use any and all .js files in a user.js-overrides sub-folder as overrides
 | 
					ECHO:     Use any and all .js files in a user.js-overrides sub-folder as overrides
 | 
				
			||||||
ECHO:     instead of the default user-overrides.js file. Files are appended in
 | 
					ECHO:     instead of the default user-overrides.js file. Files are appended in
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user