From 951c0a809ebea183279e295ee485cc3e12841021 Mon Sep 17 00:00:00 2001 From: Ali Reza Yahya Date: Sun, 3 Mar 2024 03:03:46 +0100 Subject: [PATCH] Exclude style tags from head element search --- redirector/htmlparser.go | 5 +++-- routes.yaml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/redirector/htmlparser.go b/redirector/htmlparser.go index 6d8c5e0..47dfe26 100644 --- a/redirector/htmlparser.go +++ b/redirector/htmlparser.go @@ -21,14 +21,15 @@ func FetchHeadElements(targetURL string) (string, error) { return html.Parse(resp.Body) } - // Recursive function to find all elements within excluding scripts and stylesheets + // Recursive function to find all elements within excluding scripts, stylesheets, and style tags findHeadElements := func(n *html.Node) []*html.Node { var headElements []*html.Node var traverse func(*html.Node) traverse = func(n *html.Node) { if n.Type == html.ElementNode && n.Data == "head" { for child := n.FirstChild; child != nil; child = child.NextSibling { - if child.Data != "script" && child.Data != "link" { + // Exclude script, link, and style tags + if child.Data != "script" && child.Data != "link" && child.Data != "style" { headElements = append(headElements, child) } } diff --git a/routes.yaml b/routes.yaml index 4d14084..4e2b306 100644 --- a/routes.yaml +++ b/routes.yaml @@ -2,7 +2,7 @@ a: https://a.com abc: https://hehe.com db: https://distrobe.at doner: kebab123 +go: https://google.com me: https://alileza.me test: https://google.com tos: tos -