javascript - Firefox SDK | Block Loading of Images w.r.t. Domain -


One of my earliest Firefox adsense functionality will be blocked by loading images based on those 2 criteria:

  • IMG's URL or path includes specific words (regx);
  • I have restored this feature on WebRequest in Google Chrome extension (see code below).

    background.js [Chrome Extension]

      var regex = '/ example | Example 2 / G '; // - Block Request Function Block Request (Details) {If (Type === 'Image' & Description.value Split (': //') .pop () .mail (regex)) {Return { Cancel: true}; }} // - Apply Blocking FunctionBlocking (type) {if (chrome.webRequest.onBeforeRequest.hasListener (type)) chrome.webRequest.onBeforeRequest.removeListener (type); Chrome.webRequest.onBeforeRequest.addListener (type, {urls: ['https: //*.example.com/proxy/*']}, ['blocked']); } // block function block tracking (a) {if (a) {apply blocking (blockerext); }}  

    I'm trying to replicate it in Firefox, resting on SDK. And it seems that I have to register a supervisor and have to use XPCOM, however, I have some difficulties finding more documentation about accessing the requested file and URL types to access the Firefox API Are there. Any help appreciated ...

    main.js [Firefox Extension]

      var {cc, ci} = is required ('Chrome'), Regex = '/ example | Example 2 / G '; Var ApplyBlocking = {Observation: Function (subject, subject) {if (subject === 'http-on-modify-request') {/ *} Get the Observer () (Return CC ['@ mozilla.org/observer- service.1'] .getService (CINSOBS server service);}, register: function () {this.observerService.addObserver (this , 'Http-on-modify-request', incorrect);}, unregistered: function () {this.observerService.removeObserver (this, 'http-on-modify-request');}}; // block function block tracking (A) {If (A) {ApplyBlocking.register ();}}  

    What can I implement at the end, if it is of interest to others, people can ...

      var {cc, ci, CR} = Required ('chrome'), regex = '/ example | example2 / gi'; Var ApplyBlocking = {Observation: function (subject, subject) {if (subject === 'http-on-modify-request' ) {Var channel = subject.QueryInterface (Ci.nsIHttpChannel); If (channel.originalURI.spec.match ('example.com/') & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp & amp; amp; amp; Amp; amp; amp; amp; amp; amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp; Amp; SriginalURLSpec.split (': //') .pop () .mail (regex)) {channel.cancel Cr.NS_BINDING_ABORTED); }}}, Receive supervisor (service) (return CC ['@ mozilla.org / poster service; 1] .get service (CINSOBS server service);}, register: function () {this.observerService.addObserver (' Http-on-modify-request ', incorrect);}, unregistered: function () {this.observerService.removeObserver (this,' http-on-modify-request ');}}; // block function block tracking ) {If (A) {try {ApplyBlocking.register ()); } Hold (e) {}} {try} {ApplyBlocking.unregister (); } Hold (e) {}}}  

    Comments

    Popular posts from this blog

    import - Python ImportError: No module named wmi -

    Editing Python Class in Shell and SQLAlchemy -

    c# - MySQL Parameterized Select Query joining tables issue -