简体   繁体   English

如何使用Tritium更改嵌入式JavaScript?

[英]How do I change inline javascript with Tritium?

I'm transforming a website using tritium, and there's a chunk of inline javascript that interferes with how the mobile site should work. 我正在使用Tritium转换网站,并且有很多内联JavaScript会干扰移动网站的工作方式。 There's really only one line that I want to take out, however, so I can't really just remove the whole chunk. 但是,实际上我只想删除一行,所以我不能只删除整个块。 Right now what I'm doing is just fetching the text and using a regex replace to remove the line: 现在,我正在做的只是获取文本并使用正则表达式替换来删除行:

$(".//script[contains(text(), "part of inline js")] {
    # an example of the line i want to take out
    text() {
        replace("document.getElementById('someid').value = 'somevalue';") {
            set("")
        }
    }
}

This seems kind of clunky, though, especially if the section I want to change gets very long. 但是,这似乎有些笨拙,尤其是当我要更改的部分过长时。 Is there a better way of doing this? 有更好的方法吗?

So I would probably use a regular expression in this case. 因此,在这种情况下,我可能会使用正则表达式。 Once you've got a unique enough capture, you can just capture the rest of the line. 一旦获得了足够独特的捕获,就可以捕获该行的其余部分。

In this case maybe it's something like: 在这种情况下,可能类似于:

replace(/.*getElementById\\('someid'\\)\\.value.*/, "")

As of right now this is the only way to edit inline scripts. 到目前为止,这是编辑内联脚本的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM