prefsCleaner.bat 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.1
  6. :begin
  7. ECHO:
  8. ECHO:
  9. ECHO ########################################
  10. ECHO #### prefs.js cleaner for Windows ####
  11. ECHO #### by claustromaniac ####
  12. ECHO #### v2.1 ####
  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. CALL :message "All done!"
  34. TIMEOUT 5 >nul
  35. ENDLOCAL
  36. EXIT /B
  37. REM ########## Abort Function ###########
  38. :abort
  39. CALL :message %1
  40. TIMEOUT %~2 >nul
  41. EXIT
  42. REM ########## Message Function #########
  43. :message
  44. ECHO:
  45. ECHO: %~1
  46. ECHO:
  47. GOTO :EOF
  48. REM ####### Firefox Check Function ######
  49. :FFcheck
  50. TASKLIST /FI "IMAGENAME eq firefox.exe" 2>NUL | FIND /I /N "firefox.exe">NUL
  51. IF NOT ERRORLEVEL 1 (
  52. CLS
  53. CALL :message "Firefox is still running."
  54. ECHO If you're not currently using this profile you can continue, otherwise
  55. CALL :message "close Firefox first!"
  56. ECHO:
  57. PAUSE
  58. CLS
  59. CALL :message "Resuming..."
  60. TIMEOUT 5 /nobreak >nul
  61. )
  62. GOTO :EOF
  63. REM ######### Cleanup Function ##########
  64. :cleanup
  65. FOR /F tokens^=2^ delims^=^'^" %%G IN ('FINDSTR /R /C:"^[^\"']*user_pref[ ]*\([ ]*[\"'][^\"']*[\"'][ ]*," user.js') DO (
  66. IF NOT ""=="%%G" (SET "[%%G]=1")
  67. )
  68. (
  69. FOR /F "tokens=1,* delims=:" %%G IN ('FINDSTR /N "^" prefs.js') DO (
  70. IF ""=="%%H" (
  71. ECHO:
  72. ) ELSE (
  73. FOR /F tokens^=1^,2^ delims^=^"^' %%I IN ("%%H") DO (
  74. IF NOT DEFINED [%%J] (ECHO:%%H)
  75. )
  76. )
  77. )
  78. )>tempcleanedprefs
  79. MOVE /Y tempcleanedprefs prefs.js
  80. GOTO :EOF
  81. REM ############### Help ##################
  82. :showhelp
  83. MODE 80,34
  84. CLS
  85. CALL :message "This script creates a backup of your prefs.js file before doing anything."
  86. ECHO It should be safe, but you can follow these steps if something goes wrong:
  87. ECHO:
  88. CALL :message " 1. Make sure Firefox is closed."
  89. ECHO 2. Delete prefs.js in your profile folder.
  90. CALL :message " 3. Delete Invalidprefs.js if you have one in the same folder."
  91. ECHO 4. Rename or copy your latest backup to prefs.js.
  92. CALL :message " 5. Run Firefox and see if you notice anything wrong with it."
  93. ECHO 6. If you do notice something wrong, especially with your extensions,
  94. CALL :message " and/or with the UI, go to about:support, and restart Firefox with"
  95. ECHO add-ons disabled. Then, restart it again normally, and see if the
  96. CALL :message " problems were solved."
  97. ECHO:
  98. CALL :message "If you are able to identify the cause of your issues, please bring it up"
  99. ECHO on ghacks-user.js GitHub repository.
  100. ECHO:
  101. ECHO:
  102. PAUSE
  103. CLS
  104. GOTO :begin
  105. REM #####################################