#!/usr/bin/perl
use warnings;
use strict;

# 	BBEdit Unix Filter for sending JS to JSLint web site.
# 	Feel free to customize.
# 
# 	2008-08-29
# 	http://pudge.net/
# 
# 	Requires BBEdit 8.0 or higher. To install, copy here:
# 
# 		~/Library/Application Support/BBEdit/Unix Support/Unix Filters/
# 
# 	and relaunch BBEdit, then go to Window -> Palettes -> Unix Filters.
# 	Select text and run the filter.


use Mac::Glue ':all';

my $web = new Mac::Glue 'Safari';
$web->ERRORS(1);

my $url = 'http://www.jslint.com/';

my $js = join '', <>;
print $js; # send back to window
$js =~ s|\\|\\\\|g;
$js =~ s|'|\\'|g;
$js =~ s|\n|\\n|g;



$web->make(new => 'document', with_properties => {
	URL => $url
})->activate;

my $document = $web->obj(document => 1, window => 1);

my $set_js = <<EOT;
document.getElementById('input').value = '$js';
EOT

my $click_js = <<EOT;
document.getElementsByTagName('input')[0].click()
EOT

$web->do_javascript($set_js, in => $document);
$web->do_javascript($click_js, in => $document);

__END__
