adamchilcott icon

adblock2polipo.rb

adamchilcott | PRO | 10/14/18 03:38:06 AM UTC | 0 ⭐ | 7232 👁️ | Never ⏰ | []
Ruby |

1.19 KB

|

None

|

0 👍

/

0 👎

#!/usr/bin/ruby
 
# convert adblock ruleset into polipo-forbidden format
 
if __FILE__ == $0
 
    if ARGV.length == 0
        exit("Usage: #{File.basename($0)} <adblockrules>")
    end
 
    if not File.exist?(ARGV[0])
        exit("The rules file (#{ARGV[0]}) doesn't exist")
    end
 
    dollar_re = Regexp.new(/(.*?)\$.*/)
 
    File.readlines(ARGV[0]).each {
        | line |
        unless line.empty?
            if (["[", "!", "~", "#", "@"].include?(line[0]) or
                line[0, 8] == "/adverti" or
                line.include?("##"))
                next
            end
            line = line.gsub(dollar_re, "\\1")
#           line = line.gsub("|http://", "")
            line = line.gsub("|", "")
            line = line.gsub("||", "")
            line = line.gsub(".", "\\.")
            line = line.gsub("*", ".*")
            line = line.gsub("?", "\\?")
            line = line.gsub("^", "[\\/:\\.=&\\?\\\\+\\-\\ ]+")
#           line = line.gsub("&", "\\&")
#           line = line.gsub("+", "\\+")
#           line = line.gsub("-", "\\-")
#           line = line.gsub(";", "\\;")
#           line = line.gsub("=", "\\=")
#           line = line.gsub("/", "\\/")
            puts(line.strip)
        end
    }
    puts("")
 
end
 
#############
# START NOTES
#############
 
## Reference:
## <https://sites.google.com/site/monkeesage/files/>
 
###########
# END NOTES
###########

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎