fck-honey 0.1.3 → 0.1.4

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
@@ -7,7 +7,7 @@ Open source lib for Merchants to detect if an end user has Honey browser extensi
7
7
  ## Usage (Browser Global)
8
8
 
9
9
  ```html
10
- <script src="https://cdn.jsdelivr.net/npm/fck-honey@0.1/dist/honey-detect.min.js"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/fck-honey"></script>
11
11
  <script>
12
12
  window.fckHoney.listen((el) => {
13
13
  // Decide how you want to handle this.
package/dist/esm/index.js CHANGED
@@ -19,25 +19,42 @@ function parseZIndex(cs, el) {
19
19
  var inline = parseInt(el.style.zIndex, 10);
20
20
  return isFinite(inline) ? inline : null;
21
21
  }
22
- function looksLikeTargetDiv(el, zNearMax, uuidGate) {
23
- if (!el.id)
22
+ function looksLikeTargetDiv(el, zNearMax, uuidGate, debug) {
23
+ if (!el.id) {
24
+ if (debug)
25
+ console.log("+++ reject: no id", el);
24
26
  return false;
25
- if (uuidGate && !UUIDISH_RE.test(el.id))
27
+ }
28
+ if (uuidGate && !UUIDISH_RE.test(el.id)) {
29
+ if (debug)
30
+ console.log("+++ reject: uuid", el.id);
26
31
  return false;
32
+ }
27
33
  var cs = getComputedStyle(el);
28
34
  var z = parseZIndex(cs, el);
29
- if (z === null || z < zNearMax)
35
+ if (z === null || z < zNearMax) {
36
+ if (debug)
37
+ console.log("+++ reject: z-index", z, cs.zIndex, el.style.zIndex, el);
30
38
  return false;
31
- if (cs.display === "none")
39
+ }
40
+ if (cs.display === "none") {
41
+ if (debug)
42
+ console.log("+++ reject: display none", el);
32
43
  return false;
33
- if (el.shadowRoot)
44
+ }
45
+ if (el.shadowRoot) {
46
+ if (debug)
47
+ console.log("+++ reject: shadowRoot", el);
34
48
  return false;
49
+ }
50
+ if (debug)
51
+ console.log("+++ match", el);
35
52
  return true;
36
53
  }
37
- function scanElement(el, seen, zNearMax, uuidGate, onMatch) {
54
+ function scanElement(el, seen, zNearMax, uuidGate, debug, onMatch) {
38
55
  var _a;
39
56
  if (el instanceof HTMLDivElement && el.matches(TARGET_SELECTOR)) {
40
- if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate)) {
57
+ if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate, debug)) {
41
58
  seen.push(el);
42
59
  onMatch(el);
43
60
  }
@@ -47,23 +64,25 @@ function scanElement(el, seen, zNearMax, uuidGate, onMatch) {
47
64
  return;
48
65
  for (var i = 0; i < divs.length; i += 1) {
49
66
  var d = divs[i];
50
- if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate)) {
67
+ if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate, debug)) {
51
68
  seen.push(d);
52
69
  onMatch(d);
53
70
  }
54
71
  }
55
72
  }
56
73
  export function startHoneyOverlayObserver(options) {
57
- var _a, _b, _c;
74
+ var _a, _b, _c, _d;
58
75
  if (options === void 0) { options = {}; }
59
76
  var seen = [];
60
77
  var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
61
78
  var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
62
- var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function () { });
79
+ var debug = (_c = options.debug) !== null && _c !== void 0 ? _c : false;
80
+ var onMatch = (_d = options.onMatch) !== null && _d !== void 0 ? _d : (function () { });
63
81
  var mo = new MutationObserver(function (mutations) {
64
82
  for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
65
83
  var m = mutations_1[_i];
66
- if (m.target === document.body || (m.target instanceof Node && document.body.contains(m.target))) {
84
+ if (debug &&
85
+ (m.target === document.body || (m.target instanceof Node && document.body.contains(m.target)))) {
67
86
  console.log("+++ body mutation", m.type, m.target);
68
87
  }
69
88
  }
@@ -74,17 +93,17 @@ export function startHoneyOverlayObserver(options) {
74
93
  for (var i = 0; i < m.addedNodes.length; i += 1) {
75
94
  var node = m.addedNodes[i];
76
95
  if (node.nodeType === Node.ELEMENT_NODE) {
77
- scanElement(node, seen, zNearMax, uuidGate, onMatch);
96
+ scanElement(node, seen, zNearMax, uuidGate, debug, onMatch);
78
97
  }
79
98
  }
80
99
  }
81
- else if (m.target instanceof Element) {
82
- scanElement(m.target, seen, zNearMax, uuidGate, onMatch);
100
+ if (m.target instanceof Element) {
101
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, onMatch);
83
102
  }
84
103
  }
85
104
  else if (m.type === "attributes") {
86
105
  if (m.target instanceof Element) {
87
- scanElement(m.target, seen, zNearMax, uuidGate, onMatch);
106
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, onMatch);
88
107
  }
89
108
  }
90
109
  }
@@ -95,7 +114,7 @@ export function startHoneyOverlayObserver(options) {
95
114
  attributes: true,
96
115
  attributeFilter: ["style", "class", "id"]
97
116
  });
98
- scanElement(document.documentElement, seen, zNearMax, uuidGate, onMatch);
117
+ scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, onMatch);
99
118
  return {
100
119
  stop: function () { return mo.disconnect(); }
101
120
  };
@@ -20,25 +20,42 @@ function parseZIndex(cs, el) {
20
20
  var inline = parseInt(el.style.zIndex, 10);
21
21
  return isFinite(inline) ? inline : null;
22
22
  }
23
- function looksLikeTargetDiv(el, zNearMax, uuidGate) {
24
- if (!el.id)
23
+ function looksLikeTargetDiv(el, zNearMax, uuidGate, debug) {
24
+ if (!el.id) {
25
+ if (debug)
26
+ console.log("+++ reject: no id", el);
25
27
  return false;
26
- if (uuidGate && !UUIDISH_RE.test(el.id))
28
+ }
29
+ if (uuidGate && !UUIDISH_RE.test(el.id)) {
30
+ if (debug)
31
+ console.log("+++ reject: uuid", el.id);
27
32
  return false;
33
+ }
28
34
  var cs = getComputedStyle(el);
29
35
  var z = parseZIndex(cs, el);
30
- if (z === null || z < zNearMax)
36
+ if (z === null || z < zNearMax) {
37
+ if (debug)
38
+ console.log("+++ reject: z-index", z, cs.zIndex, el.style.zIndex, el);
31
39
  return false;
32
- if (cs.display === "none")
40
+ }
41
+ if (cs.display === "none") {
42
+ if (debug)
43
+ console.log("+++ reject: display none", el);
33
44
  return false;
34
- if (el.shadowRoot)
45
+ }
46
+ if (el.shadowRoot) {
47
+ if (debug)
48
+ console.log("+++ reject: shadowRoot", el);
35
49
  return false;
50
+ }
51
+ if (debug)
52
+ console.log("+++ match", el);
36
53
  return true;
37
54
  }
38
- function scanElement(el, seen, zNearMax, uuidGate, onMatch) {
55
+ function scanElement(el, seen, zNearMax, uuidGate, debug, onMatch) {
39
56
  var _a;
40
57
  if (el instanceof HTMLDivElement && el.matches(TARGET_SELECTOR)) {
41
- if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate)) {
58
+ if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate, debug)) {
42
59
  seen.push(el);
43
60
  onMatch(el);
44
61
  }
@@ -48,23 +65,25 @@ function scanElement(el, seen, zNearMax, uuidGate, onMatch) {
48
65
  return;
49
66
  for (var i = 0; i < divs.length; i += 1) {
50
67
  var d = divs[i];
51
- if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate)) {
68
+ if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate, debug)) {
52
69
  seen.push(d);
53
70
  onMatch(d);
54
71
  }
55
72
  }
56
73
  }
57
74
  function startHoneyOverlayObserver(options) {
58
- var _a, _b, _c;
75
+ var _a, _b, _c, _d;
59
76
  if (options === void 0) { options = {}; }
60
77
  var seen = [];
61
78
  var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
62
79
  var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
63
- var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function () { });
80
+ var debug = (_c = options.debug) !== null && _c !== void 0 ? _c : false;
81
+ var onMatch = (_d = options.onMatch) !== null && _d !== void 0 ? _d : (function () { });
64
82
  var mo = new MutationObserver(function (mutations) {
65
83
  for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
66
84
  var m = mutations_1[_i];
67
- if (m.target === document.body || (m.target instanceof Node && document.body.contains(m.target))) {
85
+ if (debug &&
86
+ (m.target === document.body || (m.target instanceof Node && document.body.contains(m.target)))) {
68
87
  console.log("+++ body mutation", m.type, m.target);
69
88
  }
70
89
  }
@@ -75,17 +94,17 @@ function startHoneyOverlayObserver(options) {
75
94
  for (var i = 0; i < m.addedNodes.length; i += 1) {
76
95
  var node = m.addedNodes[i];
77
96
  if (node.nodeType === Node.ELEMENT_NODE) {
78
- scanElement(node, seen, zNearMax, uuidGate, onMatch);
97
+ scanElement(node, seen, zNearMax, uuidGate, debug, onMatch);
79
98
  }
80
99
  }
81
100
  }
82
- else if (m.target instanceof Element) {
83
- scanElement(m.target, seen, zNearMax, uuidGate, onMatch);
101
+ if (m.target instanceof Element) {
102
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, onMatch);
84
103
  }
85
104
  }
86
105
  else if (m.type === "attributes") {
87
106
  if (m.target instanceof Element) {
88
- scanElement(m.target, seen, zNearMax, uuidGate, onMatch);
107
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, onMatch);
89
108
  }
90
109
  }
91
110
  }
@@ -96,7 +115,7 @@ function startHoneyOverlayObserver(options) {
96
115
  attributes: true,
97
116
  attributeFilter: ["style", "class", "id"]
98
117
  });
99
- scanElement(document.documentElement, seen, zNearMax, uuidGate, onMatch);
118
+ scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, onMatch);
100
119
  return {
101
120
  stop: function () { return mo.disconnect(); }
102
121
  };
@@ -3,6 +3,7 @@ export interface ObserverOptions {
3
3
  onMatch?: MatchCallback;
4
4
  uuidGate?: boolean;
5
5
  zNearMax?: number;
6
+ debug?: boolean;
6
7
  }
7
8
  export interface ObserverHandle {
8
9
  stop: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fck-honey",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Detects Honey browser extension overlays for merchants.",
5
5
  "license": "MIT",
6
6
  "main": "dist/honey-detect.js",