diff --git a/handlers/proxy.go b/handlers/proxy.go index 89d8fa8..664e9c8 100644 --- a/handlers/proxy.go +++ b/handlers/proxy.go @@ -172,33 +172,37 @@ func applyRules(domain string, path string, body string) string { } for _, rule := range rulesSet { - if rule.Domain != domain { - continue - } - if len(rule.Paths) > 0 && !StringInSlice(path, rule.Paths) { - continue - } - for _, regexRule := range rule.RegexRules { - re := regexp.MustCompile(regexRule.Match) - body = re.ReplaceAllString(body, regexRule.Replace) - } - for _, injection := range rule.Injections { - doc, err := goquery.NewDocumentFromReader(strings.NewReader(body)) - if err != nil { - log.Fatal(err) + // rule.Domain can be multiple domains delimited by "|" + domains := strings.Split(rule.Domain, "|") + for _, ruleDomain := range domains { + if ruleDomain != domain { + continue } - if injection.Replace != "" { - doc.Find(injection.Position).ReplaceWithHtml(injection.Replace) + if len(rule.Paths) > 0 && !StringInSlice(path, rule.Paths) { + continue } - if injection.Append != "" { - doc.Find(injection.Position).AppendHtml(injection.Append) + for _, regexRule := range rule.RegexRules { + re := regexp.MustCompile(regexRule.Match) + body = re.ReplaceAllString(body, regexRule.Replace) } - if injection.Prepend != "" { - doc.Find(injection.Position).PrependHtml(injection.Prepend) - } - body, err = doc.Html() - if err != nil { - log.Fatal(err) + for _, injection := range rule.Injections { + doc, err := goquery.NewDocumentFromReader(strings.NewReader(body)) + if err != nil { + log.Fatal(err) + } + if injection.Replace != "" { + doc.Find(injection.Position).ReplaceWithHtml(injection.Replace) + } + if injection.Append != "" { + doc.Find(injection.Position).AppendHtml(injection.Append) + } + if injection.Prepend != "" { + doc.Find(injection.Position).PrependHtml(injection.Prepend) + } + body, err = doc.Html() + if err != nil { + log.Fatal(err) + } } } } diff --git a/ruleset.yaml b/ruleset.yaml index 8ca8ce7..8f4796c 100644 --- a/ruleset.yaml +++ b/ruleset.yaml @@ -4,21 +4,21 @@ replace: - position: h1 - replace: | + replace: |