fck-honey 0.3.1 → 0.3.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
@@ -41,3 +41,9 @@ window.fckHoney.listen((warn, el) => {
41
41
  // Set removeHoney to false if you want to keep the Honey element for some reason.
42
42
  }, { removeHoney: false });
43
43
  ```
44
+
45
+ ```js
46
+ window.fckHoney.listen((warn) => {
47
+ // Stop observing if nothing is detected within 10 seconds.
48
+ }, { unbindAfterSeconds: 10 });
49
+ ```
@@ -83,19 +83,12 @@ function looksLikeTargetDiv(el, zNearMax, uuidGate, debug) {
83
83
  console.log("+++ match", el);
84
84
  return true;
85
85
  }
86
- function scanElement(el, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn) {
86
+ function scanElement(el, seen, zNearMax, uuidGate, debug, handleMatch) {
87
87
  var _a;
88
88
  if (el instanceof HTMLDivElement && el.matches(TARGET_SELECTOR)) {
89
89
  if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate, debug)) {
90
90
  seen.push(el);
91
- if (removeHoney && el.parentNode)
92
- el.parentNode.removeChild(el);
93
- if (removeHoney) {
94
- onMatch(warn);
95
- }
96
- else {
97
- onMatch(warn, el);
98
- }
91
+ handleMatch(el);
99
92
  }
100
93
  }
101
94
  var divs = (_a = el.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(el, TARGET_SELECTOR);
@@ -105,14 +98,7 @@ function scanElement(el, seen, zNearMax, uuidGate, debug, removeHoney, onMatch,
105
98
  var d = divs[i];
106
99
  if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate, debug)) {
107
100
  seen.push(d);
108
- if (removeHoney && d.parentNode)
109
- d.parentNode.removeChild(d);
110
- if (removeHoney) {
111
- onMatch(warn);
112
- }
113
- else {
114
- onMatch(warn, d);
115
- }
101
+ handleMatch(d);
116
102
  }
117
103
  }
118
104
  }
@@ -124,8 +110,29 @@ export function startHoneyOverlayObserver(options) {
124
110
  var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
125
111
  var debug = (_c = options.debug) !== null && _c !== void 0 ? _c : false;
126
112
  var removeHoney = (_d = options.removeHoney) !== null && _d !== void 0 ? _d : true;
113
+ var unbindAfterSeconds = options.unbindAfterSeconds;
127
114
  var warn = function (message) { return showOverlay(message); };
128
115
  var onMatch = (_e = options.onMatch) !== null && _e !== void 0 ? _e : (function () { });
116
+ var matched = false;
117
+ var unbindTimer;
118
+ var handleMatch = function (el) {
119
+ matched = true;
120
+ if (typeof unbindTimer === "number") {
121
+ clearTimeout(unbindTimer);
122
+ unbindTimer = undefined;
123
+ }
124
+ if (removeHoney && el.parentNode)
125
+ el.parentNode.removeChild(el);
126
+ if (removeHoney) {
127
+ onMatch(warn);
128
+ }
129
+ else {
130
+ onMatch(warn, el);
131
+ }
132
+ };
133
+ // Greedy, page-wide observer: Honey overlays can be inserted late, moved,
134
+ // or have z-index applied after insertion. We watch all DOM changes so we
135
+ // can catch the element no matter when it appears or how it's styled.
129
136
  var mo = new MutationObserver(function (mutations) {
130
137
  for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
131
138
  var m = mutations_1[_i];
@@ -142,17 +149,17 @@ export function startHoneyOverlayObserver(options) {
142
149
  for (var i = 0; i < m.addedNodes.length; i += 1) {
143
150
  var node = m.addedNodes[i];
144
151
  if (node.nodeType === Node.ELEMENT_NODE) {
145
- scanElement(node, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
152
+ scanElement(node, seen, zNearMax, uuidGate, debug, handleMatch);
146
153
  }
147
154
  }
148
155
  }
149
156
  if (m.target instanceof Element) {
150
- scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
157
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, handleMatch);
151
158
  }
152
159
  }
153
160
  else if (m.type === "attributes") {
154
161
  if (m.target instanceof Element) {
155
- scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
162
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, handleMatch);
156
163
  }
157
164
  }
158
165
  }
@@ -163,9 +170,21 @@ export function startHoneyOverlayObserver(options) {
163
170
  attributes: true,
164
171
  attributeFilter: ["style", "class", "id"]
165
172
  });
166
- scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
173
+ scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, handleMatch);
174
+ if (typeof unbindAfterSeconds === "number" && unbindAfterSeconds > 0) {
175
+ unbindTimer = window.setTimeout(function () {
176
+ if (!matched) {
177
+ mo.disconnect();
178
+ }
179
+ }, unbindAfterSeconds * 1000);
180
+ }
167
181
  return {
168
- stop: function () { return mo.disconnect(); }
182
+ stop: function () {
183
+ mo.disconnect();
184
+ if (typeof unbindTimer === "number") {
185
+ clearTimeout(unbindTimer);
186
+ }
187
+ }
169
188
  };
170
189
  }
171
190
  export function listen(onMatch, options) {
@@ -1,7 +1,6 @@
1
- import { listen, startHoneyOverlayObserver, version } from "./core";
1
+ import { listen, version } from "./core";
2
2
  if (typeof window !== "undefined") {
3
3
  window.fckHoney = window.fckHoney || {};
4
- window.fckHoney.startHoneyOverlayObserver = startHoneyOverlayObserver;
5
4
  window.fckHoney.listen = listen;
6
5
  window.fckHoney.version = version;
7
6
  }
@@ -1,2 +1,2 @@
1
1
  // Auto-generated from package.json. Do not edit by hand.
2
- export var VERSION = "0.3.1";
2
+ export var VERSION = "0.3.3";
package/dist/esm/core.js CHANGED
@@ -83,19 +83,12 @@ function looksLikeTargetDiv(el, zNearMax, uuidGate, debug) {
83
83
  console.log("+++ match", el);
84
84
  return true;
85
85
  }
86
- function scanElement(el, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn) {
86
+ function scanElement(el, seen, zNearMax, uuidGate, debug, handleMatch) {
87
87
  var _a;
88
88
  if (el instanceof HTMLDivElement && el.matches(TARGET_SELECTOR)) {
89
89
  if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate, debug)) {
90
90
  seen.push(el);
91
- if (removeHoney && el.parentNode)
92
- el.parentNode.removeChild(el);
93
- if (removeHoney) {
94
- onMatch(warn);
95
- }
96
- else {
97
- onMatch(warn, el);
98
- }
91
+ handleMatch(el);
99
92
  }
100
93
  }
101
94
  var divs = (_a = el.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(el, TARGET_SELECTOR);
@@ -105,14 +98,7 @@ function scanElement(el, seen, zNearMax, uuidGate, debug, removeHoney, onMatch,
105
98
  var d = divs[i];
106
99
  if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate, debug)) {
107
100
  seen.push(d);
108
- if (removeHoney && d.parentNode)
109
- d.parentNode.removeChild(d);
110
- if (removeHoney) {
111
- onMatch(warn);
112
- }
113
- else {
114
- onMatch(warn, d);
115
- }
101
+ handleMatch(d);
116
102
  }
117
103
  }
118
104
  }
@@ -124,8 +110,29 @@ export function startHoneyOverlayObserver(options) {
124
110
  var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
125
111
  var debug = (_c = options.debug) !== null && _c !== void 0 ? _c : false;
126
112
  var removeHoney = (_d = options.removeHoney) !== null && _d !== void 0 ? _d : true;
113
+ var unbindAfterSeconds = options.unbindAfterSeconds;
127
114
  var warn = function (message) { return showOverlay(message); };
128
115
  var onMatch = (_e = options.onMatch) !== null && _e !== void 0 ? _e : (function () { });
116
+ var matched = false;
117
+ var unbindTimer;
118
+ var handleMatch = function (el) {
119
+ matched = true;
120
+ if (typeof unbindTimer === "number") {
121
+ clearTimeout(unbindTimer);
122
+ unbindTimer = undefined;
123
+ }
124
+ if (removeHoney && el.parentNode)
125
+ el.parentNode.removeChild(el);
126
+ if (removeHoney) {
127
+ onMatch(warn);
128
+ }
129
+ else {
130
+ onMatch(warn, el);
131
+ }
132
+ };
133
+ // Greedy, page-wide observer: Honey overlays can be inserted late, moved,
134
+ // or have z-index applied after insertion. We watch all DOM changes so we
135
+ // can catch the element no matter when it appears or how it's styled.
129
136
  var mo = new MutationObserver(function (mutations) {
130
137
  for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
131
138
  var m = mutations_1[_i];
@@ -142,17 +149,17 @@ export function startHoneyOverlayObserver(options) {
142
149
  for (var i = 0; i < m.addedNodes.length; i += 1) {
143
150
  var node = m.addedNodes[i];
144
151
  if (node.nodeType === Node.ELEMENT_NODE) {
145
- scanElement(node, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
152
+ scanElement(node, seen, zNearMax, uuidGate, debug, handleMatch);
146
153
  }
147
154
  }
148
155
  }
149
156
  if (m.target instanceof Element) {
150
- scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
157
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, handleMatch);
151
158
  }
152
159
  }
153
160
  else if (m.type === "attributes") {
154
161
  if (m.target instanceof Element) {
155
- scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
162
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, handleMatch);
156
163
  }
157
164
  }
158
165
  }
@@ -163,9 +170,21 @@ export function startHoneyOverlayObserver(options) {
163
170
  attributes: true,
164
171
  attributeFilter: ["style", "class", "id"]
165
172
  });
166
- scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
173
+ scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, handleMatch);
174
+ if (typeof unbindAfterSeconds === "number" && unbindAfterSeconds > 0) {
175
+ unbindTimer = window.setTimeout(function () {
176
+ if (!matched) {
177
+ mo.disconnect();
178
+ }
179
+ }, unbindAfterSeconds * 1000);
180
+ }
167
181
  return {
168
- stop: function () { return mo.disconnect(); }
182
+ stop: function () {
183
+ mo.disconnect();
184
+ if (typeof unbindTimer === "number") {
185
+ clearTimeout(unbindTimer);
186
+ }
187
+ }
169
188
  };
170
189
  }
171
190
  export function listen(onMatch, options) {
@@ -1,2 +1,2 @@
1
1
  // Auto-generated from package.json. Do not edit by hand.
2
- export var VERSION = "0.3.1";
2
+ export var VERSION = "0.3.3";
@@ -1,6 +1,6 @@
1
1
  (function() {
2
2
  // dist/bundle-tmp/version.js
3
- var VERSION = "0.3.1";
3
+ var VERSION = "0.3.3";
4
4
 
5
5
  // dist/bundle-tmp/core.js
6
6
  var __assign = function() {
@@ -86,18 +86,12 @@
86
86
  console.log("+++ match", el);
87
87
  return true;
88
88
  }
89
- function scanElement(el, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn) {
89
+ function scanElement(el, seen, zNearMax, uuidGate, debug, handleMatch) {
90
90
  var _a;
91
91
  if (el instanceof HTMLDivElement && el.matches(TARGET_SELECTOR)) {
92
92
  if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate, debug)) {
93
93
  seen.push(el);
94
- if (removeHoney && el.parentNode)
95
- el.parentNode.removeChild(el);
96
- if (removeHoney) {
97
- onMatch(warn);
98
- } else {
99
- onMatch(warn, el);
100
- }
94
+ handleMatch(el);
101
95
  }
102
96
  }
103
97
  var divs = (_a = el.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(el, TARGET_SELECTOR);
@@ -107,13 +101,7 @@
107
101
  var d = divs[i];
108
102
  if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate, debug)) {
109
103
  seen.push(d);
110
- if (removeHoney && d.parentNode)
111
- d.parentNode.removeChild(d);
112
- if (removeHoney) {
113
- onMatch(warn);
114
- } else {
115
- onMatch(warn, d);
116
- }
104
+ handleMatch(d);
117
105
  }
118
106
  }
119
107
  }
@@ -127,11 +115,28 @@
127
115
  var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
128
116
  var debug = (_c = options.debug) !== null && _c !== void 0 ? _c : false;
129
117
  var removeHoney = (_d = options.removeHoney) !== null && _d !== void 0 ? _d : true;
118
+ var unbindAfterSeconds = options.unbindAfterSeconds;
130
119
  var warn = function(message) {
131
120
  return showOverlay(message);
132
121
  };
133
122
  var onMatch = (_e = options.onMatch) !== null && _e !== void 0 ? _e : (function() {
134
123
  });
124
+ var matched = false;
125
+ var unbindTimer;
126
+ var handleMatch = function(el) {
127
+ matched = true;
128
+ if (typeof unbindTimer === "number") {
129
+ clearTimeout(unbindTimer);
130
+ unbindTimer = void 0;
131
+ }
132
+ if (removeHoney && el.parentNode)
133
+ el.parentNode.removeChild(el);
134
+ if (removeHoney) {
135
+ onMatch(warn);
136
+ } else {
137
+ onMatch(warn, el);
138
+ }
139
+ };
135
140
  var mo = new MutationObserver(function(mutations) {
136
141
  for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
137
142
  var m = mutations_1[_i];
@@ -146,16 +151,16 @@
146
151
  for (var i = 0; i < m.addedNodes.length; i += 1) {
147
152
  var node = m.addedNodes[i];
148
153
  if (node.nodeType === Node.ELEMENT_NODE) {
149
- scanElement(node, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
154
+ scanElement(node, seen, zNearMax, uuidGate, debug, handleMatch);
150
155
  }
151
156
  }
152
157
  }
153
158
  if (m.target instanceof Element) {
154
- scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
159
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, handleMatch);
155
160
  }
156
161
  } else if (m.type === "attributes") {
157
162
  if (m.target instanceof Element) {
158
- scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
163
+ scanElement(m.target, seen, zNearMax, uuidGate, debug, handleMatch);
159
164
  }
160
165
  }
161
166
  }
@@ -166,10 +171,20 @@
166
171
  attributes: true,
167
172
  attributeFilter: ["style", "class", "id"]
168
173
  });
169
- scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
174
+ scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, handleMatch);
175
+ if (typeof unbindAfterSeconds === "number" && unbindAfterSeconds > 0) {
176
+ unbindTimer = window.setTimeout(function() {
177
+ if (!matched) {
178
+ mo.disconnect();
179
+ }
180
+ }, unbindAfterSeconds * 1e3);
181
+ }
170
182
  return {
171
183
  stop: function() {
172
- return mo.disconnect();
184
+ mo.disconnect();
185
+ if (typeof unbindTimer === "number") {
186
+ clearTimeout(unbindTimer);
187
+ }
173
188
  }
174
189
  };
175
190
  }
@@ -183,7 +198,6 @@
183
198
  // dist/bundle-tmp/global.js
184
199
  if (typeof window !== "undefined") {
185
200
  window.fckHoney = window.fckHoney || {};
186
- window.fckHoney.startHoneyOverlayObserver = startHoneyOverlayObserver;
187
201
  window.fckHoney.listen = listen;
188
202
  window.fckHoney.version = version;
189
203
  }
@@ -1,4 +1,4 @@
1
- export declare const version = "0.3.1";
1
+ export declare const version = "0.3.3";
2
2
  export type WarnCallback = (message: string) => () => void;
3
3
  export type MatchCallback = (warn: WarnCallback, el?: HTMLDivElement) => void;
4
4
  export interface ObserverOptions {
@@ -7,6 +7,7 @@ export interface ObserverOptions {
7
7
  zNearMax?: number;
8
8
  debug?: boolean;
9
9
  removeHoney?: boolean;
10
+ unbindAfterSeconds?: number;
10
11
  }
11
12
  export interface ObserverHandle {
12
13
  stop: () => void;
@@ -1 +1 @@
1
- export declare const VERSION = "0.3.1";
1
+ export declare const VERSION = "0.3.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fck-honey",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Detects Honey browser extension overlays for merchants.",
5
5
  "license": "MIT",
6
6
  "main": "dist/honey-detect.js",