更新 proxy/rewriter.go

This commit is contained in:
XOF
2025-12-15 19:09:47 +08:00
parent 5c9ba5da8a
commit 42a6b94f06

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(!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}})();`,
Data: `(function(){var t="/p/` + r.token + `";function r(u){if(!u||typeof u!=="string")return u;if(u.startsWith(t))return u;if(u.startsWith("http://")||u.startsWith("https://")||u.startsWith("data:")||u.startsWith("blob:")||u.startsWith("javascript:"))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 d=Object.getOwnPropertyDescriptor(HTMLImageElement.prototype,"src");if(d&&d.set){var os=d.set;Object.defineProperty(i,"src",{set:function(v){os.call(this,r(v))},get:d.get})}return i}})();`,
})
script.NextSibling = n.FirstChild
n.FirstChild.PrevSibling = script