简体   繁体   中英

Using regex to find a url pattern then redirect to a new one?

Sorry for the sloppy title, what i am trying to accomplish is an extension that will read my current url, and if it falls under a certain pattern then it will redirect me to a new page.

To further explain here is an example:

Every time i get a url like this: http://giant.gfycat.com/DownrightDismalElkhound.gif (giant.*.gif)

I want to be redirected to this: http://gfycat.com/DownrightDismalElkhound ( giant. * .gif )

I have never written a chrome extension before so i was hoping someone could point me to a good resource to be able to learn how to do this.

 var url = window.location.href; if (!url.match(/giant\\./) && !url.match(/\\.gif$/)){ window.location.href = 'http://www.cnn.com'; } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM