Firefox: Get Rid of the Scratchpad Greeting

The Firefox browser has a little tool for JavaScript editing build-in called “scratchpad”. Based on the editor CodeMirror it is a bit better than writing a small HTML file with a textarea and a button to eval() the content but not very much.

The pros are the ability to “fold” code and a some pop-up things like code completion.
The cons are many, the main theme is probably that bugs (including usability issues) get ignored but featuritis is rampant. Another one is the fact that you cannot configure it a lot, actually, only half a dozen things of which only one or two affect everyday work.

Lets start at this nagging little greeting that you get every time you start-up scratchpad: “Enter some JavaScript…” and so on. Try to get rid of it. It is hard. For almost every message you get a box you can check that says something in the line of “Don’t bother me with it again!”, even for things that are more grave but such an introductory text that you do read once, wonder a bit why somebody could get the idea that such information is needed by anyone and than try to get rid of it because it steals space, is useless, needs three keypresses to delete which causes a message to pop-up that you have unsaved changes when you open a file.

Oh, and it cannot even memorize the font-size, so if you are as blind as I am and have the same fonts installed you need to press ctrl++ five times to get a readable size. Changing that is also complicated.

Now, lets take the font-size first because it is more nagging for me than the intro-thing. If you load the Firefox configure file with about:config and search for “scratchpad” you will only a couple of entries. One of them is devtools.scratchpad.enableAutocompletion which switches auto-completion on (if set to true) and off (if set to false). You can also enable/disable code folding and set the size of the list of last opened files. There is also an entry devtools.scratchpad.showTrailingSpace which shows you places where tools like eslint raise their voices to complain bitterly (switch that warning of with eslint -rule "no-trailing-spaces:0"); the usefulness of such an option is questionable at least.

For the problem of font-size: you can put some CSS rules into the file userChrome.css in the directory chrome. What, you have none of these you say? Well, you have to make it yourself, the file and the directory. The directory comes into your profile folder. The profile folder is a directory in your home directory in the mozilla directory tree under a directory calledfirefox. There should be one or more directories with some curious numbers and letters and the word default in it. One of these is your profile directory. if you have many there, for what reason ever, make a bookmark that you can find easily with your prefered text-in-file-finder. Go there, make a directory called chrome and go there and make a file called userChrome.css. In this file put the following text:

.CodeMirror,
.CodeMirror pre {
    font-family:    monospace;
    font-size:      11pt !important;
}

Change font-size and font-family to your liking. You need to restart your browser to make the changes available.
The file userChrome.css is a simple CSS file, you can do everything CSS-3 allows plus some extra functions. Googling for userChrome.css gives a lot of examples.

The case of the intro is much harder.
Some functions and most configurations are put in the three omni.ja files in the installation directory of Firefox. One is in firefox/omni.ja, one in firefox/browser/omni.ja and one in
firefox/webapprt/omni.ja. The last one if for WebRT, the first and the second one have the interesting meat inside. The configuring stuff is in files with the ending .properties. But you don’t see any files? Well, the omni.ja files are zip’ed. Most ZIP-tools can unzip these, some cannot. The free (The GNU-folks might protest here but for all others it is sufficiently free) ZIP-tool from Info-ZIP (quite outdated, please use the installer of your distribution to get a more recent or at least bugfixed version) is one of these and is also used here.

Lets start with getting rid of the useless intro-text at the start-up of the scratchpad.
List the files in the omni.ja packages and look for files with scratchpad in it (I have mine installed in /opt, but YYMV, of course):

unzip -l /opt/firefox/omni.ja | grep scratchpad

You will, most probably get an error like

warning [/opt/firefox/omni.js]:  11311983 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error [/opt/firefox/omni.ja]:  reported length of central directory is
  -11311983 bytes too long (Atari STZip zipfile?  J.H.Holm ZIPSPLIT 1.1
  zipfile?).  Compensating..

You can ignore it. The file uses a slightly different package format. The original zip fomart starts with the two characters 0x50, 0x4b (“PK”) the format used by the Mozilla developers use the characters 0xc3, 0x3e to flag the format used. See for example the short, very short oversight at MDN. Funny sidenote: the options listed for zip build a package flagged with “PK”. It works, so one wonders…

But on with the theme: Now that you have found nothing in that file but a lot in the other one at firefox/browser/omni.ja, choose a directory somewhere and… no, wait: make some backups first!
Phew…so, where have I been…uh, I see…unpack omni.ja into that directory:

unzip -d THE_DIRECTORY_CHOOSEN omni.ja

Look into the two files named
chrome/en-US/locale/browser/devtools/scratchpad.properties (or another language instead of en-US) and
chrome/browser/content/browser/devtools/scratchpad.js. The first one has the localizations for the texts in it. Search for the text in your language that is printed at the start-up of the scratchpad. The name of the variable should be scratchpadInfo1 (the version of firefox I am testing on is 34.0.5). Now search for this name in the second file. If you found it there, too, we can go on.

We have a couple of alternatives here:

  • change the JavaScript in the second file
  • delete the content of the variable scratchpadInfo1
  • Make a new, empty variable

I have chosen the last alternative, it is the cleaner and most importantly, much simpler variant.

So, at the beginning of the file chrome/en-US/locale/browser/devtools/scratchpad.properties write

scratchpadEmpty=

On two lines, the second line being empty.
In the second file chrome/browser/content/browser/devtools/scratchpad.js change the name of the variable from scratchpadIntro1 to scratchpadEmpty.

Pack a new omni.ja.

rm omni.ja && zip -qr9XD omni.ja ./*

The explanation for the options used for zip:

  • q quiet mode
  • r recursive
  • 9 maximum compression
  • X no extra file attributes
  • D no directory entries

Copy the newly made omni.ja to where it came from.
Restart browser.
Open scratchpad.
See intro again.
You may utter an expletive or two now. That’s what I did 😉

The problem is the caching of JavaScript. A good thing normally because you don’t want firefox to parse and compile e.g.: jquery.js everytime it sees it but more importantly: a lot of the XUL-handling (XUL is the GUI for Mozilla apps like Firefox) gets done by JavaScript and gets cached, too. To empty the JavaScript cache Firefox has the option -purgecache. If you do not know how to start Firefox from command line (especially on Windows but not only there)

On most Linux distributions:

/usr/bin/firefox -purgecache

Or

/usr/local/bin/firefox -purgecache

On 32-Bit Windows (Start -> Run means: Choose “Run” from the “Start” menu. If you have one. A start-menu I mean)

Start -> Run -> "%ProgramFiles%\Mozilla Firefox\firefox.exe" -purgecache

On 64-bit Windows

Start -> Run -> "%ProgramFiles(x86)%\Mozilla Firefox\firefox.exe" -purgecache

The same difference for 64-bit systems applies for the Mac-OS, too:
For Leopard 10.6 and higher

/Applications/Firefox.app/Contents/MacOS/firefox-bin -purgecache

For older Mac-OSes (needs to be told to use the 32-bit part of the binary explicitly)

arch -arch i386 /Applications/Firefox.app/Contents/MacOS/firefox-bin -purgecache

The underlying editor CodeMirror is also the base of what is called an experimental IDE: LightTable. I think I’ll take a look.
It’s building now, that’ll take a while 😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s