add another domain

This commit is contained in:
Gianni Carafa
2023-11-05 22:32:13 +01:00
parent 7b519c7016
commit a6ee6aebfc
2 changed files with 43 additions and 7 deletions

View File

@@ -164,7 +164,7 @@ func applyRules(domain string, path string, body string) string {
if rule.Domain != domain { if rule.Domain != domain {
continue continue
} }
if rule.Path != "" && !strings.HasPrefix(path, rule.Path) { if len(rule.Paths) > 0 && !StringInSlice(path, rule.Paths) {
continue continue
} }
for _, regexRule := range rule.RegexRules { 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) doc.Find(injection.Position).ReplaceWithHtml(injection.Replace)
} }
if injection.Append != "" { if injection.Append != "" {
log.Println("Appending", injection.Append)
doc.Find(injection.Position).AppendHtml(injection.Append) doc.Find(injection.Position).AppendHtml(injection.Append)
} }
if injection.Prepend != "" { if injection.Prepend != "" {
@@ -202,10 +201,10 @@ type Rule struct {
} }
type RuleSet []struct { type RuleSet []struct {
Domain string `yaml:"domain"` Domain string `yaml:"domain"`
Path string `yaml:"path,omitempty"` Paths []string `yaml:"paths,omitempty"`
GoogleCache bool `yaml:"googleCache,omitempty"` GoogleCache bool `yaml:"googleCache,omitempty"`
RegexRules []Rule `yaml:"regexRules"` RegexRules []Rule `yaml:"regexRules"`
Injections []struct { Injections []struct {
Position string `yaml:"position"` Position string `yaml:"position"`
Append string `yaml:"append"` Append string `yaml:"append"`
@@ -213,3 +212,12 @@ type RuleSet []struct {
Replace string `yaml:"replace"` Replace string `yaml:"replace"`
} `yaml:"injections"` } `yaml:"injections"`
} }
func StringInSlice(s string, list []string) bool {
for _, x := range list {
if strings.HasPrefix(s, x) {
return true
}
}
return false
}

View File

@@ -10,8 +10,12 @@
console.log("test"); console.log("test");
alert("Hello!"); alert("Hello!");
</script> </script>
- position: h1
replace: |
<h1>An example with a ladder ;-)</h1>
- domain: www.americanbanker.com - domain: www.americanbanker.com
path: /news paths:
- /news
injections: injections:
- position: head - position: head
append: | append: |
@@ -24,4 +28,28 @@
for (const elem of inlineGated) { elem.classList.remove('inline-gated'); } for (const elem of inlineGated) { elem.classList.remove('inline-gated'); }
} }
}); });
</script>
- domain: www.nzz.ch
paths:
- /international
- /sport
- /wirtschaft
- /technologie
- /feuilleton
- /zuerich
- /wissenschaft
- /gesellschaft
- /panorama
- /mobilitaet
- /reisen
- /meinung
- /finanze
injections:
- position: head
append: |
<script>
document.addEventListener("DOMContentLoaded", () => {
const paywall = document.querySelector('.dynamic-regwall');
removeDOMElement(paywall)
});
</script> </script>