How can I remove a piece of javascript text with tritium?

160 views Asked by At

I have this piece of tritium text that I was to use in order to remove a piece of javascript code.

  # to remove an inline js code based on text search
      $("//script[contains(text(),'textiwanttoremove')]") {
          text(){
              replace('thetextiwanttoremove','')
          }
      }

However, this code doesn't work. I get an error,

Failed to create body.ts transformer: 
scripts/main.ts:13: function Text.$(Text) does not exist in namespace tritium; (called from Text.with(Regexp)).

also, it if I replace text() with inner(), it still does not work, thank you.

1

There are 1 answers

0
juanca On BEST ANSWER

Hi there please verify that the mixer stdlib is present on your Mixer.loc file and then try using the following replace: http://www.tritium.io/current#Text.replace(Regexp%20%25search,%20Text%20%25with)

 $(".//script[contains(text(), 'txt2remove')]") {
    text() {
      replace(/txt2remove/, '') 
    }
 }

That should work.

Juan Camilo