#!/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 show hide onChange selectItem options); my %var = (); my @names = 'a'..'ba'; local $/ = undef; open FD, "hinter.js"; open OFD, "| yui-compressor --type js -o $output"; while() { 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; $_ = ; seek FD, 0, 0; print FD "// (c) Vitaliy Filippov 2011-2015 // \@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";