1
0

prefsCleaner 2.0

- massive speed improvement !! m-a-s-s-i-v-e !
- small fix to the time format used in backup filenames (replace space with zeros)
- better tolerance for special characters within preference names (which counters [the one downside that v1.2 brought along](https://github.com/ghacksuserjs/ghacks-user.js/pull/321#issuecomment-354394222)).
- other minor things, mostly to do with Delayed Expansion and the removal of it

known issue (but not really an issue):
- it skips instances of `user_pref` that have any quote or double-quote before `user_pref` (like `// "this" user_pref`)
This commit is contained in:
earthlng 2018-04-22 14:16:05 +02:00 committed by GitHub
commit f90c17f748
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 23 deletions

View File

@ -1,18 +1,17 @@
@ECHO OFF @ECHO OFF & SETLOCAL DisableDelayedExpansion
TITLE prefs.js cleaner TITLE prefs.js cleaner
REM ### prefs.js cleaner for Windows REM ### prefs.js cleaner for Windows
REM ## author: @claustromaniac REM ## author: @claustromaniac
REM ## version: 1.2 REM ## version: 2.0
SETLOCAL EnableDelayedExpansion
:begin :begin
ECHO: ECHO:
ECHO: ECHO:
ECHO ######################################## ECHO ########################################
ECHO #### prefs.js cleaner for Windows #### ECHO #### prefs.js cleaner for Windows ####
ECHO #### by claustromaniac #### ECHO #### by claustromaniac ####
ECHO #### v1.2 #### ECHO #### v2.0 ####
ECHO ######################################## ECHO ########################################
ECHO: ECHO:
CALL :message "This script should be run from your Firefox profile directory." CALL :message "This script should be run from your Firefox profile directory."
@ -29,12 +28,13 @@ IF NOT EXIST "user.js" (CALL :abort "user.js not found in the current directory.
IF NOT EXIST "prefs.js" (CALL :abort "prefs.js not found in the current directory." 30) IF NOT EXIST "prefs.js" (CALL :abort "prefs.js not found in the current directory." 30)
CALL :FFcheck CALL :FFcheck
CALL :message "Backing up prefs.js..." CALL :message "Backing up prefs.js..."
COPY /B /V /Y prefs.js "prefs-backup-!date:/=-!_!time::=.!.js" SET "_time=%time: =0%"
COPY /B /V /Y prefs.js "prefs-backup-%date:/=-%_%_time::=.%.js"
CALL :message "Cleaning prefs.js..." CALL :message "Cleaning prefs.js..."
CALL :cleanup CALL :cleanup
CLS CALL :message "All done!"
CALL :message "All done^!"
TIMEOUT 5 >nul TIMEOUT 5 >nul
ENDLOCAL
EXIT /B EXIT /B
REM ########## Abort Function ########### REM ########## Abort Function ###########
@ -44,11 +44,9 @@ TIMEOUT %~2 >nul
EXIT EXIT
REM ########## Message Function ######### REM ########## Message Function #########
:message :message
SETLOCAL DisableDelayedExpansion
ECHO: ECHO:
ECHO: %~1 ECHO: %~1
ECHO: ECHO:
ENDLOCAL
GOTO :EOF GOTO :EOF
REM ####### Firefox Check Function ###### REM ####### Firefox Check Function ######
:FFcheck :FFcheck
@ -57,7 +55,7 @@ IF NOT ERRORLEVEL 1 (
CLS CLS
CALL :message "Firefox is still running." CALL :message "Firefox is still running."
ECHO If you're not currently using this profile you can continue, otherwise ECHO If you're not currently using this profile you can continue, otherwise
CALL :message "close Firefox first^!" CALL :message "close Firefox first!"
ECHO: ECHO:
PAUSE PAUSE
CLS CLS
@ -67,23 +65,20 @@ IF NOT ERRORLEVEL 1 (
GOTO :EOF GOTO :EOF
REM ######### Cleanup Function ########## REM ######### Cleanup Function ##########
:cleanup :cleanup
SETLOCAL DisableDelayedExpansion FOR /F tokens^=2^ delims^=^'^" %%G IN ('FINDSTR /R /C:"^[^\"']*user_pref[ ]*\([ ]*[\"'][^\"']*[\"'][ ]*," user.js') DO (
IF NOT ""=="%%G" (SET "[%%G]=1")
)
( (
FOR /F "tokens=1,* delims=:" %%G IN ('FINDSTR /N "^" prefs.js') DO ( FOR /F "tokens=1,* delims=:" %%G IN ('FINDSTR /N "^" prefs.js') DO (
SET "_line=%%H" IF ""=="%%H" (
SETLOCAL EnableDelayedExpansion ECHO:
IF /I "user_pref"=="!_line:~0,9!" (
FOR /F tokens^=2^ delims^=^" %%I IN ("!_line:.=\.!") DO (
FINDSTR /R /C:"user_pref[ ]*\([ ]*[\"']%%I[\"'][ ]*," user.js >nul
IF ERRORLEVEL 1 (ECHO:!_line!)
)
) ELSE ( ) ELSE (
ECHO:!_line! FOR /F tokens^=1^,2^ delims^=^"^' %%I IN ("%%H") DO (
IF NOT DEFINED [%%J] (ECHO:%%H)
)
) )
ENDLOCAL
) )
)>tempcleanedprefs )>tempcleanedprefs
ENDLOCAL
MOVE /Y tempcleanedprefs prefs.js MOVE /Y tempcleanedprefs prefs.js
GOTO :EOF GOTO :EOF
REM ############### Help ################## REM ############### Help ##################

View File

@ -66,7 +66,7 @@ IF DEFINED _updateb (
START CMD /C "!_myname:~9!.bat" !_myparams! START CMD /C "!_myname:~9!.bat" !_myparams!
) )
) )
EXIT /B EXIT /B
) )
:begin :begin
CLS CLS
@ -157,7 +157,8 @@ IF EXIST user.js.new (
IF DEFINED _singlebackup ( IF DEFINED _singlebackup (
MOVE /Y user.js user.js.bak >nul MOVE /Y user.js user.js.bak >nul
) ELSE ( ) ELSE (
MOVE /Y user.js "user-backup-!date:/=-!_!time::=.!.js" >nul SET "_time=!time: =0!"
MOVE /Y user.js "user-backup-!date:/=-!_!_time::=.!.js" >nul
) )
REN user.js.new user.js REN user.js.new user.js
CALL :message "Update complete." CALL :message "Update complete."