Javascript Bookmark to download from youtube to mp3 directly
<p>I am editing a javascript code[the code takes me directly to downloading the video to mp3] since the code provided by the website was not working..i tried editing on my own</p>

<p>This is the code below</p>

<pre><code>javascript:(function() {if (location.href.indexOf('www.youtube.com') &gt; -1) {var uri_enc = encodeURIComponent(location.href).replace(/https%3A%2F%2Fwww.youtube.com%2Fwatch/g,'');var uri_dec = decodeURIComponent(uri_enc);window.open("http://youtubeplaylist-mp3.com/" + uri_dec)}else{alert('sorry youcant');}}) ();
</code></pre>

<p>Now the problem here is, I have made a bookmark of this code in chrome, The intention of the bookmark is to run the code when I visit the youtube video page and press the bookmark button.</p>

<p>But for some reason the bookmark doesn't seem to work. so I opened up the console and checked the reason..here are the pictures below of the error..</p>

<p><a href="https://i.stack.imgur.com/4H7Rn.png" rel="nofollow noreferrer">in console this error comes</a></p>

<p><a href="https://i.stack.imgur.com/Qwvmg.png" rel="nofollow noreferrer">on further examining i find that %2F is getting detected as closing '/' so its not detecting the latter part </a></p>

<p>on further examining i find that %2F is getting detected as closing '/' so its not detecting the latter part</p>

<p>Because of that false detection my bookmark is not working.
However the good news is that if I copy paste the code to console directly and execute then it will work succesfully. </p>

<p>But that is too much work.:p for everyday use.</p>

<p>so help me fix the bookmark please. </p>

<h2>UPDATE</h2>

<p>Javascript is solved and bookmark is working...
Here below is the complete code..which works for single video and a playlist too..you just need to click on the bookmark when you are on the video page or the playlist page which will direct to download page...</p>

<p><code>javascript:(function() {if (location.href.indexOf('www.youtube.com') &gt; -1) {var uri_enc = location.href.replace(/https:\/\/www.youtube.com\/watch|https:\/\/www.youtube.com\/playlist/g,'');window.open("http://youtubeplaylist-mp3.com/" + uri_enc);}else{alert('sorry youcant');}}) ();</code></p>

<p>I am still learning javascript so it took quiet time to understand the answers but thanks to both the coders who answered especially TigOldBitties who gave the complete code from which I understood what the mistake was...Have a nice day..</p>