user.js

mirror of https://github.com/arkenfox/user.js
Log | Files | Refs | README

prefsCleaner.bat (4158B)


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