One feature of my upcoming Firefox addon will be blocking image downloads based on these two criteria:
- IMG comes from a specific (additional) domain (for example, * .example.com);
- URL or IMG path contains specific words (RegEx);
I developed this feature in the Google Chrome extension based on WebRequest (see code below).
background.js [Chrome extension]
var regex = '/example|example2/gi';
function blockRequest(details) {
if( details.type === 'image' && details.url.split('://').pop().match(regex) ) {
return {cancel: true};
}
}
function applyBlocking(type) {
if(chrome.webRequest.onBeforeRequest.hasListener(type))
chrome.webRequest.onBeforeRequest.removeListener(type);
chrome.webRequest.onBeforeRequest.addListener(type, {
urls: [
'https://*.example.com/proxy/*'
]}, ['blocking']);
}
function blockTracking(a) {
if(a) {
applyBlocking(blockRequest);
}
}
Firefox, SDK. , , XPCOM. , , URL-, API- Firefox. ...
main.js [ Firefox]
var { Cc, Ci } = require('chrome'),
regex = '/example|example2/gi';
var ApplyBlocking = {
observe: function(subject, topic) {
if (topic === 'http-on-modify-request') {
}
},
get observerService() {
return Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
},
register: function() {
this.observerService.addObserver(this, 'http-on-modify-request', false);
},
unregister: function() {
this.observerService.removeObserver(this, 'http-on-modify-request');
}
};
function blockTracking(a) {
if(a) {
ApplyBlocking.register();
}
}