Advertisement
adamchilcott

adblock2polipo.rb

Oct 13th, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.19 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. # convert adblock ruleset into polipo-forbidden format
  4.  
  5. if __FILE__ == $0
  6.  
  7.     if ARGV.length == 0
  8.         exit("Usage: #{File.basename($0)} <adblockrules>")
  9.     end
  10.  
  11.     if not File.exist?(ARGV[0])
  12.         exit("The rules file (#{ARGV[0]}) doesn't exist")
  13.     end
  14.  
  15.     dollar_re = Regexp.new(/(.*?)\$.*/)
  16.  
  17.     File.readlines(ARGV[0]).each {
  18.         | line |
  19.         unless line.empty?
  20.             if (["[", "!", "~", "#", "@"].include?(line[0]) or
  21.                 line[0, 8] == "/adverti" or
  22.                 line.include?("##"))
  23.                 next
  24.             end
  25.             line = line.gsub(dollar_re, "\\1")
  26. #           line = line.gsub("|http://", "")
  27.             line = line.gsub("|", "")
  28.             line = line.gsub("||", "")
  29.             line = line.gsub(".", "\\.")
  30.             line = line.gsub("*", ".*")
  31.             line = line.gsub("?", "\\?")
  32.             line = line.gsub("^", "[\\/:\\.=&\\?\\\\+\\-\\ ]+")
  33. #           line = line.gsub("&", "\\&")
  34. #           line = line.gsub("+", "\\+")
  35. #           line = line.gsub("-", "\\-")
  36. #           line = line.gsub(";", "\\;")
  37. #           line = line.gsub("=", "\\=")
  38. #           line = line.gsub("/", "\\/")
  39.             puts(line.strip)
  40.         end
  41.     }
  42.     puts("")
  43.  
  44. end
  45.  
  46. #############
  47. # START NOTES
  48. #############
  49.  
  50. ## Reference:
  51. ## <https://sites.google.com/site/monkeesage/files/>
  52.  
  53. ###########
  54. # END NOTES
  55. ###########
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement