Skip navigation.

Prepare!

Lee Harvey's Zombie Hit Parade

UserJS to Hide Filtered Elements

, , , ,

Do you use Opera's filter.ini feature, or a HOSTS file to block certain content? Do you hate to see web pages rendered with large amounts of unused white-space when your filtering works? If so, then these pair of scripts may help.

As mentioned in my previous post, I use Opera's filter.ini feature. Because of this, Opera effectively blocks many third-party images, iframes, and JavaScripts. Effectively, this often results in large rectangular regions of unused white-space on websites that host advertisements. To compensate for this, I have developed a pair of User JS files that hide non-loaded images and iframes...


Download/view imgload.js
document.addEventListener("load",
        function(e) {
                var imgs = document.images;
                for (var i = 0, o; o = imgs[ i ]; i++) {
                        if (!o.complete) o.style.display = "none";
                }
        }, false);

-and-

Download/view iframeload.js
document.addEventListener("load",
        function(e) {
                var ifrms = document.getElementsByTagName("iframe");
                for (var i = 0, f; f = ifrms[ i ]; i++) {
                        // if (!f.location) f.style.display = "none"; // Version 1.0
                        if (!f.src) f.style.display = "none"; // Version 1.1
                }
        }, false);

As an added bonus to webpage readability, these scripts can also improve mouse gesture usability -- which don't work so well over blank/filtered-out inline frame elements.

Enjoy.

Update 2009/12/07 - Changed f.location to f.src in iframeload.js

My filter.ini entriesUserJS for MegaMillions.com

Comments

dapxin 3. March 2009, 06:33

hope this doesn't add unnecessary load to page rendering ?

Lee Harvey 3. March 2009, 13:20

Nope.

Of course, if you visit a page that contains a ton of non-loadable images, then you're going to wait a very long time for the document.load event to kick-in (after the page has loaded) anyhow. Meaning: These scripts don't run until /after/ the page has loaded. They then filter-out (hide) any non-displayed images and silly inline frames with no location specified.

dapxin 3. March 2009, 18:05

Tx. I will keep it alive then :smile:

J 27. April 2009, 16:27

Nice idea.

Brent B. Powers 21. October 2009, 19:29

It's taken quite a while, but I've tracked down at least one problem with Opera 10 and either iGoogle or eBay, at least. For some reason, in some circumstances, this js blocks gmail and google calendar widgets, or (on eBay), the description frame.

Unfrotunately, my java script fu is weak, at best, but I'll let you know if I find anything else...

dapxin 30. October 2009, 23:47

Causes a couple of problems I have noticed
e.g http://tinypaste.com/261fe14

How can this be stopped?

dapxin 18. November 2009, 10:13

Hello ! :smile:

dapxin 18. November 2009, 10:24

well, after a little thinking, I fixed it by adding

// @exclude http://*tinypaste.com/*

To the header files. nice.

Lee Harvey 7. December 2009, 13:32

I confirmed an issue with iframeload.js In essence, the old frame.location object reference no longer seems to be valid (Opera security fix?). Anyhow, I have changed it to frame.src, but this may have other side-effects. If you run into any sites where the new code misbehaves, please let me know. I'll run with this new version for now, and will keep you posted if I run into any, as well.

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.