更新 proxy/rewriter.go

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

View File

@@ -52,14 +52,13 @@ func (r *ContentRewriter) rewriteNode(n *html.Node) {
}
script.AppendChild(&html.Node{
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
n.FirstChild.PrevSibling = script
script.Parent = n
n.FirstChild = script
}
attrs := map[string]bool{"href": true, "src": true, "action": true, "data": true}