我如何从用户脚本创建chrome扩展?

时间:2015-11-07 22:09:05

标签: javascript google-chrome userscripts

所以,我有一个用户脚本,我想把它变成一个扩展,在点击按钮时执行用户脚本。我自己尝试了但失败了。有人可以给我一些指示吗?这是未触及的用户名:

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?');
            }
        }   
    }
};

谢谢,谢谢!

0 个答案:

没有答案