2014-09-21 63 views
2

我有一個問題,我做了一個Chrome擴展和OPERA,但對於Firefox,它根本沒有任何工作,我的擴展只是阻止了我添加到我的url列表background.js。 有人可以幫助我將Chrome轉換爲Firefox嗎?如何將Chrome擴展程序轉換爲Firefox - URL阻止/重定向

更多細節: 我試圖將我的Chrome擴展轉換爲fireox,我的Chrome擴展阻止了位於background.js中的url列表,我真的被Firefox困住了,我試圖使用我的chrome版本下的Firefox擴展,它加載圖標,在manifest.json的相關信息,但background.js不工作,網址未堵塞

這裏我給大家先我manifest.json代碼:

{ 
"name":"blocker", 
"description":"block bad urls", 
"version":"1.0", 
"manifest_version":2, 
"permissions": [ 
     "http://*/*", 
     "https://*/*", 
     "webRequest", 
     "webRequestBlocking", 
     "<all_urls>" ,  
     "unlimitedStorage" 
]  
,"icons":{"48":"icon.png"}, 
"background":{ 
    "scripts": ["background.js"] 
}, 
"browser_action":{ 
    "default_popup":"popup.html", 
    "default_icon":"icon.png"}, 
"content_scripts": [ 
{ 
"matches": ["<all_urls>"], 
"js": ["disablef12.js"] 
} 
] 
} 

這裏是我的background.js

var AUTHORIZED_DOMAINS= { 
"www.url01.com": false, 
"url01.com": false, 
"www.url02.com": false, 
etc.. 
}; 
function extract_domain(url) { 
    var matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i); 
    return matches[1]; 
} 

chrome.webRequest.onBeforeRequest.addListener(function(details) { 
var domain = extract_domain(details.url); 
return { cancel: AUTHORIZED_DOMAINS[domain ]===false }; 
}, {urls: ["<all_urls>"]},["blocking"]); 

感謝您的時間了很多東西,幫助

回答

1

塊網址:

https://github.com/Noitidart/PortableTester/tree/block-urls

下載XPI:

充滿工作如何封鎖網址,引導方法示例並將其拖到Firefox上,它阻止谷歌和BBC。

const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; 
Cu.import('resource://gre/modules/Services.jsm'); 

var urls_block = [ //if urls ontain any of these elements they will be blocked or redirected, your choice based on code in observer line 17 
'www.google.com', 
'www.bbc.com' 
]; 

var observers = { 
    'http-on-modify-request': { 
     observe: function (aSubject, aTopic, aData) { 
      console.info('http-on-modify-request: aSubject = ' + aSubject + ' | aTopic = ' + aTopic + ' | aData = ' + aData); 
      var httpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel); 
      var requestUrl = httpChannel.URI.spec; 
      for (var i=0; i<urls_block.length; i++) { 
      if (requestUrl.indexOf(urls_block[i]) > -1) { 
       //httpChannel.cancel(Cr.NS_BINDING_ABORTED); //this aborts the load 
       httpChannel.redirectTo(Services.io.newURI('data:text,url_blocked', null, null)); //can redirect with this line, if dont want to redirect and just block, then uncomment this line and comment out line above (line 17) 
      } 
      } 
     }, 
     reg: function() { 
      Services.obs.addObserver(observers['http-on-modify-request'], 'http-on-modify-request', false); 
     }, 
     unreg: function() { 
      Services.obs.removeObserver(observers['http-on-modify-request'], 'http-on-modify-request'); 
     } 
    } 
}; 

function install() {} 

function uninstall() {} 

function startup() { 
for (var o in observers) { 
    observers[o].reg(); 
} 
} 

function shutdown(aData, aReason) { 
if (aReason == APP_SHUTDOWN) return; 

for (var o in observers) { 
    observers[o].unreg(); 
} 
} 

如果你想要一個圖標只添加到xpi文件,這只是一個zip文件重命名爲xpi。添加一個名爲icon.png的文件

請參閱此基本引導程序模板:https://gist.github.com/Noitidart/9025999

相關問題