Autosizer 2, UserJS and cross-domain storage

Back in 2005, I wrote a UserJS named “Autosizer”: that enhances Opera’s behavior when you view a single image. The script from back then has one inherent problem, though; when you set a resize mode, it would be remembered on a per-site basis, instead of as a global option. Which, frankly, sucks, as I usually prefer a preference to be that, just a preference that sticks, whether I am viewing “infinite lolcats”: or “ray tracing examples”:
Enter Autosizer 2, which fixes this, through a hack, which either is really clever, completely insane, or both. First off, “download”: and “install”: the user script. The script is a complete rewrite of the old script, and has been on a severe diet: There are now only two modes: View in original size, or Fit to screen.
h3. The hack: Iframes, error pages, invalid domains and cross-document messaging
The way this works is roughly:
# When an image is loaded, such as the two example images above, the script creates and injects an iframe pointing to — an invalid URL
# Next, the other half of the script activates only on the URL mentioned above, and sets up a few listeners for cross-document messages. It recognizes three settings, one for setting Fit to screen, one for no fit, and one for just retrieving the current setting
# Every 300ms, the iframe will post a message to its parent window, with the current value of the setting.
# The event listeners in the parent window (the image) will, upon getting a message from the iframe set the correct sizing mode.
# The net effect of this is that we now have a cross-domain preference storage for UserJS.
What about security? Well, this is the catch, there is absolutely _no_ security here, so a user script author should never store anything here that is remotely private, nor should an author assume that data stored in this way are not corrupted: A web page can send and retrieve messages in just the same way a user script can.
So, how much data can you store? Well, you have an entire /8 to store cookies on, which is 16 777 216 domains, you can have 30 cookies per domain, of max 4096 bytes each. That is “1.87 terabytes”: Just don’t try. Or if you do, write a virtual filesystem implementation or something that gives you infinite geek points.
Should you want to mess around with the autosizer script, it’s licensed under the New BSD License. Enjoy.

Previous Post


  1. Is there anything special (other than enabling user scripts, etc) I need to do for this to work? Images resize not, for I. 🙁

  2. WOFall

     /  2008-06-17

    Ah, thanks. The previous version i used (the one edited by shoust) had stoped working in 9.5
    It’s a pity about the white frame around the image… hope you can find a work around 🙂

  3. JKing: You’ll need Opera 9.5, I believe. Other than that, it should work straight out of the box.

  4. Note, to alter the sizing behavior, you have to click on the image, loading the raytrace example image I pointed to should show the effect.

  5. Note, to alter the sizing behavior, you have to click on the image, loading the raytrace example image I pointed to should show the effect.

    Ah, that was the missing piece! It now works marvelously! Thank you much, Arve. 🙂

  6. For added fun: Open two images that are both larger than the viewport, side-by-side, either in separate restored tabs or windows, click one of the images, and then observe what happens in the other.

  7. Paulo

     /  2008-06-20

    This doesn’t work with http://www.imagebam.

  8. Thomas Chah

     /  2008-06-24

    Opera is resizing it one the page is fully loaded, unlike Firefox and IE.
    For example here is
    The page shows two images among the texts, but they is displayed in small size.
    Is there a way to load the full-sized image like Firefox and IE?
    I’m using Opera 9.50, and tested in Firefox3 and IE7.

  9. Bernard Bredhauer

     /  2008-06-25

    Hi Arve,
    Would it be possible to add icons to your user.js
    to show the zoomed state of the image such as in IE7
    or Firefox.

  10. Hi Arve!
    I have to agree with WOFall: Autosizer workes wonderful in the previous versions of opera, but since v9.5, your script stopped working!
    Is there a new release of autosizer or can I fix the problem?