1
votes

I am using Jquery userscript to change the link within <iframe> or <a> with any other link for me (not on the site). How can I remove part of that link?

Currently this userscripts turns

http://www.youtube.com/embed/YDkTCGL1l0s?hd=1&autohide=1&showinfo=0&wmode=opaque&cc_load_policy=1&rel=0&autoplay=1

into

http://playit.pk/embed?v=YDkTCGL1l0s%3fhd=1&autohide=1&showinfo=0&wmode=opaque&cc_load_policy=1&rel=0&autoplay=1

I want to remove the

hd=1&autohide=1&showinfo=0&wmode=opaque&cc_load_policy=1&rel=0&autoplay=1

So that the final link becomes

http://playit.pk/embed?v=YDkTCGL1l0s

Here is what I am currently using.

$('iframe').each(function(){
        this.src = this.src.replace('youtube.com/embed/', 'playit.pk/embed?v=');
    });
1
so it's not working or you want another way?Mritunjay
Basically when it is converted to another link playit.pk/… As no such link exist on playit.pk so the video wont start. So only if the link is like playit.pk/embed?v=YDkTCGL1l0s The video starts playingSarmadK
I think you are trying to encode/decode the url here.Mr_Green
So what do you want me to? Wait for the comments like "please elaborate :p"SarmadK

1 Answers

0
votes

Try this :

$('iframe').each(function(){
        var src = $(this).attr('src');
        var index = src.indexOf('?');
            src = src.substring(0,index);

        $(this).attr('src',src.replace('youtube.com/embed/', 'playit.pk/embed?v='));
    });

Demo