feat: enable multiple domains to apply same rule
This commit is contained in:
@@ -172,33 +172,37 @@ func applyRules(domain string, path string, body string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rule := range rulesSet {
|
for _, rule := range rulesSet {
|
||||||
if rule.Domain != domain {
|
// rule.Domain can be multiple domains delimited by "|"
|
||||||
continue
|
domains := strings.Split(rule.Domain, "|")
|
||||||
}
|
for _, ruleDomain := range domains {
|
||||||
if len(rule.Paths) > 0 && !StringInSlice(path, rule.Paths) {
|
if ruleDomain != domain {
|
||||||
continue
|
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)
|
|
||||||
}
|
}
|
||||||
if injection.Replace != "" {
|
if len(rule.Paths) > 0 && !StringInSlice(path, rule.Paths) {
|
||||||
doc.Find(injection.Position).ReplaceWithHtml(injection.Replace)
|
continue
|
||||||
}
|
}
|
||||||
if injection.Append != "" {
|
for _, regexRule := range rule.RegexRules {
|
||||||
doc.Find(injection.Position).AppendHtml(injection.Append)
|
re := regexp.MustCompile(regexRule.Match)
|
||||||
|
body = re.ReplaceAllString(body, regexRule.Replace)
|
||||||
}
|
}
|
||||||
if injection.Prepend != "" {
|
for _, injection := range rule.Injections {
|
||||||
doc.Find(injection.Position).PrependHtml(injection.Prepend)
|
doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
|
||||||
}
|
if err != nil {
|
||||||
body, err = doc.Html()
|
log.Fatal(err)
|
||||||
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user