32 lines
793 B
Perl
32 lines
793 B
Perl
|
#!/usr/bin/perl
|
||
|
# Mangle names in SimpleAutocomplete code for better compression
|
||
|
|
||
|
use strict;
|
||
|
|
||
|
my $output = 'hinter.min.js';
|
||
|
my %whitelist = map { $_ => 1 } qw(input remove replaceItems hide onChange);
|
||
|
my %var = ();
|
||
|
my @names = 'a'..'ba';
|
||
|
|
||
|
local $/ = undef;
|
||
|
open FD, "hinter.js";
|
||
|
open OFD, "| yui-compressor --type js -o $output";
|
||
|
while(<FD>)
|
||
|
{
|
||
|
s/(this|self|SimpleAutocomplete(?:\.prototype)?)\.([a-zA-Z0-9_]+)/$1 . '.' . ($whitelist{$2} ? $2 : ($var{$2} ||= shift @names))/egs;
|
||
|
print OFD $_;
|
||
|
}
|
||
|
close FD;
|
||
|
close OFD;
|
||
|
|
||
|
open FD, "+<", $output;
|
||
|
$_ = <FD>;
|
||
|
seek FD, 0, 0;
|
||
|
print FD "// (c) Vitaliy Filippov 2011-2013
|
||
|
// \@license MPL 2.0 http://www.mozilla.org/MPL/2.0/
|
||
|
// http://yourcmc.ru/wiki/SimpleAutocomplete
|
||
|
$_";
|
||
|
close FD;
|
||
|
|
||
|
print "Compressed SimpleAutocomplete written to $output\n";
|