improve injections
This commit is contained in:
@@ -166,7 +166,15 @@ func applyRules(domain string, path string, body string) string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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()
|
body, err = doc.Html()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -189,6 +197,8 @@ type RuleSet []struct {
|
|||||||
RegexRules []Rule `yaml:"regexRules"`
|
RegexRules []Rule `yaml:"regexRules"`
|
||||||
Injections []struct {
|
Injections []struct {
|
||||||
Position string `yaml:"position"`
|
Position string `yaml:"position"`
|
||||||
Code string `yaml:"code"`
|
Append string `yaml:"append"`
|
||||||
|
Prepend string `yaml:"prepend"`
|
||||||
|
Replace string `yaml:"replace"`
|
||||||
} `yaml:"injections"`
|
} `yaml:"injections"`
|
||||||
}
|
}
|
||||||
|
|||||||
12
ruleset.yaml
12
ruleset.yaml
@@ -4,7 +4,7 @@
|
|||||||
replace: <script $1 script="/https://www.example.com/$3"
|
replace: <script $1 script="/https://www.example.com/$3"
|
||||||
injections:
|
injections:
|
||||||
- position: head # Position where to inject the code
|
- position: head # Position where to inject the code
|
||||||
code: |
|
append: |
|
||||||
<script>
|
<script>
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
console.log("test");
|
console.log("test");
|
||||||
@@ -18,8 +18,8 @@
|
|||||||
replace: <script $1 script="/https://www.example.com/$3"
|
replace: <script $1 script="/https://www.example.com/$3"
|
||||||
injections:
|
injections:
|
||||||
- position: .left-content article .post-title # Position where to inject the code into DOM
|
- position: .left-content article .post-title # Position where to inject the code into DOM
|
||||||
code: |
|
replace: |
|
||||||
<script>
|
<h1>My Custom Title</h1>
|
||||||
window.localStorage.clear();
|
- position: .left-content article # Position where to inject the code into DOM
|
||||||
console.log("test");
|
prepend: |
|
||||||
</script>
|
<h2>Suptitle</h2>
|
||||||
Reference in New Issue
Block a user