JavaScript Code to Get a List of Firefox XPI Files
Whenever you install an add-on in Firefox, the browser downloads an XPI file and stores it in your Firefox profile directory. These files consist of images, JavaScript and other elements needed to make your add-on work. If you would like to view a list of those files quickly, create a Windows Script Host program that builds a list using JavaScript. You can then run the file any time you like by double-clicking it.
-
Firefox XPI Files
-
You don't have to click "Install" on Firefox's Add-ons page to install a new add-on. Drag an XPI file from your desktop or any folder onto a Firefox Web page, and the browser installs it automatically after asking if you wish to install the add-on. XPI files are compressed and you cannot view them in a text editor. However, you can use a program such as WinRAR or 7-ZIP to extract their contents. Examine your XPI files by finding your Firefox profile folder and locating the Extensions file within that folder.
Windows Scripting Host and JavaScript
-
To build a list of files that reside in a folder such as Extensions, you must have authorization to do so. JavaScript running in a browser cannot access files on a hard drive. However, it can read and write files when you place it inside a Windows Script Host program. WSH allows anyone to use VBScript or JavaScript to create useful applications that automate Windows tasks. Begin creating a script that reads XPI files by creating a WSH shell object, a file system object and a folder object as shown below.
var xpiFolderName = " ";
var shell = WScript.CreateObject ("WScript.Shell");
var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
var folderObject = fileSystemObject.GetFolder(xpiFolderName);The xpiFolderName variable holds the full path name of your Firefox Extensions folder.
-
Finding Your Extensions Folder
-
Your Firefox profile folder name contains the Firefox user name you create or the browser creates by default if you do not specify one. Finding this folder may be difficult if you have no idea where Firefox stores its system files. You can discover its name by opening Firefox, clicking "Help," and then clicking "Troubleshooting Information." Click "Open Containing Folder," and Windows Explorer displays the contents of your profile folder. If you double-click the Extensions folder located in that folder, Windows Explorer displays the full path name to that folder. Right-click that name, select "Copy" to copy that name, and paste it between the quotes in the assignment statement shown below:
var xpiFolderName = " ";
Finishing the Code
-
Now that you have a folder object named folderObject, you simply need to iterate through that folder and write the names of its XPI files to another file as shown below:
var xpiFiles = folderObject.Files;
var looper = new Enumerator(xpiFiles);var outputObject = fileSystemObject.OpenTextFile("outputFile", 8, true);
for (; !looper.atEnd(); looper.moveNext())
{
outputObject.WriteLine(looper.item() + "\n");
}The looper object holds the list of XPI file names, and the outputObject holds a reference to the output file where you will write the list. Replace "outputFile" with the name of the file you wish to hold your list of XPI list. The "for" loop iterates through the files in the looper object and writes them to that file. You can then save the file with a .js extension, double-click it and run the program. It will store the names of all your XPI files in your output file.
-