How do I change inline javascript with Tritium?

281 views Asked by At

I'm transforming a website using tritium, and there's a chunk of inline javascript that interferes with how the mobile site should work. 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?

1

There are 1 answers

0
nmakiya On

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.