2017-12-19 11:25:14 -05:00
|
|
|
@ECHO OFF & SETLOCAL EnableDelayedExpansion
|
|
|
|
TITLE ghacks user.js updater
|
|
|
|
|
2017-12-24 11:49:33 -05:00
|
|
|
REM ## ghacks-user.js updater for Windows
|
2017-12-19 11:25:14 -05:00
|
|
|
REM ## author: @claustromaniac
|
2018-04-25 15:28:09 -04:00
|
|
|
REM ## version: 4.5
|
2017-12-24 11:49:33 -05:00
|
|
|
REM ## instructions: https://github.com/ghacksuserjs/ghacks-user.js/wiki/3.3-Updater-Scripts
|
2017-12-19 11:25:14 -05:00
|
|
|
|
|
|
|
SET _myname=%~n0
|
|
|
|
SET _myparams=%*
|
|
|
|
:parse
|
2017-12-24 22:48:39 -05:00
|
|
|
IF "%~1"=="" (GOTO endparse)
|
|
|
|
IF /I "%~1"=="-unattended" (SET _ua=1)
|
|
|
|
IF /I "%~1"=="-log" (SET _log=1)
|
|
|
|
IF /I "%~1"=="-logp" (SET _log=1 & SET _logp=1)
|
|
|
|
IF /I "%~1"=="-multioverrides" (SET _multi=1)
|
|
|
|
IF /I "%~1"=="-merge" (SET _merge=1)
|
|
|
|
IF /I "%~1"=="-updatebatch" (SET _updateb=1)
|
2018-01-17 10:30:02 -05:00
|
|
|
IF /I "%~1"=="-singlebackup" (SET _singlebackup=1)
|
2017-12-19 11:25:14 -05:00
|
|
|
SHIFT
|
|
|
|
GOTO parse
|
|
|
|
:endparse
|
|
|
|
IF DEFINED _updateb (
|
|
|
|
REM The normal flow here goes from phase 1 to phase 2 and then phase 3.
|
|
|
|
IF NOT "!_myname:~0,9!"=="[updated]" (
|
|
|
|
IF EXIST "[updated]!_myname!.bat" (
|
|
|
|
REM ## Phase 3 ##: The new script, with the original name, will:
|
|
|
|
REM * Delete the [updated]*.bat script
|
|
|
|
REM * Begin the normal routine
|
|
|
|
REN "[updated]!_myname!.bat" "[updated]!_myname!.bat.old"
|
|
|
|
DEL /F "[updated]!_myname!.bat.old"
|
|
|
|
CALL :message "Script updated^!"
|
|
|
|
TIMEOUT 3 >nul
|
|
|
|
GOTO begin
|
|
|
|
)
|
|
|
|
REM ## Phase 1 ##
|
|
|
|
REM * Download new batch and name it [updated]*.bat
|
|
|
|
REM * Start that script in a new CMD window
|
|
|
|
REM * Exit
|
|
|
|
CALL :message "Updating script..."
|
|
|
|
REM Uncomment the next line and comment the powershell call for testing.
|
|
|
|
REM COPY /B /V /Y "!_myname!.bat" "[updated]!_myname!.bat"
|
|
|
|
(
|
2018-02-23 01:47:38 -05:00
|
|
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/updater.bat', '[updated]!_myname!.bat')"
|
2017-12-19 11:25:14 -05:00
|
|
|
) >nul 2>&1
|
|
|
|
IF EXIST "[updated]!_myname!.bat" (
|
|
|
|
START /min CMD /C "[updated]!_myname!.bat" !_myparams!
|
|
|
|
) ELSE (
|
|
|
|
CALL :message "Failed. Make sure PowerShell is allowed internet access."
|
|
|
|
TIMEOUT 120 >nul
|
|
|
|
)
|
|
|
|
) ELSE (
|
|
|
|
IF "!_myname!"=="[updated]" (
|
|
|
|
CALL :message "The [updated] label is reserved. Rename this script and try again."
|
|
|
|
TIMEOUT 300 >nul
|
|
|
|
) ELSE (
|
|
|
|
REM ## Phase 2 ##: The [updated]*.bat script will:
|
|
|
|
REM * Copy itself overwriting the original batch
|
|
|
|
REM * Start that script in a new CMD instance
|
|
|
|
REM * Exit
|
|
|
|
IF EXIST "!_myname:~9!.bat" (
|
|
|
|
REN "!_myname:~9!.bat" "!_myname:~9!.bat.old"
|
|
|
|
DEL /F "!_myname:~9!.bat.old"
|
|
|
|
)
|
|
|
|
COPY /B /V /Y "!_myname!.bat" "!_myname:~9!.bat"
|
|
|
|
START CMD /C "!_myname:~9!.bat" !_myparams!
|
|
|
|
)
|
|
|
|
)
|
2018-04-18 16:33:39 -04:00
|
|
|
EXIT /B
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
|
|
|
:begin
|
2018-03-01 14:15:10 -05:00
|
|
|
CLS
|
2017-12-19 11:25:14 -05:00
|
|
|
ECHO:
|
|
|
|
ECHO:
|
|
|
|
ECHO: ########################################
|
|
|
|
ECHO: #### user.js Updater for Windows ####
|
|
|
|
ECHO: #### by claustromaniac ####
|
2018-04-25 15:28:09 -04:00
|
|
|
ECHO: #### v4.5 ####
|
2017-12-19 11:25:14 -05:00
|
|
|
ECHO: ########################################
|
|
|
|
ECHO:
|
|
|
|
SET /A "_line=0"
|
|
|
|
IF NOT EXIST user.js (
|
|
|
|
CALL :message "user.js not detected in the current directory."
|
|
|
|
) ELSE (
|
2018-01-15 20:15:30 -05:00
|
|
|
FOR /F "skip=1 tokens=1,* delims=:" %%G IN (user.js) DO (
|
2017-12-19 11:25:14 -05:00
|
|
|
SET /A "_line+=1"
|
2017-12-24 22:48:39 -05:00
|
|
|
IF !_line! GEQ 4 (GOTO exitloop)
|
|
|
|
IF !_line! EQU 1 (SET _name=%%H)
|
|
|
|
IF !_line! EQU 2 (SET _date=%%H)
|
|
|
|
IF !_line! EQU 3 (SET _version=%%G)
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
|
|
|
:exitloop
|
2018-01-16 08:46:57 -05:00
|
|
|
IF NOT "!_name!"=="" (
|
2017-12-19 11:25:14 -05:00
|
|
|
IF /I NOT "!_name!"=="!_name:ghacks=!" (
|
2018-01-16 08:46:57 -05:00
|
|
|
CALL :message "!_name! !_version:~2!,!_date!"
|
|
|
|
) ELSE (CALL :message "Current user.js version not recognised.")
|
|
|
|
) ELSE (CALL :message "Current user.js version not recognised.")
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
|
|
|
ECHO:
|
|
|
|
IF NOT DEFINED _ua (
|
|
|
|
CALL :message "This batch should be run from your Firefox profile directory."
|
|
|
|
ECHO: It will download the latest version of ghacks user.js from github and then
|
|
|
|
CALL :message "append any of your own changes from user-overrides.js to it."
|
|
|
|
CALL :message "Visit the wiki for more detailed information."
|
|
|
|
ECHO:
|
|
|
|
TIMEOUT 1 /nobreak >nul
|
|
|
|
CHOICE /C SHE /N /M "Start [S] Help [H] Exit [E]"
|
|
|
|
CLS
|
2017-12-24 22:48:39 -05:00
|
|
|
IF ERRORLEVEL 3 (EXIT /B)
|
|
|
|
IF ERRORLEVEL 2 (GOTO :showhelp)
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
|
|
|
IF DEFINED _log (
|
|
|
|
CALL :log >>user.js-update-log.txt 2>&1
|
2017-12-24 22:48:39 -05:00
|
|
|
IF DEFINED _logp (START user.js-update-log.txt)
|
2017-12-19 11:25:14 -05:00
|
|
|
EXIT /B
|
|
|
|
:log
|
2017-12-26 12:29:11 -05:00
|
|
|
SET _log=2
|
2017-12-19 11:25:14 -05:00
|
|
|
ECHO:##################################################################
|
2018-03-01 14:15:10 -05:00
|
|
|
ECHO: %date%, %time%
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
2018-01-15 20:15:30 -05:00
|
|
|
IF EXIST user.js.new (DEL /F "user.js.new")
|
2017-12-19 11:25:14 -05:00
|
|
|
CALL :message "Retrieving latest user.js file from github repository..."
|
|
|
|
(
|
2018-02-23 01:47:38 -05:00
|
|
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js', 'user.js.new')"
|
2017-12-19 11:25:14 -05:00
|
|
|
) >nul 2>&1
|
2018-01-15 20:15:30 -05:00
|
|
|
IF EXIST user.js.new (
|
2017-12-19 11:25:14 -05:00
|
|
|
IF DEFINED _multi (
|
|
|
|
FORFILES /P user.js-overrides /M *.js >nul 2>&1
|
|
|
|
IF NOT ERRORLEVEL 1 (
|
|
|
|
IF DEFINED _merge (
|
|
|
|
CALL :message "Merging..."
|
|
|
|
COPY /B /V /Y user.js-overrides\*.js user-overrides-merged.js
|
|
|
|
CALL :merge user-overrides-merged.js
|
2018-01-15 20:15:30 -05:00
|
|
|
COPY /B /V /Y user.js.new+user-overrides-merged.js user.js.new
|
|
|
|
CALL :merge user.js.new
|
2017-12-19 11:25:14 -05:00
|
|
|
) ELSE (
|
|
|
|
CALL :message "Appending..."
|
2018-01-15 20:15:30 -05:00
|
|
|
COPY /B /V /Y user.js.new+"user.js-overrides\*.js" user.js.new
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
2017-12-24 22:48:39 -05:00
|
|
|
) ELSE (CALL :message "No override files found.")
|
2017-12-19 11:25:14 -05:00
|
|
|
) ELSE (
|
|
|
|
IF EXIST "user-overrides.js" (
|
2018-01-15 20:15:30 -05:00
|
|
|
COPY /B /V /Y user.js.new+"user-overrides.js" "user.js.new"
|
2017-12-19 11:25:14 -05:00
|
|
|
IF DEFINED _merge (
|
|
|
|
CALL :message "Merging user-overrides.js..."
|
2018-01-15 20:15:30 -05:00
|
|
|
CALL :merge user.js.new
|
2017-12-19 11:25:14 -05:00
|
|
|
) ELSE (
|
|
|
|
CALL :message "user-overrides.js appended."
|
|
|
|
)
|
2017-12-24 22:48:39 -05:00
|
|
|
) ELSE (CALL :message "user-overrides.js not found.")
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
2018-01-15 20:15:30 -05:00
|
|
|
IF EXIST user.js (
|
|
|
|
FC user.js.new user.js >nul && SET "_changed=false" || SET "_changed=true"
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
2018-01-15 20:15:30 -05:00
|
|
|
IF "!_changed!"=="true" (
|
|
|
|
CALL :message "Backing up..."
|
2018-01-17 10:30:02 -05:00
|
|
|
IF DEFINED _singlebackup (
|
2018-01-15 20:15:30 -05:00
|
|
|
MOVE /Y user.js user.js.bak >nul
|
2018-01-17 10:30:02 -05:00
|
|
|
) ELSE (
|
2018-04-18 16:33:39 -04:00
|
|
|
SET "_time=!time: =0!"
|
|
|
|
MOVE /Y user.js "user-backup-!date:/=-!_!_time::=.!.js" >nul
|
2018-01-15 20:15:30 -05:00
|
|
|
)
|
|
|
|
REN user.js.new user.js
|
2017-12-19 11:25:14 -05:00
|
|
|
CALL :message "Update complete."
|
|
|
|
) ELSE (
|
2018-01-15 20:15:30 -05:00
|
|
|
IF "!_changed!"=="false" (
|
|
|
|
DEL /F user.js.new >nul
|
2017-12-19 11:25:14 -05:00
|
|
|
CALL :message "Update completed without changes."
|
2018-01-15 20:15:30 -05:00
|
|
|
) ELSE (
|
|
|
|
REN user.js.new user.js
|
2018-01-16 09:13:07 -05:00
|
|
|
CALL :message "Update complete."
|
2018-01-15 20:15:30 -05:00
|
|
|
)
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
|
|
|
) ELSE (
|
|
|
|
CALL :message "Update failed. Make sure PowerShell is allowed internet access."
|
2018-02-23 01:47:38 -05:00
|
|
|
ECHO: No changes were made.
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
|
|
|
IF NOT DEFINED _log (
|
2017-12-24 22:48:39 -05:00
|
|
|
IF NOT DEFINED _ua (PAUSE)
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
|
|
|
EXIT /B
|
|
|
|
|
|
|
|
REM ########### Message Function ###########
|
|
|
|
:message
|
|
|
|
SETLOCAL DisableDelayedExpansion
|
2017-12-26 12:29:11 -05:00
|
|
|
IF NOT "2"=="%_log%" (ECHO:)
|
2017-12-19 11:25:14 -05:00
|
|
|
ECHO: %~1
|
2017-12-26 12:29:11 -05:00
|
|
|
IF NOT "2"=="%_log%" (ECHO:)
|
2017-12-19 11:25:14 -05:00
|
|
|
ENDLOCAL
|
|
|
|
GOTO :EOF
|
|
|
|
REM ############ Merge function ############
|
|
|
|
:merge
|
|
|
|
SETLOCAL DisableDelayedExpansion
|
2018-04-25 15:28:09 -04:00
|
|
|
FOR /F tokens^=2^,^*^ delims^=^'^" %%G IN ('FINDSTR /R /C:"^user_pref[ ]*\([ ]*[\"'].*[\"'][ ]*,.*\)[ ]*;" "%~1"') DO (SET "[%%G]=%%H")
|
2018-08-06 15:14:56 -04:00
|
|
|
|
2018-04-25 15:28:09 -04:00
|
|
|
FOR /F tokens^=2^,^*^ delims^=^' %%G IN ('FINDSTR /R /C:"^//// --- comment-out --- '[^'][^']*'.*" "%~1"') DO (SET "__unset__%%G=1")
|
2017-12-19 11:25:14 -05:00
|
|
|
(
|
|
|
|
FOR /F "tokens=1,* delims=:" %%I IN ('FINDSTR /N "^" "%~1"') DO (
|
2018-01-15 20:15:30 -05:00
|
|
|
SET "_temp=%%J"
|
|
|
|
SETLOCAL EnableDelayedExpansion
|
2018-01-17 10:30:02 -05:00
|
|
|
IF NOT "!_temp:~0,9!"=="user_pref" (
|
2018-01-15 20:15:30 -05:00
|
|
|
ENDLOCAL & ECHO:%%J
|
2017-12-19 11:25:14 -05:00
|
|
|
) ELSE (
|
2018-01-17 10:30:02 -05:00
|
|
|
IF "!_temp:;=!"=="!_temp!" (
|
2018-01-15 20:15:30 -05:00
|
|
|
ENDLOCAL & ECHO:%%J
|
|
|
|
) ELSE (
|
|
|
|
ENDLOCAL
|
|
|
|
FOR /F tokens^=2^ delims^=^'^" %%K IN ("%%J") DO (
|
2018-08-06 15:14:56 -04:00
|
|
|
|
2018-01-15 20:15:30 -05:00
|
|
|
IF NOT "_user.js.parrot"=="%%K" (
|
2018-04-25 15:28:09 -04:00
|
|
|
IF DEFINED __unset__%%K (
|
|
|
|
ECHO://%%J
|
|
|
|
) ELSE (
|
|
|
|
IF DEFINED [%%K] (
|
|
|
|
SETLOCAL EnableDelayedExpansion
|
|
|
|
FOR /F "delims=" %%L IN ("![%%K]!") DO (
|
|
|
|
ENDLOCAL & ECHO:user_pref("%%K"%%L
|
|
|
|
SET "[%%K]="
|
|
|
|
)
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
|
|
|
)
|
2018-01-15 20:15:30 -05:00
|
|
|
) ELSE (ECHO:%%J)
|
2017-12-19 11:25:14 -05:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)>updatertempfile
|
|
|
|
MOVE /Y updatertempfile "%~1" >nul
|
|
|
|
ENDLOCAL
|
|
|
|
GOTO :EOF
|
|
|
|
REM ############### Help ##################
|
|
|
|
:showhelp
|
2018-01-15 20:15:30 -05:00
|
|
|
MODE 80,46
|
2017-12-19 11:25:14 -05:00
|
|
|
CLS
|
2017-12-24 11:49:33 -05:00
|
|
|
CALL :message "Available arguments (case-insensitive):"
|
2017-12-19 11:25:14 -05:00
|
|
|
CALL :message " -log"
|
2017-12-24 19:51:56 -05:00
|
|
|
ECHO: Write the console output to a logfile (user.js-update-log.txt)
|
2017-12-19 11:25:14 -05:00
|
|
|
CALL :message " -logP"
|
2017-12-24 19:51:56 -05:00
|
|
|
ECHO: Like -log, but also open the logfile after updating.
|
2017-12-19 11:25:14 -05:00
|
|
|
CALL :message " -merge"
|
2018-01-15 20:15:30 -05:00
|
|
|
ECHO: Merge overrides instead of appending them. Single-line comments and
|
2017-12-24 11:49:33 -05:00
|
|
|
ECHO: _user.js.parrot lines are appended normally. Overrides for inactive
|
2017-12-19 11:25:14 -05:00
|
|
|
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: directory for quick reference. It contains only the merged data from
|
|
|
|
ECHO: override files and can be safely discarded after updating, or used as the
|
|
|
|
ECHO: new user-overrides.js. When there are conflicting records for the same
|
2017-12-24 11:55:17 -05:00
|
|
|
ECHO: pref, the value of the last one declared will be used. Visit the wiki
|
|
|
|
ECHO: for usage examples and more detailed information.
|
2017-12-19 11:25:14 -05:00
|
|
|
CALL :message " -multiOverrides"
|
2017-12-24 19:51:56 -05:00
|
|
|
ECHO: Use any and all .js files in a user.js-overrides sub-folder as overrides
|
2017-12-19 11:25:14 -05:00
|
|
|
ECHO: instead of the default user-overrides.js file. Files are appended in
|
|
|
|
ECHO: alphabetical order.
|
2017-12-24 11:49:33 -05:00
|
|
|
CALL :message " -unattended"
|
2017-12-24 19:51:56 -05:00
|
|
|
ECHO: Run without user input.
|
2018-01-17 23:18:05 -05:00
|
|
|
CALL :message " -singleBackup"
|
|
|
|
ECHO: Use a single backup file and overwrite it on new updates, instead of
|
|
|
|
ECHO: cumulative backups. This was the default behaviour before v4.3.
|
2017-12-19 11:25:14 -05:00
|
|
|
CALL :message " -updatebatch"
|
2017-12-24 19:51:56 -05:00
|
|
|
ECHO: Update the script itself on execution, before the normal routine.
|
2017-12-19 11:25:14 -05:00
|
|
|
CALL :message ""
|
|
|
|
PAUSE
|
|
|
|
MODE 80,25
|
|
|
|
GOTO :begin
|
|
|
|
REM #####################################
|