commit f90c17f74894c0e1b2ff9437b79c2b9eae11f073
parent d055560f6f80150b7b2e2cbe5de7647d68543456
Author: earthlng <earthlng@users.noreply.github.com>
Date: Sun, 22 Apr 2018 14:16:05 +0200
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`)
Diffstat:
2 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/prefsCleaner.bat b/prefsCleaner.bat
@@ -1,18 +1,17 @@
-@ECHO OFF
+@ECHO OFF & SETLOCAL DisableDelayedExpansion
TITLE prefs.js cleaner
REM ### prefs.js cleaner for Windows
REM ## author: @claustromaniac
-REM ## version: 1.2
+REM ## version: 2.0
-SETLOCAL EnableDelayedExpansion
:begin
ECHO:
ECHO:
ECHO ########################################
ECHO #### prefs.js cleaner for Windows ####
ECHO #### by claustromaniac ####
-ECHO #### v1.2 ####
+ECHO #### v2.0 ####
ECHO ########################################
ECHO:
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)
CALL :FFcheck
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 :cleanup
-CLS
-CALL :message "All done^!"
+CALL :message "All done!"
TIMEOUT 5 >nul
+ENDLOCAL
EXIT /B
REM ########## Abort Function ###########
@@ -44,11 +44,9 @@ TIMEOUT %~2 >nul
EXIT
REM ########## Message Function #########
:message
-SETLOCAL DisableDelayedExpansion
ECHO:
ECHO: %~1
ECHO:
-ENDLOCAL
GOTO :EOF
REM ####### Firefox Check Function ######
:FFcheck
@@ -57,7 +55,7 @@ IF NOT ERRORLEVEL 1 (
CLS
CALL :message "Firefox is still running."
ECHO If you're not currently using this profile you can continue, otherwise
- CALL :message "close Firefox first^!"
+ CALL :message "close Firefox first!"
ECHO:
PAUSE
CLS
@@ -67,23 +65,20 @@ IF NOT ERRORLEVEL 1 (
GOTO :EOF
REM ######### Cleanup Function ##########
: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 (
- SET "_line=%%H"
- SETLOCAL EnableDelayedExpansion
- 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!)
- )
+ IF ""=="%%H" (
+ ECHO:
) ELSE (
- ECHO:!_line!
+ FOR /F tokens^=1^,2^ delims^=^"^' %%I IN ("%%H") DO (
+ IF NOT DEFINED [%%J] (ECHO:%%H)
+ )
)
- ENDLOCAL
)
)>tempcleanedprefs
-ENDLOCAL
MOVE /Y tempcleanedprefs prefs.js
GOTO :EOF
REM ############### Help ##################
diff --git a/updater.bat b/updater.bat
@@ -66,7 +66,7 @@ IF DEFINED _updateb (
START CMD /C "!_myname:~9!.bat" !_myparams!
)
)
- EXIT /B
+ EXIT /B
)
:begin
CLS
@@ -157,7 +157,8 @@ IF EXIST user.js.new (
IF DEFINED _singlebackup (
MOVE /Y user.js user.js.bak >nul
) 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
CALL :message "Update complete."