tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

css-changes.js (1128B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 class CSSChangeWatcher {
      8  constructor() {
      9    this.onTrackChange = this.onTrackChange.bind(this);
     10  }
     11 
     12  #targetActor;
     13 
     14  /**
     15   * Start watching for all css changes related to a given Target Actor.
     16   *
     17   * @param TargetActor targetActor
     18   *        The target actor from which we should observe css changes.
     19   * @param Object options
     20   *        Dictionary object with following attributes:
     21   *        - onAvailable: mandatory function
     22   *          This will be called for each resource.
     23   */
     24  async watch(targetActor, { onAvailable }) {
     25    this.#targetActor = targetActor;
     26    this.onAvailable = onAvailable;
     27    this.#targetActor.on("track-css-change", this.onTrackChange);
     28  }
     29 
     30  onTrackChange(change) {
     31    this.onAvailable([change]);
     32  }
     33 
     34  destroy() {
     35    this.#targetActor.off("track-css-change", this.onTrackChange);
     36    this.#targetActor = null;
     37  }
     38 }
     39 
     40 module.exports = CSSChangeWatcher;