tor-browser

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

TorUIUtils.sys.mjs (679B)


      1 /**
      2 * Common methods for tor UI components.
      3 */
      4 export const TorUIUtils = {
      5  /**
      6   * Shorten the given address if it is an onion address.
      7   *
      8   * @param {string} address - The address to shorten.
      9   *
     10   * @returns {string} The shortened form of the address, or the address itself
     11   *   if it was not shortened.
     12   */
     13  shortenOnionAddress(address) {
     14    if (
     15      // Only shorten ".onion" addresses.
     16      !address.endsWith(".onion") ||
     17      // That are not "onion" aliases.
     18      address.endsWith(".tor.onion") ||
     19      // And are long.
     20      address.length <= 21
     21    ) {
     22      return address;
     23    }
     24    return `${address.slice(0, 6)}${address.slice(-12)}`;
     25  },
     26 };