diff --git a/handlers/proxy.go b/handlers/proxy.go index 732da7c..6d79889 100644 --- a/handlers/proxy.go +++ b/handlers/proxy.go @@ -164,7 +164,7 @@ func applyRules(domain string, path string, body string) string { if rule.Domain != domain { continue } - if rule.Path != "" && !strings.HasPrefix(path, rule.Path) { + if len(rule.Paths) > 0 && !StringInSlice(path, rule.Paths) { continue } for _, regexRule := range rule.RegexRules { @@ -180,7 +180,6 @@ func applyRules(domain string, path string, body string) string { doc.Find(injection.Position).ReplaceWithHtml(injection.Replace) } if injection.Append != "" { - log.Println("Appending", injection.Append) doc.Find(injection.Position).AppendHtml(injection.Append) } if injection.Prepend != "" { @@ -202,10 +201,10 @@ type Rule struct { } type RuleSet []struct { - Domain string `yaml:"domain"` - Path string `yaml:"path,omitempty"` - GoogleCache bool `yaml:"googleCache,omitempty"` - RegexRules []Rule `yaml:"regexRules"` + Domain string `yaml:"domain"` + Paths []string `yaml:"paths,omitempty"` + GoogleCache bool `yaml:"googleCache,omitempty"` + RegexRules []Rule `yaml:"regexRules"` Injections []struct { Position string `yaml:"position"` Append string `yaml:"append"` @@ -213,3 +212,12 @@ type RuleSet []struct { Replace string `yaml:"replace"` } `yaml:"injections"` } + +func StringInSlice(s string, list []string) bool { + for _, x := range list { + if strings.HasPrefix(s, x) { + return true + } + } + return false +} diff --git a/ruleset.yaml b/ruleset.yaml index c7bc90b..8ca8ce7 100644 --- a/ruleset.yaml +++ b/ruleset.yaml @@ -10,8 +10,12 @@ console.log("test"); alert("Hello!"); + - position: h1 + replace: | +

An example with a ladder ;-)

- domain: www.americanbanker.com - path: /news + paths: + - /news injections: - position: head append: | @@ -24,4 +28,28 @@ for (const elem of inlineGated) { elem.classList.remove('inline-gated'); } } }); + +- domain: www.nzz.ch + paths: + - /international + - /sport + - /wirtschaft + - /technologie + - /feuilleton + - /zuerich + - /wissenschaft + - /gesellschaft + - /panorama + - /mobilitaet + - /reisen + - /meinung + - /finanze + injections: + - position: head + append: | + \ No newline at end of file