prefsCleaner.bat 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. @ECHO OFF & SETLOCAL DisableDelayedExpansion
  2. TITLE prefs.js cleaner
  3. REM ### prefs.js cleaner for Windows
  4. REM ## author: @claustromaniac
  5. REM ## version: 2.2
  6. CD /D "%~dp0"
  7. :begin
  8. ECHO:
  9. ECHO:
  10. ECHO ########################################
  11. ECHO #### prefs.js cleaner for Windows ####
  12. ECHO #### by claustromaniac ####
  13. ECHO #### v2.2 ####
  14. ECHO ########################################
  15. ECHO:
  16. CALL :message "This script should be run from your Firefox profile directory."
  17. ECHO It will remove any entries from prefs.js that also exist in user.js.
  18. CALL :message "This will allow inactive preferences to be reset to their default values."
  19. ECHO This Firefox profile shouldn't be in use during the process.
  20. CALL :message ""
  21. TIMEOUT 1 /nobreak >nul
  22. CHOICE /C SHE /N /M "Start [S] Help [H] Exit [E]"
  23. CLS
  24. IF ERRORLEVEL 3 (EXIT /B)
  25. IF ERRORLEVEL 2 (GOTO :showhelp)
  26. IF NOT EXIST "user.js" (CALL :abort "user.js not found in the current directory." 30)
  27. IF NOT EXIST "prefs.js" (CALL :abort "prefs.js not found in the current directory." 30)
  28. CALL :FFcheck
  29. CALL :message "Backing up prefs.js..."
  30. SET "_time=%time: =0%"
  31. COPY /B /V /Y prefs.js "prefs-backup-%date:/=-%_%_time::=.%.js"
  32. CALL :message "Cleaning prefs.js..."
  33. CALL :cleanup
  34. CALL :message "All done!"
  35. TIMEOUT 5 >nul
  36. ENDLOCAL
  37. EXIT /B
  38. REM ########## Abort Function ###########
  39. :abort
  40. CALL :message %1
  41. TIMEOUT %~2 >nul
  42. EXIT
  43. REM ########## Message Function #########
  44. :message
  45. ECHO:
  46. ECHO: %~1
  47. ECHO:
  48. GOTO :EOF
  49. REM ####### Firefox Check Function ######
  50. :FFcheck
  51. TASKLIST /FI "IMAGENAME eq firefox.exe" 2>NUL | FIND /I /N "firefox.exe">NUL
  52. IF NOT ERRORLEVEL 1 (
  53. CLS
  54. CALL :message "Firefox is still running."
  55. ECHO If you're not currently using this profile you can continue, otherwise
  56. CALL :message "close Firefox first!"
  57. ECHO:
  58. PAUSE
  59. CLS
  60. CALL :message "Resuming..."
  61. TIMEOUT 5 /nobreak >nul
  62. )
  63. GOTO :EOF
  64. REM ######### Cleanup Function ##########
  65. :cleanup
  66. FOR /F tokens^=2^ delims^=^'^" %%G IN ('FINDSTR /R /C:"^[^\"']*user_pref[ ]*\([ ]*[\"'][^\"']*[\"'][ ]*," user.js') DO (
  67. IF NOT ""=="%%G" (SET "[%%G]=1")
  68. )
  69. (
  70. FOR /F "tokens=1,* delims=:" %%G IN ('FINDSTR /N "^" prefs.js') DO (
  71. IF ""=="%%H" (
  72. ECHO:
  73. ) ELSE (
  74. FOR /F tokens^=1^,2^ delims^=^"^' %%I IN ("%%H") DO (
  75. IF NOT DEFINED [%%J] (ECHO:%%H)
  76. )
  77. )
  78. )
  79. )>tempcleanedprefs
  80. MOVE /Y tempcleanedprefs prefs.js
  81. GOTO :EOF
  82. REM ############### Help ##################
  83. :showhelp
  84. MODE 80,34
  85. CLS
  86. CALL :message "This script creates a backup of your prefs.js file before doing anything."
  87. ECHO It should be safe, but you can follow these steps if something goes wrong:
  88. ECHO:
  89. CALL :message " 1. Make sure Firefox is closed."
  90. ECHO 2. Delete prefs.js in your profile folder.
  91. CALL :message " 3. Delete Invalidprefs.js if you have one in the same folder."
  92. ECHO 4. Rename or copy your latest backup to prefs.js.
  93. CALL :message " 5. Run Firefox and see if you notice anything wrong with it."
  94. ECHO 6. If you do notice something wrong, especially with your extensions,
  95. CALL :message " and/or with the UI, go to about:support, and restart Firefox with"
  96. ECHO add-ons disabled. Then, restart it again normally, and see if the
  97. CALL :message " problems were solved."
  98. ECHO:
  99. CALL :message "If you are able to identify the cause of your issues, please bring it up"
  100. ECHO on ghacks-user.js GitHub repository.
  101. ECHO:
  102. ECHO:
  103. PAUSE
  104. CLS
  105. GOTO :begin
  106. REM #####################################