Skip to content

Instantly share code, notes, and snippets.

@agate
Created September 22, 2009 11:27
Show Gist options
  • Save agate/190990 to your computer and use it in GitHub Desktop.
Save agate/190990 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'open-uri'
require 'base64'
url = 'http://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt'
list_txt = Base64.decode64(open(url).read)
list = list_txt.split("\n").reject do |item|
item.start_with?('@@') ||
item.start_with?('!') ||
item.start_with?('|') ||
item.start_with?('[') ||
item.empty?
end
script_list = list.collect do |item|
%{shExpMatch(url, "*#{item}*")}
end
pac = %{function FindProxyForURL(url, host) {
if (#{script_list.join(" ||\n ")}
) {
return "PROXY #{$*[0]}";
} else {
return "DIRECT";
}
}}
File.open('gfwlist.pac', 'w') do |f|
f << pac
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment