用于阻止的 Firefox 插件 url
Firefox addon for blocking url
通过我的扩展,我想 "block" 一些网站 url 并重定向到我想要的一个 url 每当用户试图加入被阻止的 url 时。
假设我想 "ban" facebook.com 如果有人试图去 facebook.com ... firefox 插件应该将他重定向到 www.google.com.
我这里有这个代码
============================================= ==================================
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.facebook.com'
];
var redir_obj = {
'www.google.com': 'data:text,' + escape('url_blocked that would have went to google')
}
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.toLowerCase();
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(redir_obj[urls_block[i]], 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)
break;
}
}
},
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();
}
}
============================================= =====================
但我不知道如何让它工作,即使它是将 "facebook" 重定向到 "google"
的正确代码
有人可以帮我解决这个问题,告诉我如何将它打包为 firefox 扩展吗???
非常感谢您花时间阅读。
此处发布了演示其工作原理的视频:
相关主题:
Why is this JavaScript page redirect so slow?
通过我的扩展,我想 "block" 一些网站 url 并重定向到我想要的一个 url 每当用户试图加入被阻止的 url 时。
假设我想 "ban" facebook.com 如果有人试图去 facebook.com ... firefox 插件应该将他重定向到 www.google.com.
我这里有这个代码
============================================= ==================================
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.facebook.com'
];
var redir_obj = {
'www.google.com': 'data:text,' + escape('url_blocked that would have went to google')
}
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.toLowerCase();
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(redir_obj[urls_block[i]], 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)
break;
}
}
},
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();
}
}
============================================= =====================
但我不知道如何让它工作,即使它是将 "facebook" 重定向到 "google"
的正确代码有人可以帮我解决这个问题,告诉我如何将它打包为 firefox 扩展吗???
非常感谢您花时间阅读。
此处发布了演示其工作原理的视频:
相关主题:
Why is this JavaScript page redirect so slow?