JS (Javascript) function to remove all images and media on web page

Leaving only text and colors on web page

Quite often, I found myself wishing I could clear the web page I'm looking at from all the colorful junk with one click. Whether it was distracting, or drawing attention, or containing things that I thought weren't appropriate and I just needed to read some text, being able to perform a simple action to get rid of all pictures, flash objects, iframes and background images has proven to be quite handy. Of course, there's a myriad of plugins and tools that assist with this problem, but being a developer, I came up with a quick and effective script that accomplishes all that in just one line of code (wrapped it would appear to be around 2-3, depending on where you're viewing it).

To use the script, with the page loaded, just open the console (F12 in Chrome), paste it in there and hit enter. Observe the result. No more flashing GIFs, flash ads, colorful backgrounds and etc. Just the text. The Javascript code is completely self-reliant, as it doesn't use JQuery or any other libraries, meaning that it can be used with any website. Please see the code below. Happy browsing! And feel free to use it in your development projects too.

JS code to remove all images and media on a web page:

(function(){var scan = function(par){var n=par.childNodes,i=n?n.length:0,e,s;while(--i>=0){if((s=(e=n[i]).tagName)&&((s=s.toLowerCase())=='img'||s=='object'||s=='iframe'||s=='embed'))par.removeChild(e);else{if(s&&((typeof(getComputedStyle)!='undefined'?getComputedStyle(e,''):e.currentStyle||{}).backgroundImage||'').indexOf('url') > -1)e.style.background='none';scan(e);}}};scan(document.body.parentNode);})()





Information Error Confirmation required