fck-honey 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,10 @@ Open source lib for Merchants to detect if an end user has Honey browser extensi
19
19
 
20
20
  ## Usage (ESM)
21
21
 
22
+ ```sh
23
+ npm install fck-honey
24
+ ```
25
+
22
26
  ```js
23
27
  import { listen } from "fck-honey";
24
28
 
@@ -28,11 +32,3 @@ listen((el) => {
28
32
  console.log("Honey overlay detected:", el);
29
33
  });
30
34
  ```
31
-
32
- ## Local Dev
33
-
34
- ```sh
35
- npm run build
36
- ```
37
-
38
- Open `example/index.html` in your browser.
package/dist/esm/index.js CHANGED
@@ -11,9 +11,13 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  var DEFAULT_Z_NEAR_MAX = 2147480000;
13
13
  var UUIDISH_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
14
- function parseZIndex(cs) {
15
- var z = parseInt(cs.zIndex, 10);
16
- return isFinite(z) ? z : null;
14
+ var TARGET_SELECTOR = "div[id]";
15
+ function parseZIndex(cs, el) {
16
+ var computed = parseInt(cs.zIndex, 10);
17
+ if (isFinite(computed))
18
+ return computed;
19
+ var inline = parseInt(el.style.zIndex, 10);
20
+ return isFinite(inline) ? inline : null;
17
21
  }
18
22
  function looksLikeTargetDiv(el, zNearMax, uuidGate) {
19
23
  if (!el.id)
@@ -21,7 +25,7 @@ function looksLikeTargetDiv(el, zNearMax, uuidGate) {
21
25
  if (uuidGate && !UUIDISH_RE.test(el.id))
22
26
  return false;
23
27
  var cs = getComputedStyle(el);
24
- var z = parseZIndex(cs);
28
+ var z = parseZIndex(cs, el);
25
29
  if (z === null || z < zNearMax)
26
30
  return false;
27
31
  if (cs.display === "none")
@@ -30,17 +34,15 @@ function looksLikeTargetDiv(el, zNearMax, uuidGate) {
30
34
  return false;
31
35
  return true;
32
36
  }
33
- function checkNode(node, seen, zNearMax, uuidGate, onMatch) {
37
+ function scanElement(el, seen, zNearMax, uuidGate, onMatch) {
34
38
  var _a;
35
- if (!(node instanceof Element))
36
- return;
37
- if (node instanceof HTMLDivElement &&
38
- seen.indexOf(node) === -1 &&
39
- looksLikeTargetDiv(node, zNearMax, uuidGate)) {
40
- seen.push(node);
41
- onMatch(node);
39
+ if (el instanceof HTMLDivElement && el.matches(TARGET_SELECTOR)) {
40
+ if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate)) {
41
+ seen.push(el);
42
+ onMatch(el);
43
+ }
42
44
  }
43
- var divs = (_a = node.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(node, "div[id]");
45
+ var divs = (_a = el.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(el, TARGET_SELECTOR);
44
46
  if (!divs)
45
47
  return;
46
48
  for (var i = 0; i < divs.length; i += 1) {
@@ -57,26 +59,32 @@ export function startHoneyOverlayObserver(options) {
57
59
  var seen = [];
58
60
  var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
59
61
  var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
60
- var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function (el) {
61
- // Default: warn only, leaving response up to caller.
62
- console.warn("[honey-detect] matched near-max z-index div:", el);
63
- });
62
+ var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function () { });
64
63
  var mo = new MutationObserver(function (mutations) {
65
64
  for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
66
65
  var m = mutations_1[_i];
66
+ if (m.target === document.body || (m.target instanceof Node && document.body.contains(m.target))) {
67
+ console.log("+++ body mutation", m.type, m.target);
68
+ }
69
+ }
70
+ for (var _a = 0, mutations_2 = mutations; _a < mutations_2.length; _a++) {
71
+ var m = mutations_2[_a];
67
72
  if (m.type === "childList") {
68
- for (var i = 0; i < m.addedNodes.length; i += 1) {
69
- checkNode(m.addedNodes[i], seen, zNearMax, uuidGate, onMatch);
73
+ if (m.addedNodes.length) {
74
+ for (var i = 0; i < m.addedNodes.length; i += 1) {
75
+ var node = m.addedNodes[i];
76
+ if (node.nodeType === Node.ELEMENT_NODE) {
77
+ scanElement(node, seen, zNearMax, uuidGate, onMatch);
78
+ }
79
+ }
80
+ }
81
+ else if (m.target instanceof Element) {
82
+ scanElement(m.target, seen, zNearMax, uuidGate, onMatch);
70
83
  }
71
84
  }
72
85
  else if (m.type === "attributes") {
73
- var el = m.target;
74
- if (el instanceof HTMLDivElement &&
75
- el.id &&
76
- seen.indexOf(el) === -1 &&
77
- looksLikeTargetDiv(el, zNearMax, uuidGate)) {
78
- seen.push(el);
79
- onMatch(el);
86
+ if (m.target instanceof Element) {
87
+ scanElement(m.target, seen, zNearMax, uuidGate, onMatch);
80
88
  }
81
89
  }
82
90
  }
@@ -87,7 +95,7 @@ export function startHoneyOverlayObserver(options) {
87
95
  attributes: true,
88
96
  attributeFilter: ["style", "class", "id"]
89
97
  });
90
- checkNode(document.documentElement, seen, zNearMax, uuidGate, onMatch);
98
+ scanElement(document.documentElement, seen, zNearMax, uuidGate, onMatch);
91
99
  return {
92
100
  stop: function () { return mo.disconnect(); }
93
101
  };
@@ -12,9 +12,13 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  var DEFAULT_Z_NEAR_MAX = 2147480000;
14
14
  var UUIDISH_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
15
- function parseZIndex(cs) {
16
- var z = parseInt(cs.zIndex, 10);
17
- return isFinite(z) ? z : null;
15
+ var TARGET_SELECTOR = "div[id]";
16
+ function parseZIndex(cs, el) {
17
+ var computed = parseInt(cs.zIndex, 10);
18
+ if (isFinite(computed))
19
+ return computed;
20
+ var inline = parseInt(el.style.zIndex, 10);
21
+ return isFinite(inline) ? inline : null;
18
22
  }
19
23
  function looksLikeTargetDiv(el, zNearMax, uuidGate) {
20
24
  if (!el.id)
@@ -22,7 +26,7 @@ function looksLikeTargetDiv(el, zNearMax, uuidGate) {
22
26
  if (uuidGate && !UUIDISH_RE.test(el.id))
23
27
  return false;
24
28
  var cs = getComputedStyle(el);
25
- var z = parseZIndex(cs);
29
+ var z = parseZIndex(cs, el);
26
30
  if (z === null || z < zNearMax)
27
31
  return false;
28
32
  if (cs.display === "none")
@@ -31,17 +35,15 @@ function looksLikeTargetDiv(el, zNearMax, uuidGate) {
31
35
  return false;
32
36
  return true;
33
37
  }
34
- function checkNode(node, seen, zNearMax, uuidGate, onMatch) {
38
+ function scanElement(el, seen, zNearMax, uuidGate, onMatch) {
35
39
  var _a;
36
- if (!(node instanceof Element))
37
- return;
38
- if (node instanceof HTMLDivElement &&
39
- seen.indexOf(node) === -1 &&
40
- looksLikeTargetDiv(node, zNearMax, uuidGate)) {
41
- seen.push(node);
42
- onMatch(node);
40
+ if (el instanceof HTMLDivElement && el.matches(TARGET_SELECTOR)) {
41
+ if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate)) {
42
+ seen.push(el);
43
+ onMatch(el);
44
+ }
43
45
  }
44
- var divs = (_a = node.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(node, "div[id]");
46
+ var divs = (_a = el.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(el, TARGET_SELECTOR);
45
47
  if (!divs)
46
48
  return;
47
49
  for (var i = 0; i < divs.length; i += 1) {
@@ -58,26 +60,32 @@ function startHoneyOverlayObserver(options) {
58
60
  var seen = [];
59
61
  var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
60
62
  var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
61
- var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function (el) {
62
- // Default: warn only, leaving response up to caller.
63
- console.warn("[honey-detect] matched near-max z-index div:", el);
64
- });
63
+ var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function () { });
65
64
  var mo = new MutationObserver(function (mutations) {
66
65
  for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
67
66
  var m = mutations_1[_i];
67
+ if (m.target === document.body || (m.target instanceof Node && document.body.contains(m.target))) {
68
+ console.log("+++ body mutation", m.type, m.target);
69
+ }
70
+ }
71
+ for (var _a = 0, mutations_2 = mutations; _a < mutations_2.length; _a++) {
72
+ var m = mutations_2[_a];
68
73
  if (m.type === "childList") {
69
- for (var i = 0; i < m.addedNodes.length; i += 1) {
70
- checkNode(m.addedNodes[i], seen, zNearMax, uuidGate, onMatch);
74
+ if (m.addedNodes.length) {
75
+ for (var i = 0; i < m.addedNodes.length; i += 1) {
76
+ var node = m.addedNodes[i];
77
+ if (node.nodeType === Node.ELEMENT_NODE) {
78
+ scanElement(node, seen, zNearMax, uuidGate, onMatch);
79
+ }
80
+ }
81
+ }
82
+ else if (m.target instanceof Element) {
83
+ scanElement(m.target, seen, zNearMax, uuidGate, onMatch);
71
84
  }
72
85
  }
73
86
  else if (m.type === "attributes") {
74
- var el = m.target;
75
- if (el instanceof HTMLDivElement &&
76
- el.id &&
77
- seen.indexOf(el) === -1 &&
78
- looksLikeTargetDiv(el, zNearMax, uuidGate)) {
79
- seen.push(el);
80
- onMatch(el);
87
+ if (m.target instanceof Element) {
88
+ scanElement(m.target, seen, zNearMax, uuidGate, onMatch);
81
89
  }
82
90
  }
83
91
  }
@@ -88,7 +96,7 @@ function startHoneyOverlayObserver(options) {
88
96
  attributes: true,
89
97
  attributeFilter: ["style", "class", "id"]
90
98
  });
91
- checkNode(document.documentElement, seen, zNearMax, uuidGate, onMatch);
99
+ scanElement(document.documentElement, seen, zNearMax, uuidGate, onMatch);
92
100
  return {
93
101
  stop: function () { return mo.disconnect(); }
94
102
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fck-honey",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Detects Honey browser extension overlays for merchants.",
5
5
  "license": "MIT",
6
6
  "main": "dist/honey-detect.js",