-1

I’ve scripted it to append a string to the URL and when I keep issuing the request it keeps appending over and over again

In OnBeforeRequest function

if (oSession.uriContains("www.youtube.com/results?search_query=")) {

    var sText = "+test1+test2+test3";

    oSession.fullUrl = oSession.fullUrl + sText;
}

visual info: https://i.stack.imgur.com/JT4bF.png

How can I fix this ?

nasekt
  • 15
  • 7

1 Answers1

2

The typical way to do this would be to see whether the string in question already ends with what you're adding, and if so, don't add it again.

endsWith in JavaScript

if (oSession.uriContains("www.youtube.com/results?search_query=")) 
{
  var str = oSession.fullUrl;
  var sAppend = "+test1+test2+test3";
  if (oSession.fullUrl.indexOf(sAppend, str.length - sAppend.length) < 0)
  {
     oSession.fullUrl = str + sAppend;
  }
}
Community
  • 1
  • 1
EricLaw
  • 56,563
  • 7
  • 151
  • 196
  • Sorry,tried several times, but its not working, or rather it does not even append at all. http://i.imgur.com/JSExReN.jpg – nasekt Sep 13 '14 at 13:39
  • fixed a typo. try it again. – EricLaw Sep 13 '14 at 20:28
  • Thanks, but there is one new problem, it gets appended to **page result** as well.Because of that, I can only browse the first page. http://imgur.com/GX29THV – nasekt Sep 14 '14 at 02:14
  • That's a different question, so you technically should mark this one as answered and ask a new question. The change is simple: just change the line to `if (oSession.fullUrl.indexOf(sAppend) < 0)` – EricLaw Sep 15 '14 at 14:03