更新 proxy/rewriter.go

This commit is contained in:
XOF
2025-12-15 18:37:22 +08:00
parent 8091c9993d
commit 5c9ba5da8a

View File

@@ -52,7 +52,7 @@ func (r *ContentRewriter) rewriteNode(n *html.Node) {
}
script.AppendChild(&html.Node{
Type: html.TextNode,
Data: `(function(){var t="/p/` + r.token + `";function r(u){if(typeof u!=="string")return u;if(u.startsWith(t))return u;if(u.startsWith("/")){return t+u}return u}var o=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(m,u){arguments[1]=r(u);return o.apply(this,arguments)};var f=window.fetch;window.fetch=function(u,opt){return f.call(this,r(u),opt)}})();`,
Data: `(function(){var t="/p/` + r.token + `";function r(u){if(!u||typeof u!=="string")return u;if(u.startsWith(t)||u.startsWith("http")||u.startsWith("data:")||u.startsWith("blob:"))return u;if(u.startsWith("/")){return t+u}return u}var o=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(m,u){arguments[1]=r(u);return o.apply(this,arguments)};var f=window.fetch;window.fetch=function(u,opt){return f.call(this,r(u),opt)};var oa=Element.prototype.setAttribute;Element.prototype.setAttribute=function(n,v){if((n==="href"||n==="src")&&typeof v==="string"){v=r(v)}return oa.call(this,n,v)};var oi=Image;window.Image=function(){var i=new oi();var os=Object.getOwnPropertyDescriptor(oi.prototype,"src").set;Object.defineProperty(i,"src",{set:function(v){os.call(this,r(v))}});return i}})();`,
})
script.NextSibling = n.FirstChild
n.FirstChild.PrevSibling = script