更新 proxy/rewriter.go

This commit is contained in:
XOF
2025-12-15 17:49:28 +08:00
parent 38167214fd
commit e14b0baa08

View File

@@ -52,7 +52,7 @@ func (r *ContentRewriter) rewriteNode(n *html.Node) {
} }
script.AppendChild(&html.Node{ script.AppendChild(&html.Node{
Type: html.TextNode, Type: html.TextNode,
Data: `(function(){var o=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(m,u){if(typeof u==="string"&&u.startsWith("/")){arguments[1]="/p/` + r.token + `"+u}return o.apply(this,arguments)};var f=window.fetch;window.fetch=function(u,opt){if(typeof u==="string"&&u.startsWith("/")){u="/p/` + r.token + `"+u}return f.call(this,u,opt)}})();`, Data: `(function(){var t="/p/` + r.token + `",b="` + r.baseURL.String() + `";Object.defineProperty(window.location,"origin",{get:function(){return b}});Object.defineProperty(window.location,"host",{get:function(){return"` + r.baseURL.Host + `"}});var o=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(m,u){if(typeof u==="string"&&u.startsWith("/")){arguments[1]=t+u}return o.apply(this,arguments)};var f=window.fetch;window.fetch=function(u,opt){if(typeof u==="string"&&u.startsWith("/")){u=t+u}return f.call(this,u,opt)};var U=window.URL;window.URL=function(u,base){if(typeof u==="string"&&u.startsWith("/")){u=t+u}return new U(u,base)}})();`,
}) })
script.NextSibling = n.FirstChild script.NextSibling = n.FirstChild
n.FirstChild.PrevSibling = script n.FirstChild.PrevSibling = script
@@ -60,7 +60,6 @@ func (r *ContentRewriter) rewriteNode(n *html.Node) {
n.FirstChild = script n.FirstChild = script
} }
attrs := map[string]bool{"href": true, "src": true, "action": true, "data": true} attrs := map[string]bool{"href": true, "src": true, "action": true, "data": true}
for i, attr := range n.Attr { for i, attr := range n.Attr {