tor-browser

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

url.js (710B)


      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 /* global ConditionBase */
      6 
      7 /**
      8 * URL condition
      9 */
     10 class ConditionUrl extends ConditionBase {
     11  constructor(factory, desc) {
     12    super(factory, desc);
     13  }
     14 
     15  check() {
     16    try {
     17      const pattern = new RegExp(String(this.desc?.pattern ?? ""));
     18      const url = String(this.factory?.context?.url ?? "");
     19      return pattern.test(url);
     20    } catch (e) {
     21      console.warn("Unable to parse the regexp", this.desc?.pattern, e);
     22      return false;
     23    }
     24  }
     25 }
     26 
     27 globalThis.ConditionUrl = ConditionUrl;