0

So, I have a userscript, and I want to make this into an extension that executes the userscript on click of the button. I tried it myself and failed. Could anybody give me some pointers? Here is the userscript untouched:

proxy_str = "proxy-4-web.appspot.com//";
yt_url = "youtube.com/";
yt_str = "videoonline.pk/";

window.onkeydown = function(event) {
    if (event.ctrlKey && event.altKey && event.keyCode === 80) {
        if(window.location.href.indexOf(proxy_str) === -1 && window.location.href.indexOf(yt_str) === -1) {
           if(window.location.href.indexOf(yt_url) != -1) {
            var str = window.location.href,
                delimiter = '?',
                div_loc = 1,
                tokens = str.split(delimiter),
                after = tokens.slice(div_loc),
                result = yt_str + 'watch.php?' + after.join(delimiter);
            window.location.href = 'http://'+ result;
           } else {
            var str = window.location.href,
                delimiter = '/',
                div_loc = 2,
                tokens = str.split(delimiter),
                after = tokens.slice(div_loc),
                result = proxy_str + after.join(delimiter);
            window.location.href = 'http://'+ result;
           }
        } else {
            if(window.location.href.indexOf(proxy_str) >= 0 && window.location.href.indexOf(yt_str) === -1) {
            var url = window.location.toString();
            window.location = url.replace(proxy_str, '');
            } else {
            var url = window.location.toString();
            var url2 = url.replace(yt_str,yt_url);
            window.location = url2.replace('watch.php?', 'watch?');
            }
        }   
    }
};

Thanks, appreciate it!

  • 1
    Reference: http://stackoverflow.com/questions/11480985/can-a-greasemonkey-type-userscript-be-packaged-as-a-chrome-extension and http://stackoverflow.com/questions/5258989/manually-adding-a-userscript-to-google-chrome . – Brock Adams Nov 07 '15 at 23:26
  • To turn a UserScript into a chrome extension, you just need to convert the headers to a chrome extension's `manifest.json` style – Quill Apr 03 '16 at 10:14

0 Answers0