Skip to content
Snippets Groups Projects
Commit 65ceb1f6 authored by henry's avatar henry Committed by Beatriz Rizental
Browse files

TB 42110: Add TorUIUtils module for common tor component methods.

parent 727de9af
Branches
Tags
1 merge request!1507Rebase Tor Browser onto 136.0a1
......@@ -83,6 +83,7 @@ ChromeUtils.defineESModuleGetters(this, {
"resource:///modules/firefox-view-tabs-setup-manager.sys.mjs",
TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.sys.mjs",
ToolbarContextMenu: "resource:///modules/ToolbarContextMenu.sys.mjs",
TorUIUtils: "resource:///modules/TorUIUtils.sys.mjs",
TranslationsParent: "resource://gre/actors/TranslationsParent.sys.mjs",
UITour: "resource:///modules/UITour.sys.mjs",
UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs",
......
......@@ -268,5 +268,6 @@
"BrowserSearch",
"SelectableProfileService",
"SecurityLevelButton",
"NewIdentityButton"
"NewIdentityButton",
"TorUIUtils"
]
/**
* Common methods for tor UI components.
*/
export const TorUIUtils = {
/**
* Shorten the given address if it is an onion address.
*
* @param {string} address - The address to shorten.
*
* @returns {string} The shortened form of the address, or the address itself
* if it was not shortened.
*/
shortenOnionAddress(address) {
if (
// Only shorten ".onion" addresses.
!address.endsWith(".onion") ||
// That are not "onion" aliases.
address.endsWith(".tor.onion") ||
// And are long.
address.length <= 21
) {
return address;
}
return `${address.slice(0, 6)}${address.slice(-12)}`;
},
};
......@@ -138,6 +138,7 @@ EXTRA_JS_MODULES += [
"SelectionChangedMenulist.sys.mjs",
"SiteDataManager.sys.mjs",
"SitePermissions.sys.mjs",
"TorUIUtils.sys.mjs",
"TransientPrefs.sys.mjs",
"URILoadingHelper.sys.mjs",
"webrtcUI.sys.mjs",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment