From a1e5d540fea48d0dea52e71d40ebc3efc6724d38 Mon Sep 17 00:00:00 2001 From: Gianni Carafa Date: Sat, 4 Nov 2023 20:54:38 +0100 Subject: [PATCH] improve injections --- handlers/proxy.go | 14 ++++++++++++-- ruleset.yaml | 12 ++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/handlers/proxy.go b/handlers/proxy.go index 7fd3e3a..7128c2b 100644 --- a/handlers/proxy.go +++ b/handlers/proxy.go @@ -166,7 +166,15 @@ func applyRules(domain string, path string, body string) string { if err != nil { log.Fatal(err) } - doc.Find(injection.Position).AppendHtml(injection.Code) + 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) @@ -189,6 +197,8 @@ type RuleSet []struct { RegexRules []Rule `yaml:"regexRules"` Injections []struct { Position string `yaml:"position"` - Code string `yaml:"code"` + Append string `yaml:"append"` + Prepend string `yaml:"prepend"` + Replace string `yaml:"replace"` } `yaml:"injections"` } diff --git a/ruleset.yaml b/ruleset.yaml index 4b23b3c..1fd2011 100644 --- a/ruleset.yaml +++ b/ruleset.yaml @@ -4,7 +4,7 @@ replace: \ No newline at end of file + replace: | +

My Custom Title

+ - position: .left-content article # Position where to inject the code into DOM + prepend: | +

Suptitle

\ No newline at end of file