allow domain list in rules
This commit is contained in:
@@ -121,12 +121,15 @@ See in [ruleset.yaml](ruleset.yaml) for an example.
|
||||
|
||||
```yaml
|
||||
- domain: www.example.com
|
||||
domains: # Additional domains to apply the rule
|
||||
- www.example.com
|
||||
- www.beispiel.de
|
||||
regexRules:
|
||||
- match: <script\s+([^>]*\s+)?src="(/)([^"]*)"
|
||||
replace: <script $1 script="/https://www.example.com/$3"
|
||||
injections:
|
||||
- position: head # Position where to inject the code
|
||||
append: |
|
||||
append: | # possible keys: append, prepend, replace
|
||||
<script>
|
||||
window.localStorage.clear();
|
||||
console.log("test");
|
||||
|
||||
@@ -155,14 +155,17 @@ func loadRules() RuleSet {
|
||||
yaml.Unmarshal(yamlFile, &ruleSet)
|
||||
}
|
||||
|
||||
domains := []string{}
|
||||
for _, rule := range ruleSet {
|
||||
//log.Println("Loaded rules for", rule.Domain)
|
||||
|
||||
domains = append(domains, rule.Domain)
|
||||
domains = append(domains, rule.Domains...)
|
||||
if os.Getenv("ALLOWED_DOMAINS_RULESET") == "true" {
|
||||
allowedDomains = append(allowedDomains, rule.Domain)
|
||||
allowedDomains = append(allowedDomains, domains...)
|
||||
}
|
||||
}
|
||||
|
||||
log.Println("Loaded rules for", len(ruleSet), "Domains")
|
||||
log.Println("Loaded ", len(ruleSet), " rules for", len(domains), "Domains")
|
||||
return ruleSet
|
||||
}
|
||||
|
||||
@@ -172,8 +175,8 @@ func applyRules(domain string, path string, body string) string {
|
||||
}
|
||||
|
||||
for _, rule := range rulesSet {
|
||||
// rule.Domain can be multiple domains delimited by "|"
|
||||
domains := strings.Split(rule.Domain, "|")
|
||||
domains := rule.Domains
|
||||
domains = append(domains, rule.Domain)
|
||||
for _, ruleDomain := range domains {
|
||||
if ruleDomain != domain {
|
||||
continue
|
||||
@@ -217,6 +220,7 @@ type Rule struct {
|
||||
|
||||
type RuleSet []struct {
|
||||
Domain string `yaml:"domain"`
|
||||
Domains []string `yaml:"domains,omitempty"`
|
||||
Paths []string `yaml:"paths,omitempty"`
|
||||
GoogleCache bool `yaml:"googleCache,omitempty"`
|
||||
RegexRules []Rule `yaml:"regexRules"`
|
||||
|
||||
26
ruleset.yaml
26
ruleset.yaml
@@ -1,4 +1,6 @@
|
||||
- domain: www.example.com
|
||||
domains:
|
||||
- www.beispiel.com
|
||||
regexRules:
|
||||
- match: <script\s+([^>]*\s+)?src="(/)([^"]*)"
|
||||
replace: <script $1 script="/https://www.example.com/$3"
|
||||
@@ -53,7 +55,16 @@
|
||||
removeDOMElement(paywall)
|
||||
});
|
||||
</script>
|
||||
- domain: www.architecturaldigest.com|www.bonappetit.com|www.cntraveler.com|www.epicurious.com|www.gq.com|www.newyorker.com|www.vanityfair.com|www.vogue.com|www.wired.com
|
||||
- domains:
|
||||
- www.architecturaldigest.com
|
||||
- www.bonappetit.com
|
||||
- www.cntraveler.com
|
||||
- www.epicurious.com
|
||||
- www.gq.com
|
||||
- www.newyorker.com
|
||||
- www.vanityfair.com
|
||||
- www.vogue.com
|
||||
- www.wired.com
|
||||
injections:
|
||||
- position: head
|
||||
append: |
|
||||
@@ -63,7 +74,9 @@
|
||||
banners.forEach(el => { el.remove(); });
|
||||
});
|
||||
</script>
|
||||
- domain: www.nytimes.com|www.time.com
|
||||
- domains:
|
||||
- www.nytimes.com
|
||||
- www.time.com
|
||||
injections:
|
||||
- position: head
|
||||
append: |
|
||||
@@ -74,7 +87,14 @@
|
||||
banners.forEach(el => { el.remove(); });
|
||||
});
|
||||
</script>
|
||||
- domain: www.thestar.com|www.niagarafallsreview.ca|www.stcatharinesstandard.ca|www.thepeterboroughexaminer.com|www.therecord.com|www.thespec.com|www.wellandtribune.ca
|
||||
- domains:
|
||||
- www.thestar.com
|
||||
- www.niagarafallsreview.ca
|
||||
- www.stcatharinesstandard.ca
|
||||
- www.thepeterboroughexaminer.com
|
||||
- www.therecord.com
|
||||
- www.thespec.com
|
||||
- www.wellandtribune.ca
|
||||
injections:
|
||||
- position: head
|
||||
append: |
|
||||
|
||||
Reference in New Issue
Block a user