浏览代码

added the page modifications to each request

svcs 1 年之前
父节点
当前提交
9f9751f0dd
共有 1 个文件被更改,包括 17 次插入3 次删除
  1. 17 3
      pkg/client.go

+ 17 - 3
pkg/client.go

@@ -38,7 +38,7 @@ func (c *Controller) RetrieveStaticResource(method string, path string, ctx *gin
 	if resp.StatusCode == 200 {
 		c.CacheResource(path, NewCachedResource(b, resp.Header.Get("content-type"), resp.StatusCode))
 	}
-	return b, resp.Header.Get("content-type"), resp.StatusCode, nil
+	return c.pageMod(b), resp.Header.Get("content-type"), resp.StatusCode, nil
 
 }
 
@@ -68,7 +68,7 @@ func (c *Controller) SiteauditApiCall(method string, path string, query string,
 	if err != nil {
 		return nil, "", 500, err
 	}
-	return b, resp.Header.Get("content-type"), resp.StatusCode, nil
+	return c.pageMod(b), resp.Header.Get("content-type"), resp.StatusCode, nil
 
 }
 
@@ -121,7 +121,7 @@ func (c *Controller) SemrushGeneric(ctx *gin.Context) ([]byte, string, int, erro
 		}
 	}
 
-	return b, resp.Header.Get("content-type"), resp.StatusCode, nil
+	return c.pageMod(b), resp.Header.Get("content-type"), resp.StatusCode, nil
 
 }
 
@@ -146,3 +146,17 @@ func (c *Controller) setHeaders(req *http.Request, ctx *gin.Context) {
 	}
 
 }
+
+/*
+Rewrite all occurences of these values into the response body
+*/
+func (c *Controller) pageMod(data []byte) []byte {
+	newBody := strings.ReplaceAll(string(data), "\"srf-browser-unhappy\"", "\"srf-browser-unhappy\" style=\"display:none;\"")
+	newBody = strings.ReplaceAll(newBody, "\"srf-navbar__right\"", "\"srf-navbar__right\" style=\"display:none;\"")
+	newBody = strings.ReplaceAll(newBody, "<footer", "<footer style=\"display:none;\"")
+	newBody = strings.ReplaceAll(newBody, "\"srf-report-sidebar-extras\"", "\"srf-report-sidebar-extra\" style=\"display:none;\"")
+	newBody = strings.ReplaceAll(newBody, c.Config.AllowedDomain, c.Config.ProxyAddr)
+	newBody = strings.ReplaceAll(newBody, c.Config.AltAllowedDomain, c.Config.ProxyAddr)
+	return []byte(newBody)
+
+}