0

I have the current script to amend a link in the URL bar

(function() {
    'use strict';
    location.replace(location.href.replace("www.reddit.com", "old.reddit.com"));
})();

I'd want it to check if the URL has the word "old" before running the remainder of the script. How do I do this?

NLed
  • 1,817
  • 14
  • 37
  • 67

1 Answers1

0

You can check the index of the word old by considering the URL as a normal string.

if(location.href.indexOf('old') > -1) {
  // do something
}

It is simple as that.

anjuc
  • 149
  • 2
  • 10