0

I am currently working on an user script made for YouTube using Firefoxs addon 'Greasemonkey' and came across a deadend.. Is it possible to check the url whether or not the url contains a specific string? I tried using indexOf() along with match() since I want it to check the string being case-insensitive..

My attempt with

if (window.location.href.indexOf(match(new RegExp("youtube.com/thumbnail?id=", "i"))) > -1) {

does not work however. I tried using contains() but it would return true as soon as the url has 'youtube' in it. Avoiding 'new RegExp' and only using match() does not work either, since I can't escape that forward slash in 'youtube.com/' with a backslash..

Dean
  • 301
  • 1
  • 3
  • 13

1 Answers1

0

related question: Is there a version of JavaScript's String.indexOf() that allows for regular expressions?

But only for a case sensitive is more easy to do:

window.location.href.toLowerCase().indexOf("youtube.com/thumbnail?id=")
Community
  • 1
  • 1
Raúl Martín
  • 4,471
  • 3
  • 23
  • 42