prefsCleaner.bat 3.6 KB

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