#!/usr/bin/perl
# This perl script provides filtering for undesireable garbage in HTML files
# It is intended to be used as an external parser for MiddleMan

while ( <STDIN> ) {
   chomp;
   $PAGE .= $_;
   $PAGE .= "\n";
}

# Remove popups
# Note: alot of sites won't load with these enabled
# $PAGE =~ s/window\.open\s*\(/concat(/ig;
# $PAGE =~ s/([ =;])open\s*\(/$1concat(/ig;
# $PAGE =~ s/target=['"]?(_blank|_new)['"]?/notarget/ig;

# HTML Cookies
$PAGE =~ s/<meta\s+http-equiv=['"]?set-cookie['"]?\s+content=[^>].*>//ig;

# Don't let sites change status bar
$PAGE =~ s/window\.status\s*=/uselessness =/ig;

# Make sure popup's are resizeable and have scroll bar's
$PAGE =~ s/(<a\s+href[^>]+)resizable=['"]?(no|0|false)['"]?(.*>)/$1resizable="1"$3/ig;
$PAGE =~ s/(<a\s+href[^>]+)location=['"]?(no|0)['"]?(.*>)/$1location="1"$3/ig;
$PAGE =~ s/(<a\s+href[^>]+)status=['"]?(no|0)['"]?(.*>)/$1status="1"$3/ig;
$PAGE =~ s/(<a\s+href[^>]+)scrolling=['"]?(no|0|auto)['"]?(.*>)/$1scrolling="no"$3/ig;
$PAGE =~ s/(<a\s+href[^>]+)menubar=['"]?(no|0)['"]?(.*>)/$1menubar="1"$3/ig;

print $PAGE;
