Chrome百度反跳转插件BaiduGo源代码

BaiduGo由两个文件组成,由于代码量非常小,所以直接放到博客上了.

manifest.json

{
    "name":"BaiduGo",
    "version":"1.0",
    "description":"百度反跳转插件 http://www.blackglory.me/baidugo",
    "background":{"scripts":["background.js"]},
    "permissions":["webRequest","*://*.baidu.com/","webRequestBlocking"],
    "manifest_version":2
}

background.js

chrome.webRequest.onBeforeSendHeaders.addListener(  
    function(details){
        for(var i=0;i<details.requestHeaders.length;i++){
            if(details.requestHeaders[i].name=="Referer"){
                details.requestHeaders[i].value=details.url;
                break;
            }
        }
        return {requestHeaders:details.requestHeaders};
    },
    {urls:["*://*.baidu.com/*"]},
    ["blocking","requestHeaders"]
);