prefsCleaner.bat 3.6 KB

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