From 68d20d0f76037d407e5ec0537ab7e1eec276b87b Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Tue, 12 Dec 2017 21:09:39 +0000 Subject: [PATCH 1/9] initial commit --- prefs cleaner.bat | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 prefs cleaner.bat diff --git a/prefs cleaner.bat b/prefs cleaner.bat new file mode 100644 index 0000000..b0a6900 --- /dev/null +++ b/prefs cleaner.bat @@ -0,0 +1,61 @@ +@ECHO OFF +TITLE prefs.js cleaner + +REM ### prefs.js cleaner for Windows +REM ## author: @claustromaniac +REM ## version: 1.0b + +SETLOCAL EnableDelayedExpansion +CALL :message "This batch should be run from your Firefox profile directory. It will remove from prefs.js any entries that exist in user.js, allowing inactive preferences to reset to default value." +CHOICE /M "Continue" +IF ERRORLEVEL 2 ( EXIT /B ) +CLS +IF NOT EXIST "user.js" ( CALL :abort "user.js not found in the current directory." 30 ) +IF NOT EXIST "prefs.js" ( CALL :abort "prefs.js not found in the current directory." 30 ) +IF EXIST "webappsstore.sqlite-shm" ( CALL :abort "Running this script while Firefox is also running is useless. Close Firefox and try again." 60 ) +CALL :message "Backing up prefs.js..." +COPY /B /V /Y prefs.js "prefs-backup-!date:/=-!, !time::=.!.js" +CALL :message "Cleaning prefs.js... (this can take a while)" +CALL :cleanup +CLS +CALL :message "All done." +TIMEOUT 5 >nul +EXIT /B + +REM ######### Cleanup Function ########## +:cleanup +SETLOCAL DisableDelayedExpansion +( + FOR /F "tokens=1,* delims=]" %%G IN ('FIND /N /V "" ^< "prefs.js"') DO ( + SET "_line=%%H" + SETLOCAL EnableDelayedExpansion + SET "_pref=!_line: =!" + FOR /F "delims=," %%X IN ("!_pref!") DO ( SET "_pref=%%X" ) + IF /I "user_pref"=="!_pref:~0,9!" ( + SET _pref=!_pref:"=""! + FIND /I "!_pref!" user.js >nul + IF ERRORLEVEL 1 ( + ECHO(!_line! + ) + ) ELSE ( + ECHO(!_line! + ) + ENDLOCAL + ) +)>newprefs.js +ENDLOCAL +MOVE /Y newprefs.js prefs.js +GOTO :EOF +REM ########## Message Function ######### +:message +ECHO. +ECHO %~1 +ECHO. +GOTO :EOF +REM ########## Abort Function ########### +:abort +CALL :message %1 +ECHO. +TIMEOUT %~2 >nul +EXIT +REM ##################################### From f07bbb6c85bed98daf3bbeb3e5afe7c00119fed2 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Wed, 13 Dec 2017 04:18:10 +0000 Subject: [PATCH 2/9] 1.0b2 Fix for long lines Fixed long lines getting truncated. Improved other aspects for performance. --- prefs cleaner.bat | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/prefs cleaner.bat b/prefs cleaner.bat index b0a6900..62b2961 100644 --- a/prefs cleaner.bat +++ b/prefs cleaner.bat @@ -3,7 +3,7 @@ TITLE prefs.js cleaner REM ### prefs.js cleaner for Windows REM ## author: @claustromaniac -REM ## version: 1.0b +REM ## version: 1.0b2 SETLOCAL EnableDelayedExpansion CALL :message "This batch should be run from your Firefox profile directory. It will remove from prefs.js any entries that exist in user.js, allowing inactive preferences to reset to default value." @@ -26,7 +26,7 @@ REM ######### Cleanup Function ########## :cleanup SETLOCAL DisableDelayedExpansion ( - FOR /F "tokens=1,* delims=]" %%G IN ('FIND /N /V "" ^< "prefs.js"') DO ( + FOR /F "tokens=1,* delims=:" %%G IN ( 'FINDSTR /N "^" prefs.js' ) DO ( SET "_line=%%H" SETLOCAL EnableDelayedExpansion SET "_pref=!_line: =!" @@ -35,10 +35,10 @@ SETLOCAL DisableDelayedExpansion SET _pref=!_pref:"=""! FIND /I "!_pref!" user.js >nul IF ERRORLEVEL 1 ( - ECHO(!_line! + ECHO:!_line! ) ) ELSE ( - ECHO(!_line! + ECHO:!_line! ) ENDLOCAL ) @@ -48,14 +48,13 @@ MOVE /Y newprefs.js prefs.js GOTO :EOF REM ########## Message Function ######### :message -ECHO. -ECHO %~1 -ECHO. +ECHO: +ECHO:%~1 +ECHO: GOTO :EOF REM ########## Abort Function ########### :abort CALL :message %1 -ECHO. TIMEOUT %~2 >nul EXIT REM ##################################### From e3b8d0955b7393ea41865bdd419753285f07a660 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Wed, 13 Dec 2017 11:47:39 +0000 Subject: [PATCH 3/9] Minor improvement. --- prefs cleaner.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prefs cleaner.bat b/prefs cleaner.bat index 62b2961..a0ed289 100644 --- a/prefs cleaner.bat +++ b/prefs cleaner.bat @@ -30,8 +30,8 @@ SETLOCAL DisableDelayedExpansion SET "_line=%%H" SETLOCAL EnableDelayedExpansion SET "_pref=!_line: =!" - FOR /F "delims=," %%X IN ("!_pref!") DO ( SET "_pref=%%X" ) IF /I "user_pref"=="!_pref:~0,9!" ( + FOR /F "delims=," %%X IN ("!_pref!") DO ( SET "_pref=%%X" ) SET _pref=!_pref:"=""! FIND /I "!_pref!" user.js >nul IF ERRORLEVEL 1 ( From e1c3d6993b0aa49b8614c67855ad555a0ea16720 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Thu, 14 Dec 2017 01:31:54 +0000 Subject: [PATCH 4/9] 1.0b3 - Improved check to see if Firefox is running. The script now waits for the user to close it, and resumes on its own afterwards. - Added Help option, that displays troubleshooting information. - Reordered functions. - Some cosmetic changes suggested by @earthing --- prefs cleaner.bat | 80 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/prefs cleaner.bat b/prefs cleaner.bat index a0ed289..2304816 100644 --- a/prefs cleaner.bat +++ b/prefs cleaner.bat @@ -3,18 +3,27 @@ TITLE prefs.js cleaner REM ### prefs.js cleaner for Windows REM ## author: @claustromaniac -REM ## version: 1.0b2 +REM ## version: 1.0b3 SETLOCAL EnableDelayedExpansion -CALL :message "This batch should be run from your Firefox profile directory. It will remove from prefs.js any entries that exist in user.js, allowing inactive preferences to reset to default value." -CHOICE /M "Continue" -IF ERRORLEVEL 2 ( EXIT /B ) +:begin CLS +CALL :message "This batch should be run from your Firefox profile directory." +CALL :message "It will remove from prefs.js any entries that also exist in user.js." +CALL :message "This will allow inactive preferences to reset to default value." +ECHO: +CHOICE /C SHE /N /M "Start [S] Help [H] Exit [E]" +CLS +IF ERRORLEVEL 3 ( EXIT /B ) +IF ERRORLEVEL 2 ( + CALL :showhelp + GOTO :begin +) IF NOT EXIST "user.js" ( CALL :abort "user.js not found in the current directory." 30 ) IF NOT EXIST "prefs.js" ( CALL :abort "prefs.js not found in the current directory." 30 ) -IF EXIST "webappsstore.sqlite-shm" ( CALL :abort "Running this script while Firefox is also running is useless. Close Firefox and try again." 60 ) +CALL :FFcheck CALL :message "Backing up prefs.js..." -COPY /B /V /Y prefs.js "prefs-backup-!date:/=-!, !time::=.!.js" +COPY /B /V /Y prefs.js "prefs-backup-!date:/=-!_!time::=.!.js" CALL :message "Cleaning prefs.js... (this can take a while)" CALL :cleanup CLS @@ -22,6 +31,27 @@ CALL :message "All done." TIMEOUT 5 >nul EXIT /B +REM ########## Abort Function ########### +:abort +CALL :message %1 +TIMEOUT %~2 >nul +EXIT +REM ########## Message Function ######### +:message +ECHO: +ECHO:%~1 +ECHO: +GOTO :EOF +REM ####### Firefox Check Function ###### +:FFcheck +TASKLIST /FI "IMAGENAME eq firefox.exe" 2>NUL | FIND /I /N "firefox.exe">NUL +IF NOT ERRORLEVEL 1 ( + CLS + CALL :message "Please, close Firefox to continue." + TIMEOUT 3 >nul + GOTO :FFcheck +) +GOTO :EOF REM ######### Cleanup Function ########## :cleanup SETLOCAL DisableDelayedExpansion @@ -46,15 +76,37 @@ SETLOCAL DisableDelayedExpansion ENDLOCAL MOVE /Y newprefs.js prefs.js GOTO :EOF -REM ########## Message Function ######### -:message +REM ########### Help Function ########### +:showhelp +CLS +CALL :message "This script creates a backup of your prefs.js file before doing anything." +CALL :message "It should be safe, but you can follow these steps if something goes wrong:" +ECHO 1. Make sure Firefox is closed. ECHO: -ECHO:%~1 +ECHO 2. Delete prefs.js in your profile folder. ECHO: +ECHO 3. Delete Invalidprefs.js if you have one in the same folder. +ECHO: +ECHO 4. Rename or copy your latest backup to prefs.js. +ECHO: +ECHO 5. Run Firefox and see if you notice anything wrong with it. +ECHO: +ECHO 6. If you do, restart it again, and check back. +ECHO: +ECHO 7. If you still notice something wrong, especially with your extensions, +ECHO: +ECHO and/or with the UI, go to about:support, and restart Firefox with +ECHO: +ECHO add-ons disabled. Then, restart it again normally, and see if the problems +ECHO: +ECHO were solved. +ECHO: +ECHO If you are able to identify the cause of your issues, please bring it up on +ECHO: +ECHO ghacks-user.js GitHub repository. +ECHO: +ECHO: +PAUSE +CLS GOTO :EOF -REM ########## Abort Function ########### -:abort -CALL :message %1 -TIMEOUT %~2 >nul -EXIT REM ##################################### From be15603be8b5a0bcca95b70d3be5a5642922e848 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Thu, 14 Dec 2017 01:58:33 +0000 Subject: [PATCH 5/9] +Verbosity --- prefs cleaner.bat | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/prefs cleaner.bat b/prefs cleaner.bat index 2304816..582d809 100644 --- a/prefs cleaner.bat +++ b/prefs cleaner.bat @@ -11,6 +11,7 @@ CLS CALL :message "This batch should be run from your Firefox profile directory." CALL :message "It will remove from prefs.js any entries that also exist in user.js." CALL :message "This will allow inactive preferences to reset to default value." +CALL :message "Firefox needs to stay closed during the process." ECHO: CHOICE /C SHE /N /M "Start [S] Help [H] Exit [E]" CLS @@ -24,7 +25,8 @@ IF NOT EXIST "prefs.js" ( CALL :abort "prefs.js not found in the current directo CALL :FFcheck CALL :message "Backing up prefs.js..." COPY /B /V /Y prefs.js "prefs-backup-!date:/=-!_!time::=.!.js" -CALL :message "Cleaning prefs.js... (this can take a while)" +CALL :message "Cleaning prefs.js... +CALL :message "Don't close this window and don't run Firefox until this is done." CALL :cleanup CLS CALL :message "All done." From c8d21f7c4ed8842218133a64efd4c85e8f629f54 Mon Sep 17 00:00:00 2001 From: Thorin-Oakenpants Date: Thu, 14 Dec 2017 16:13:08 +1300 Subject: [PATCH 6/9] more verbosity --- prefs cleaner.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prefs cleaner.bat b/prefs cleaner.bat index 582d809..2fd3040 100644 --- a/prefs cleaner.bat +++ b/prefs cleaner.bat @@ -9,8 +9,8 @@ SETLOCAL EnableDelayedExpansion :begin CLS CALL :message "This batch should be run from your Firefox profile directory." -CALL :message "It will remove from prefs.js any entries that also exist in user.js." -CALL :message "This will allow inactive preferences to reset to default value." +CALL :message "It will remove from any entries from prefs.js that also exist in user.js." +CALL :message "This will allow inactive preferences to be reset to their default values." CALL :message "Firefox needs to stay closed during the process." ECHO: CHOICE /C SHE /N /M "Start [S] Help [H] Exit [E]" From b25e0a196a58f8e793ffda789a40855ee5de738e Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Thu, 14 Dec 2017 10:47:52 +0000 Subject: [PATCH 7/9] less verbosity J/K --- prefs cleaner.bat | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/prefs cleaner.bat b/prefs cleaner.bat index 2fd3040..7e10e06 100644 --- a/prefs cleaner.bat +++ b/prefs cleaner.bat @@ -9,7 +9,7 @@ SETLOCAL EnableDelayedExpansion :begin CLS CALL :message "This batch should be run from your Firefox profile directory." -CALL :message "It will remove from any entries from prefs.js that also exist in user.js." +CALL :message "It will remove any entries from prefs.js that also exist in user.js." CALL :message "This will allow inactive preferences to be reset to their default values." CALL :message "Firefox needs to stay closed during the process." ECHO: @@ -83,28 +83,18 @@ REM ########### Help Function ########### CLS CALL :message "This script creates a backup of your prefs.js file before doing anything." CALL :message "It should be safe, but you can follow these steps if something goes wrong:" -ECHO 1. Make sure Firefox is closed. -ECHO: +CALL :message " 1. Make sure Firefox is closed." ECHO 2. Delete prefs.js in your profile folder. -ECHO: -ECHO 3. Delete Invalidprefs.js if you have one in the same folder. -ECHO: +CALL :message " 3. Delete Invalidprefs.js if you have one in the same folder." ECHO 4. Rename or copy your latest backup to prefs.js. -ECHO: -ECHO 5. Run Firefox and see if you notice anything wrong with it. -ECHO: +CALL :message " 5. Run Firefox and see if you notice anything wrong with it." ECHO 6. If you do, restart it again, and check back. -ECHO: -ECHO 7. If you still notice something wrong, especially with your extensions, -ECHO: +CALL :message " 7. If you still notice something wrong, especially with your extensions," ECHO and/or with the UI, go to about:support, and restart Firefox with -ECHO: -ECHO add-ons disabled. Then, restart it again normally, and see if the problems -ECHO: +CALL :message " add-ons disabled. Then, restart it again normally, and see if the problems" ECHO were solved. ECHO: -ECHO If you are able to identify the cause of your issues, please bring it up on -ECHO: +CALL :message "If you are able to identify the cause of your issues, please bring it up on" ECHO ghacks-user.js GitHub repository. ECHO: ECHO: From ee7d95b8c173965fad57de7ff878f6779a137889 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Fri, 15 Dec 2017 15:40:11 +0000 Subject: [PATCH 8/9] 1.0b4 - Mostly cosmetic changes. --- prefs cleaner.bat | 72 ++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/prefs cleaner.bat b/prefs cleaner.bat index 7e10e06..378c51e 100644 --- a/prefs cleaner.bat +++ b/prefs cleaner.bat @@ -3,30 +3,33 @@ TITLE prefs.js cleaner REM ### prefs.js cleaner for Windows REM ## author: @claustromaniac -REM ## version: 1.0b3 +REM ## version: 1.0b4 SETLOCAL EnableDelayedExpansion :begin -CLS -CALL :message "This batch should be run from your Firefox profile directory." -CALL :message "It will remove any entries from prefs.js that also exist in user.js." -CALL :message "This will allow inactive preferences to be reset to their default values." -CALL :message "Firefox needs to stay closed during the process." ECHO: +ECHO: +ECHO ######################################## +ECHO #### prefs.js cleaner for Windows #### +ECHO #### author: @claustromaniac #### +ECHO #### version: 1.0 #### +ECHO ######################################## +ECHO: +CALL :message "This script should be run from your Firefox profile directory." +ECHO It will remove any entries from prefs.js that also exist in user.js. +CALL :message "This will allow inactive preferences to be reset to their default values." +ECHO Don't use this profile during the process. +CALL :message "" CHOICE /C SHE /N /M "Start [S] Help [H] Exit [E]" CLS IF ERRORLEVEL 3 ( EXIT /B ) -IF ERRORLEVEL 2 ( - CALL :showhelp - GOTO :begin -) +IF ERRORLEVEL 2 ( GOTO :showhelp ) IF NOT EXIST "user.js" ( CALL :abort "user.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 :message "Backing up prefs.js..." COPY /B /V /Y prefs.js "prefs-backup-!date:/=-!_!time::=.!.js" CALL :message "Cleaning prefs.js... -CALL :message "Don't close this window and don't run Firefox until this is done." CALL :cleanup CLS CALL :message "All done." @@ -41,7 +44,7 @@ EXIT REM ########## Message Function ######### :message ECHO: -ECHO:%~1 +ECHO: %~1 ECHO: GOTO :EOF REM ####### Firefox Check Function ###### @@ -49,9 +52,14 @@ REM ####### Firefox Check Function ###### TASKLIST /FI "IMAGENAME eq firefox.exe" 2>NUL | FIND /I /N "firefox.exe">NUL IF NOT ERRORLEVEL 1 ( CLS - CALL :message "Please, close Firefox to continue." - TIMEOUT 3 >nul - GOTO :FFcheck + CALL :message "Firefox is still running." + ECHO If it's not using this profile you can continue, otherwise close it first^^! + ECHO: + ECHO: + PAUSE + CLS + CALL :message "Resuming..." + TIMEOUT 5 /nobreak >nul ) GOTO :EOF REM ######### Cleanup Function ########## @@ -74,31 +82,31 @@ SETLOCAL DisableDelayedExpansion ) ENDLOCAL ) -)>newprefs.js +)>tempcleanedprefs ENDLOCAL -MOVE /Y newprefs.js prefs.js +MOVE /Y tempcleanedprefs prefs.js GOTO :EOF -REM ########### Help Function ########### +REM ############### Help ################## :showhelp CLS CALL :message "This script creates a backup of your prefs.js file before doing anything." -CALL :message "It should be safe, but you can follow these steps if something goes wrong:" -CALL :message " 1. Make sure Firefox is closed." -ECHO 2. Delete prefs.js in your profile folder. -CALL :message " 3. Delete Invalidprefs.js if you have one in the same folder." -ECHO 4. Rename or copy your latest backup to prefs.js. -CALL :message " 5. Run Firefox and see if you notice anything wrong with it." -ECHO 6. If you do, restart it again, and check back. -CALL :message " 7. If you still notice something wrong, especially with your extensions," -ECHO and/or with the UI, go to about:support, and restart Firefox with -CALL :message " add-ons disabled. Then, restart it again normally, and see if the problems" -ECHO were solved. +ECHO It should be safe, but you can follow these steps if something goes wrong: ECHO: -CALL :message "If you are able to identify the cause of your issues, please bring it up on" -ECHO ghacks-user.js GitHub repository. +CALL :message " 1. Make sure Firefox is closed." +ECHO 2. Delete prefs.js in your profile folder. +CALL :message " 3. Delete Invalidprefs.js if you have one in the same folder." +ECHO 4. Rename or copy your latest backup to prefs.js. +CALL :message " 5. Run Firefox and see if you notice anything wrong with it." +ECHO 6. If you do notice something wrong, especially with your extensions, +CALL :message " and/or with the UI, go to about:support, and restart Firefox with" +ECHO add-ons disabled. Then, restart it again normally, and see if the +CALL :message " problems were solved." +ECHO: +CALL :message "If you are able to identify the cause of your issues, please bring it up" +ECHO on ghacks-user.js GitHub repository. ECHO: ECHO: PAUSE CLS -GOTO :EOF +GOTO :begin REM ##################################### From b91e08ab040689f7117f8a35419a9ca21d4c3e0c Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Fri, 15 Dec 2017 16:55:15 +0000 Subject: [PATCH 9/9] just some re-wording --- prefs cleaner.bat | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/prefs cleaner.bat b/prefs cleaner.bat index 378c51e..c5256b5 100644 --- a/prefs cleaner.bat +++ b/prefs cleaner.bat @@ -18,7 +18,7 @@ ECHO: CALL :message "This script should be run from your Firefox profile directory." ECHO It will remove any entries from prefs.js that also exist in user.js. CALL :message "This will allow inactive preferences to be reset to their default values." -ECHO Don't use this profile during the process. +ECHO This Firefox profile shouldn't be in use during the process. CALL :message "" CHOICE /C SHE /N /M "Start [S] Help [H] Exit [E]" CLS @@ -53,7 +53,9 @@ TASKLIST /FI "IMAGENAME eq firefox.exe" 2>NUL | FIND /I /N "firefox.exe">NUL IF NOT ERRORLEVEL 1 ( CLS CALL :message "Firefox is still running." - ECHO If it's not using this profile you can continue, otherwise close it first^^! + ECHO If you're not currently using this profile you can continue, otherwise + ECHO: + ECHO close Firefox first^^! ECHO: ECHO: PAUSE