Hack #80. Break Out of Frames

Replace a framed document with the biggest single frame.

On some news sites, link collections or weblogs, and even web mail programs, external links are wrapped into a frame. This wastes your precious screen real estate to keep part of the original web site in view, usually with additional advertisements. We can take back control of our browsing experience and use the whole screen instead of wasting it on these framed wrappers.

The Code

This script takes a straightforward approach, which comes in three simple steps. First, via XPath, we find all the <frame> elements. Then, we check the site and location of each frame and save it as if it is the biggest frame so far.

Once the loop has evaluated all <frame> tags, one of two things happens. If we have a URL of the biggest frame recorded, the script redirects to that URL with the location.replace method. If no URL has been recorded because there are no frames on this page, we do nothing. This makes the script safe to include with wide-open wildcards that match an entire domain.

The default list of included pages is simply an example page. There are many legitimately frames-based pages, so a catchall @include * parameter would disrupt too many sites. You will need to manually add pages that you know have wrapped frames.

Save the following user script as frame-killer-plus.user.js:

 // ==UserScript== // @name Frame Killer Plus // @namespace http://www.arantius.com/ // @description Replaces the current page with ...

Get Greasemonkey Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.