prefsCleaner.bat 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.0
  6. :begin
  7. ECHO:
  8. ECHO:
  9. ECHO ########################################
  10. ECHO #### prefs.js cleaner for Windows ####
  11. ECHO #### by claustromaniac ####
  12. ECHO #### v2.0 ####
  13. ECHO ########################################
  14. ECHO:
  15. CALL :message "This script should be run from your Firefox profile directory."
  16. ECHO It will remove any entries from prefs.js that also exist in user.js.
  17. CALL :message "This will allow inactive preferences to be reset to their default values."
  18. ECHO This Firefox profile shouldn't be in use during the process.
  19. CALL :message ""
  20. TIMEOUT 1 /nobreak >nul
  21. CHOICE /C SHE /N /M "Start [S] Help [H] Exit [E]"
  22. CLS
  23. IF ERRORLEVEL 3 (EXIT /B)
  24. IF ERRORLEVEL 2 (GOTO :showhelp)
  25. IF NOT EXIST "user.js" (CALL :abort "user.js not found in the current directory." 30)
  26. IF NOT EXIST "prefs.js" (CALL :abort "prefs.js not found in the current directory." 30)
  27. CALL :FFcheck
  28. CALL :message "Backing up prefs.js..."
  29. SET "_time=%time: =0%"
  30. COPY /B /V /Y prefs.js "prefs-backup-%date:/=-%_%_time::=.%.js"
  31. CALL :message "Cleaning prefs.js..."
  32. CALL :cleanup
  33. CLS
  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. (
  67. FOR /F tokens^=2^ delims^=^'^" %%G IN ('FINDSTR /R /C:"^[^\"']*user_pref[ ]*\([ ]*[\"'][^\"']*[\"'][ ]*," user.js') DO (
  68. IF NOT ""=="%%G" (SET "[%%G]=1")
  69. )
  70. FOR /F "tokens=1,* delims=:" %%G IN ('FINDSTR /N "^" prefs.js') DO (
  71. FOR /F tokens^=1^,2^ delims^=^" %%I IN ("%%H") DO (
  72. IF NOT DEFINED [%%J] (
  73. ECHO:%%H
  74. )
  75. )
  76. )
  77. )>tempcleanedprefs
  78. MOVE /Y tempcleanedprefs prefs.js
  79. GOTO :EOF
  80. REM ############### Help ##################
  81. :showhelp
  82. MODE 80,34
  83. CLS
  84. CALL :message "This script creates a backup of your prefs.js file before doing anything."
  85. ECHO It should be safe, but you can follow these steps if something goes wrong:
  86. ECHO:
  87. CALL :message " 1. Make sure Firefox is closed."
  88. ECHO 2. Delete prefs.js in your profile folder.
  89. CALL :message " 3. Delete Invalidprefs.js if you have one in the same folder."
  90. ECHO 4. Rename or copy your latest backup to prefs.js.
  91. CALL :message " 5. Run Firefox and see if you notice anything wrong with it."
  92. ECHO 6. If you do notice something wrong, especially with your extensions,
  93. CALL :message " and/or with the UI, go to about:support, and restart Firefox with"
  94. ECHO add-ons disabled. Then, restart it again normally, and see if the
  95. CALL :message " problems were solved."
  96. ECHO:
  97. CALL :message "If you are able to identify the cause of your issues, please bring it up"
  98. ECHO on ghacks-user.js GitHub repository.
  99. ECHO:
  100. ECHO:
  101. PAUSE
  102. CLS
  103. GOTO :begin
  104. REM #####################################