topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 3:16 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: How I fought Firefox and won  (Read 14587 times)

tranglos

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,081
    • View Profile
    • Donate to Member
How I fought Firefox and won
« on: January 29, 2012, 03:04 PM »
I held out as long as I could, but when every other site tells you your browser is outdated, it's time to give up and move on. So I switched, very recently, from Firefox 3.6 to 9. And well, you know what happened next :-)

Sure, I expected problems with extensions, but not to the point where just lying to Firefox about the extension's version compatibility would no longer work. It no longer works. Something changed dramatically in how Firefox handles menus and toolbars, so each and every extension that added a menu item or a toolbar button is now dead. Completely.

Now, this isn't going to help everyone, but perhaps some DC readers will find it useful. I can give up on a lot, but there are several extensions and modifications that I absolutely cannot live without. They are:

  • "Paste and go" in the address bar and "Paste and search" in the search bar.
  • A Save button on the toolbar for File -> Save Page As command.
  • A context menu command to copy current page title, selection (if any) and address to clipboard.
  • A modification of how Firefox saves pages to disk: (a) use page title instead of the document filename, which is usually "index.php" or something equally useless, and (b) use the selected text, if any, as filename.

For all that I had relied on a bunch of extensions and self-made modifications that I had always been able to carry over from one FF release to another. Until now. With FF 9, I've had to re-do them all from scratch or find alternative solutions. Here's how I did that, FWIW.

(a) "Paste and go" in the address bar and "Paste and search" in the search bar.

This one was easy. The "Paste and go" extension is no longer supported, but its functionality has finally been added to the Firefox core. No doubt it was because Google Chrome had thought of it earlier; the FF developers had never figured out by themselves that the #1 reason to paste anything in the address bar... better late than never! IE still doesn't get that.

(b) A Save button on the toolbar for File -> Save Page As command.

This one required some work, but was easy. The old way no longer seems to work. Happily, there is a new extension that's even better: Custom Buttons. This one lets you create buttons inside the browser, and it is not limited to a predefined set of functions. Instead, you can assign any JavaScript code to a button you create - from a single FF function to a script of any complexity. You can pick your own button image as well, of course, and set a few other options. I'm not all that conversant with Firefox's internals, but the extension home has a detailed FAQs and a user forum if you need help. So after some looking stuff up and tweaking the code, I ended up with a button definition that looks like this:

ff_save_btn_def.png

...and a Save button on the bookmarks toolbar:

ff_save_btn.png

Done!

(c) A context menu command to copy current page title, selection (if any) and address to clipboard.

This one took some more work. Previously, I had used an extension called CopyUrlPlus. It would add a submenu to FF context menu, with commands like "Copy Title and URL", "Copy Title, Selection and URL", etc. Exactly what I needed. There were not many options, but you could tweak the extension's JavaScript code to add your own related commands or modify their behavior. This one is of huge importance to me, because I run my old, creaky bookmark manager set to capture URLs with titles from clipboard, and I use it to archive almost everything I ever read or want to read later. Well, the extension no longer works at all, as the mechanism for adding commands to the context menu in FF has changed. I suppose I could learn that part and update the extension, but instead I went looking for a newer equivalent.

I found it in QuoteURLText. It does almost the same as CopyUrlPlus used to do, but "almost" makes a big difference in this case. It would only copy current selection and page URL; and if there were no selection, it would do nothing at all. Plus, it would add "field" names before each line, such as "Address: " or "Source:". I don't want that, because it breaks the URL and title recognition in my app. So, JavaScript time again!

I did a horrible hack with that. It was already late and I wanted to get the results I needed as quickly
as I could. I ripped out some prefs I do not need, such as copying with HTML formatting, and changed the code around to suit my purpose.  Instead of two or three separate commands I now have only one. If some text is selected, the extension copies the selection and the URL. If no selection is present, it copies page title and the URL. It does not copy all three, but with some more tweaking it is certainly possible.

I won't post my code here, because I'm not even sure if QuoteText license would permit that, but if anyone wants my modifications, just PM me.

(d) A modification of how Firefox saves pages to disk: (a) use page title instead of the document filename, and (b) use the selected text, if any, as filename.

I really cannot understand why FF does not do it already. It actually contains code that does at least (a), but for some reason that code is never used. As a result, FF saves pages with unhelpful filenames.

Alas, no extension ever did that part, and I don't think it even could. To get what I want, I've always had to hack Firefox's internal JavaScript. Under FF installation folder there used to be a file called toolkit.jar. A .jar file is just a .zip file with a different extension, so it can be easily browsed. Inside it, there's a piece of JavaScript called "contentAreaUtils.js", and in it there is a function named "getDefaultFileName()", which does what it says: generates a filename Firefox uses when you click File -> Save Page As. I have a snippet of JavaScript code that I would simply put on top of that function, copy the .js file back into toolkit.jar and that did the trick.

So I had a near breakdown when I saw the latest FF does not even come with a "toolkit.jar" :-) After some digging, it turns out that several .jar files have been merged into one, now called appropriately "omni.jar". And sure enough, contentAreaUtils.js is inside it, under "chrome\toolkit\content\global". It still contains the getDefaultFileName() function, but its parameters have changed and its code is now different, but never mind. The old trick still works. Put the following on top of that function, and Firefox will instantly become much smarter when saving files:

Code: Javascript [Select]
  1. if (aDocument) {
  2.     // use selection, if any
  3.     var mjSelText = aDocument.getSelection();
  4.     mjSelText = mjSelText.replace(/(\n|\r)+/g, " ");
  5.     mjSelText = validateFileName(mjSelText).replace(/^\s+|\s+$/g, "");
  6.     mjSelText = mjSelText.replace(/ +/g, " " );
  7.     if (mjSelText != "") {
  8.       return mjSelText;
  9.     }
  10.  
  11.     var docTitle = validateFileName(aDocument.title).replace(/^\s+|\s+$/g, "");
  12.     if (docTitle != "") {
  13.       // Use the document title
  14.       return docTitle;
  15.     }
  16.   }

First, it checks whether any text is selected, and if so, it replaces any illegal characters with spaces and returns the result. Second, if no selection, it does the same with the page title. If neither works, it gives up and Firefox takes over with its own code. Later on Firefox actually checks for docTitle and uses it, but for some reason the function always returns earlier, so that code never runs. I just put it on top of the function instead, preceded only by the check for selection.

Of course Windows will complain badly when you try to replace "omni.jar" under Program Files with your own, but eventually you'll get your way.

And it's all good now.

« Last Edit: January 29, 2012, 04:32 PM by tranglos »

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #1 on: January 29, 2012, 04:13 PM »
Great info, tranglos. Thanks for sharing this.

tranglos

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,081
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #2 on: January 29, 2012, 04:31 PM »
BTW, there's one really annoying thing when you are modifying the JavaScript code of an extension. It used to be that you could edit the code, re-package the .js file into the .xpi extension file and restart the browser to test your changes. Not any more. Firefox 9 detects that an extension has been modified and simply blocks it. There's no special error message, either. FF just claims the extension is incompatible with it, which is misleading and may send you looking for bugs in your extension code that just aren't there.

So, to see if your code works, you have to uninstall the extension first, then manually re-install it after every change. That includes the wait countdown every time. Security, I know, but it makes little tweaks like mine quite aggravating.

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,566
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #3 on: January 30, 2012, 02:42 PM »
Please test CoLT (Copy Link Text), to replace "c)"  It also supports right-clicking on the page and copying page title & URL, etcetera. It even comes localized for 22 languages.
 :up:
http://www.borngeek.com/firefox/colt/
https://addons.mozil.../firefox/addon/colt/

How I fought Firefox and won - DonationCoder.com
-CoLT

tranglos

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,081
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #4 on: January 30, 2012, 03:21 PM »
Please test CoLT (Copy Link Text), to replace "c)"  It also supports right-clicking on the page and copying page title & URL, etcetera. It even comes localized for 22 languages.
 :up:
http://www.borngeek.com/firefox/colt/
https://addons.mozil.../firefox/addon/colt/

Awe-some, thanks! The great thing is that I can create my own copy formats *and* menu commands right in the extension's UI. This one is better that CopyURL+, and miles better than hacking JavaScript.


Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,566
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #5 on: January 30, 2012, 04:56 PM »
Also, the addon with the very long name Mozilla Archive Format, with MHT and Faithful Save, has a "title save", but I no longer remember "pro & cons".

Title Save is an optional feature that changes the default behavior of the browser, suggesting the document's title in place of the remote file name when saving.

http://maf.mozdev.org/
https://addons.mozil...zilla-archive-format


This extension enhances the way web pages are saved on your computer.

It provides the following advantages over the built-in save system:
— A complete page can be saved as a single file (web archive)
— You can name files using the title of the page (title save)
— The saved pages are faithful to the original (exact save)

You can view and save MHT (MHTML) files, with excellent compatibility with Internet Explorer;
but more importantly, you can use the MAFF file format, with the following advantages:
— Save disk space, since MAFF files are compressed
— Include video and audio embedded in the pages
— Be universal, since MAFF is based on ZIP and compatible with Linux and other platforms
— Use an open format, with no risk of vendor lock-in

The MAFF format is exceptional when combined with the built-in browser support for the Ogg Vorbis and Ogg Theora media formats in web pages: you can save everything in a single file. You can even save more than one tab in a single MAFF file.
-MAF

Thinking about it, I am going to re-install this one right now!

Edited:

Thank you for installing Mozilla Archive Format!
     
            Many features of Firefox have been improved by this add-on.
            Web pages are saved more accurately, what you see is what you get.
            You can save one or more tabs in a single file (web archive).
            The title of the document is now the default file name.
            You can save HTML5 video and audio, and more!
         
          You can control which features are enabled from the extension's options.
-Welcome!
« Last Edit: January 30, 2012, 05:13 PM by Curt, Reason: quotes »

40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,859
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #6 on: January 30, 2012, 06:14 PM »
I won't post my code here, because I'm not even sure if QuoteText license would permit that, but if anyone wants my modifications, just PM me.

It should be cool to do that. It's released under the Mozilla Public License V1.1:

2.2. Contributor Grant.

Subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license

 A)   under intellectual property rights (other than patent or trademark) Licensable by Contributor, to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof) either on an unmodified basis, with other Modifications, as Covered Code and/or as part of a Larger Work; and
.
.
.

If you distribute a packaged version of the modified add-on, the distribution obligations in section 3 may also apply. But it's mostly about requiring you make your source code available. If you're just posting source code hacks, then you should be covered even though the obligation doesn't really apply.

 :)


app103

  • That scary taskbar girl
  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 5,885
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #7 on: January 31, 2012, 06:40 AM »
Happily, there is a new extension that's even better: Custom Buttons.

THANK YOU!  :-*

I have been a user of CB2 for a long time and didn't know that my existing buttons from that were compatible with the original extension. I installed the original and disabled CB2, restarted my browser and didn't have to recreate my buttons. They were all still there and working.  :Thmbsup:

I also did not know that the original extension was still in development. CB2 is not and was one of the many reasons why I have resisted upgrading.

Would you happen to know if button sharing is supported in the original? I have code saved as a local .html file, for one-click installation of the buttons, which serves as a backup for my button code and I have resisted publishing it on my website due to the CB2 extension not working with newer versions of Firefox and no hope of being updated. (last update was Sept. 2009)

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,566
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #8 on: January 31, 2012, 11:47 AM »
-this Custom Buttons site is too weird for me - I don't understand what it is; No files, no descriptions. Nothing. I will stay with Custom Toolbar Buttons; they should be outdated, but mine are working fine.

http://codefisher.or...toolbar_button_maker

dainamadona

  • Participant
  • Joined in 2012
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #9 on: January 31, 2012, 12:29 PM »
BTW, there's one really annoying thing when you are modifying the JavaScript code of an extension. It used to be that you could edit the code, re-package the .js file into the .xpi extension file and restart the browser to test your changes. Not any more. Firefox 9 detects that an extension has been modified and simply blocks it. There's no special error message, either. FF just claims the extension is incompatible with it, which is misleading and may send you looking for bugs in your extension code that just aren't there.

So, to see if your code works, you have to uninstall the extension first, then manually re-install it after every change. That includes the wait countdown every time. Security, I know, but it makes little tweaks like mine quite aggravating.

tranglos

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,081
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #10 on: January 31, 2012, 01:38 PM »
-this Custom Buttons site is too weird for me - I don't understand what it is; No files, no descriptions. Nothing.

I agree, it's not friendly at all, but it's there. Click "Installation" on top, you'll see a list of releases. Click a link to install or right-click and save the xpi file to disk.

For some reason the xpi says it's compatible only up to FF 7, but after saving the xpi file locally I could install it in FF 9.0.1 without even modifying the compatibility info in the extenion's install.rdf file.

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,566
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #11 on: January 31, 2012, 01:43 PM »
-thanks, tranglos.
But still, "fixed this and fixed that", but what do the addon do?


tranglos

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,081
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #12 on: January 31, 2012, 01:45 PM »
Also, the addon with the very long name Mozilla Archive Format, with MHT and Faithful Save, has a "title save", but I no longer remember "pro & cons".

Thanks, Curt! I remember having seen it before. Does it save mht format only, or can it saves as plain html as well?  I don't want mht, because it takes much more space, isn't as easily searchable and may not be viewable in Firefox or Chrome (it wasn't before; don't know about now. I need the files saved as plain html without any of the additional baggage.

And the ability to use selected text as title is also quite useful, because plenty of blogs and even news magazines still do not put article titles in the html title tags, so each article would be saved as "Someone's blog.html". Instead, I just select the actual title, press Ctrl+S and am done.

tranglos

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,081
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #13 on: January 31, 2012, 01:46 PM »
-thanks, tranglos.
But still, "fixed this and fixed that", but what do the addon do?

That's on the "Home" page:

The custombuttons extension gives a possibility to create custom toolbarbuttons.

daddydave

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 867
  • test
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #14 on: February 04, 2012, 11:07 AM »
Like the custom configuration stuff!  :Thmbsup: Nice to know about Custom Buttons. Seems like its usefulness overlaps with an extension I recently discovered called PrefBar, so now I am curious to install it to compare the two.

Innuendo

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 2,266
    • View Profile
    • Donate to Member
Re: How I fought Firefox and won
« Reply #15 on: February 06, 2012, 01:32 PM »
Tranglos upgraded to Firefox 9? So that's why Firefox 10 was then released. ;)

On a more serious note, Firefox 10 marks the start of a new era where addons/extensions are not automatically disabled just because the browser version does not automatically match an arbitrary number in an .rdf file. Hopefully, this is the first step on the road to putting threads like this behind us.