aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/utils/injected-code.js
diff options
context:
space:
mode:
authorArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 11:35:08 +0530
committerArpit Chakladar <arpitchakladar+git@gmail.com>2026-07-13 11:35:08 +0530
commit600c337b1cdc884aebf59083eb57b178b43441ce (patch)
treed1f3cb7eb1020bcdcd66d9dbf0279f79d5856332 /config/webpack/utils/injected-code.js
parent98e7019c61ea0ffe344ef7ce809d38d62254a9fc (diff)
downloadbanglar-bhumi-utils-600c337b1cdc884aebf59083eb57b178b43441ce.tar.gz
banglar-bhumi-utils-600c337b1cdc884aebf59083eb57b178b43441ce.zip
docs: added some documentation comments to all functions
Diffstat (limited to 'config/webpack/utils/injected-code.js')
-rw-r--r--config/webpack/utils/injected-code.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/config/webpack/utils/injected-code.js b/config/webpack/utils/injected-code.js
index a2884f6..2b8f750 100644
--- a/config/webpack/utils/injected-code.js
+++ b/config/webpack/utils/injected-code.js
@@ -1,5 +1,12 @@
import crypto from "crypto";
+/**
+ * Computes an MD5 hash suffix (last 16 hex characters) for a given URL.
+ * Used to create unique attribute names for injected script data.
+ *
+ * @param {string} url - The URL to hash.
+ * @returns {string} A 16-character hex hash.
+ */
const getHash = url =>
crypto
.createHash("md5")
@@ -7,6 +14,15 @@ const getHash = url =>
.digest("hex")
.substring(16);
+/**
+ * Transforms extension asset URL placeholders (`"$l{ url }l$"`) in the
+ * compiled JavaScript into `document.currentScript.getAttribute("data-<hash>")`
+ * lookups. The mapping of hashes to resolved `chrome.runtime.getURL()` calls
+ * is returned separately so the injector script can embed it as data attributes.
+ *
+ * @param {string} code - The compiled JavaScript bundle.
+ * @returns {[string, string]} A tuple of [transformedCode, extensionAssetsJSON].
+ */
export const getInjectedCode = code => {
const extensionAssets = {};
let i = 0;