Home

Awesome

Compare-UserJS


This script parses user.js files and compares them, logging the results to userJS_diff.log.

Information provided by this script:

Additionally, it can catch one type of syntax error (for now), and includes that information in the report.

You can see an example of what the output looks like here.

🔹 Requirements

PowerShell version 2 (or newer) and .NET 3.5 (or newer), both of which come as standard components of Windows 7, but the script also runs fine on Unix-like systems. You can download the latest version of PowerShell and its dependencies from the official PowerShell repository.

🔹 Instructions

Compare-UserJS requires two parameters: the paths of the two files to be compared. You can pass them directly from the console/terminal, but that is not strictly necessary because the script will prompt you to enter them during execution if you don't.

If you're on *nix you can just skip to the examples.

On Windows you can:

  1. Download copies of both Compare-UserJS.bat and Compare-UserJS.ps1.
  2. Place them in the same folder.
  3. Drag and drop the two files that you want to compare on the Compare-UserJS.bat, simultaneously.

The Compare-UserJS.bat works as a launcher that makes it easier to run the PowerShell script. If you don't want to use said batchfile, you will first have to either:

...relax the execution policy:

# pick one or the other
Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy Unrestricted

...or call the script like this:

PowerShell -ExecutionPolicy Bypass -File Compare-UserJS.ps1 <params>

:top:

🔹 Parameters

IndexNameRequired?DefaultDescription
0filePath_AYesPath to the first file to compare. (1)
1filePath_BYesPath to the second file to compare.
2ouputFileNouserJS_diff.logPath to the file where the report will be dumped.
3appendNofalseAppend the report to the end of the file if it already exists.
4noCommentsANofalseParse JS comments in file A as code. (deprecated)
5noCommentsBNofalseParse JS comments in file B as code.
6hideMaskNo0Bitmask value for hiding parts of the report selectively. (2)
7inJSNofalseGet the report written in JavaScript. (3)

<sub><em> 1 - All path parameters can be absolute or relative. <br> 2 - See the embedded help info for details. <br> 3 - It will be written to userJS_diff.js unless the -outputFile parameter is also specified. </em></sub>

:top:

🔹 Examples and tips

See the embedded help info:

Get-Help .\Compare-UserJS -full

Or just read it from the file, but that's less thrilling.

If you encounter any sort of issues with this script in a version of PowerShell higher than v2, try forcing the use of PSv2 like this:

PowerShell -Version 2 -File Compare-UserJS.ps1 <params>
# if you have PowerShell Core, use "pwsh" instead of "PowerShell", like this:
pwsh -Version 2 -File Compare-UserJS.ps1 <params>

Comparing fileA to fileB:

.\Compare-UserJS.ps1 "C:\absolute\path\to\fileA" "..\relative\path\to\fileB"

Comparing fileA.js to fileB.js, and saving the report to report.txt, appending to the end of the file:

.\Compare-UserJS.ps1 "fileA.js" "fileB.js" -outputFile "report.txt" -append

This tool can help you make manual cleanups of your prefs.js too!

.\Compare-UserJS.ps1 prefs.js user.js -hideMask 502 -inJS

Passing any parameters to the BAT is the same, except that you don't need the .\

Compare-UserJS.bat "fileA.js" "fileB.js" -outputFile diff.txt

:top:

🔹 Acknowledgments

Thanks to Thorin-Oakenpants and earthlng for their valuable feedback on the initial stages of this little project.

🔹 Glossary