将多个URL重定向到多个备用URL

时间:2016-03-26 10:26:39

标签: javascript google-chrome redirect google-chrome-extension

我正在构建Chrome扩展程序,将某些网站重定向到其他网站。

目前,我正在使用由用户亲切编写的一段代码,它就像一个魅力。唯一的,它只重定向一个站点。 我怎样才能让它有一个重定向到我可以指定的其他网站的网站列表?

这是background.js的当前代码:

var host = "http://tpb.pirateparty.org.uk";
chrome.webRequest.onBeforeRequest.addListener(
    function(details) {
         return {redirectUrl: host + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]};
    },
    {
        urls: [
            "*://piratebay.se/*",
            "*://www.piratebay.se/*"
        ],
        types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
    },
    ["blocking"]
);

0 个答案:

没有答案
相关问题