fck-honey 0.1.0 → 0.1.2

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 ADDED
@@ -0,0 +1,34 @@
1
+ # fck-honey
2
+ Open source lib for Merchants to detect if an end user has Honey browser extension installed
3
+
4
+ ## Inspiration
5
+ [MegaLag exposed Honey as a scam](https://www.youtube.com/watch?v=wwB3FmbcC88)
6
+
7
+ ## Usage (Browser Global)
8
+
9
+ ```html
10
+ <script src="https://cdn.jsdelivr.net/npm/fck-honey@0.1/dist/honey-detect.min.js"></script>
11
+ <script>
12
+ window.fckHoney.listen((el) => {
13
+ // Decide how you want to handle this.
14
+ // Example: pause checkout and notify the user.
15
+ console.log("Honey overlay detected:", el);
16
+ });
17
+ </script>
18
+ ```
19
+
20
+ ## Usage (ESM)
21
+
22
+ ```sh
23
+ npm install fck-honey
24
+ ```
25
+
26
+ ```js
27
+ import { listen } from "fck-honey";
28
+
29
+ listen((el) => {
30
+ // Decide how you want to handle this.
31
+ // Example: pause checkout and notify the user.
32
+ console.log("Honey overlay detected:", el);
33
+ });
34
+ ```
@@ -0,0 +1,95 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var DEFAULT_Z_NEAR_MAX = 2147480000;
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;
17
+ }
18
+ function looksLikeTargetDiv(el, zNearMax, uuidGate) {
19
+ if (!el.id)
20
+ return false;
21
+ if (uuidGate && !UUIDISH_RE.test(el.id))
22
+ return false;
23
+ var cs = getComputedStyle(el);
24
+ var z = parseZIndex(cs);
25
+ if (z === null || z < zNearMax)
26
+ return false;
27
+ if (cs.display === "none")
28
+ return false;
29
+ if (el.shadowRoot)
30
+ return false;
31
+ return true;
32
+ }
33
+ function checkNode(node, seen, zNearMax, uuidGate, onMatch) {
34
+ 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);
42
+ }
43
+ var divs = (_a = node.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(node, "div[id]");
44
+ if (!divs)
45
+ return;
46
+ for (var i = 0; i < divs.length; i += 1) {
47
+ var d = divs[i];
48
+ if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate)) {
49
+ seen.push(d);
50
+ onMatch(d);
51
+ }
52
+ }
53
+ }
54
+ export function startHoneyOverlayObserver(options) {
55
+ var _a, _b, _c;
56
+ if (options === void 0) { options = {}; }
57
+ var seen = [];
58
+ var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
59
+ var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
60
+ var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function () { });
61
+ var mo = new MutationObserver(function (mutations) {
62
+ for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
63
+ var m = mutations_1[_i];
64
+ if (m.type === "childList") {
65
+ for (var i = 0; i < m.addedNodes.length; i += 1) {
66
+ checkNode(m.addedNodes[i], seen, zNearMax, uuidGate, onMatch);
67
+ }
68
+ }
69
+ else if (m.type === "attributes") {
70
+ var el = m.target;
71
+ if (el instanceof HTMLDivElement &&
72
+ el.id &&
73
+ seen.indexOf(el) === -1 &&
74
+ looksLikeTargetDiv(el, zNearMax, uuidGate)) {
75
+ seen.push(el);
76
+ onMatch(el);
77
+ }
78
+ }
79
+ }
80
+ });
81
+ mo.observe(document.documentElement, {
82
+ subtree: true,
83
+ childList: true,
84
+ attributes: true,
85
+ attributeFilter: ["style", "class", "id"]
86
+ });
87
+ checkNode(document.documentElement, seen, zNearMax, uuidGate, onMatch);
88
+ return {
89
+ stop: function () { return mo.disconnect(); }
90
+ };
91
+ }
92
+ export function listen(onMatch, options) {
93
+ if (options === void 0) { options = {}; }
94
+ return startHoneyOverlayObserver(__assign(__assign({}, options), { onMatch: onMatch }));
95
+ }
@@ -10,100 +10,92 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
- var fckHoney;
14
- (function (fckHoney) {
15
- var DEFAULT_Z_NEAR_MAX = 2147480000;
16
- var UUIDISH_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
17
- function parseZIndex(cs) {
18
- var z = parseInt(cs.zIndex, 10);
19
- return isFinite(z) ? z : null;
20
- }
21
- function looksLikeTargetDiv(el, zNearMax, uuidGate) {
22
- if (!el.id)
23
- return false;
24
- if (uuidGate && !UUIDISH_RE.test(el.id))
25
- return false;
26
- var cs = getComputedStyle(el);
27
- var z = parseZIndex(cs);
28
- if (z === null || z < zNearMax)
29
- return false;
30
- if (cs.display === "none")
31
- return false;
32
- if (el.shadowRoot)
33
- return false;
34
- return true;
13
+ var DEFAULT_Z_NEAR_MAX = 2147480000;
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;
18
+ }
19
+ function looksLikeTargetDiv(el, zNearMax, uuidGate) {
20
+ if (!el.id)
21
+ return false;
22
+ if (uuidGate && !UUIDISH_RE.test(el.id))
23
+ return false;
24
+ var cs = getComputedStyle(el);
25
+ var z = parseZIndex(cs);
26
+ if (z === null || z < zNearMax)
27
+ return false;
28
+ if (cs.display === "none")
29
+ return false;
30
+ if (el.shadowRoot)
31
+ return false;
32
+ return true;
33
+ }
34
+ function checkNode(node, seen, zNearMax, uuidGate, onMatch) {
35
+ 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);
35
43
  }
36
- function checkNode(node, seen, zNearMax, uuidGate, onMatch) {
37
- var _a;
38
- if (!(node instanceof Element))
39
- return;
40
- if (node instanceof HTMLDivElement &&
41
- seen.indexOf(node) === -1 &&
42
- looksLikeTargetDiv(node, zNearMax, uuidGate)) {
43
- seen.push(node);
44
- onMatch(node);
45
- }
46
- var divs = (_a = node.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(node, "div[id]");
47
- if (!divs)
48
- return;
49
- for (var i = 0; i < divs.length; i += 1) {
50
- var d = divs[i];
51
- if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate)) {
52
- seen.push(d);
53
- onMatch(d);
54
- }
44
+ var divs = (_a = node.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(node, "div[id]");
45
+ if (!divs)
46
+ return;
47
+ for (var i = 0; i < divs.length; i += 1) {
48
+ var d = divs[i];
49
+ if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate)) {
50
+ seen.push(d);
51
+ onMatch(d);
55
52
  }
56
53
  }
57
- function startHoneyOverlayObserver(options) {
58
- var _a, _b, _c;
59
- if (options === void 0) { options = {}; }
60
- var seen = [];
61
- var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
62
- var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
63
- var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function (el) {
64
- // Default: warn only, leaving response up to caller.
65
- console.warn("[honey-detect] matched near-max z-index div:", el);
66
- });
67
- var mo = new MutationObserver(function (mutations) {
68
- for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
69
- var m = mutations_1[_i];
70
- if (m.type === "childList") {
71
- for (var i = 0; i < m.addedNodes.length; i += 1) {
72
- checkNode(m.addedNodes[i], seen, zNearMax, uuidGate, onMatch);
73
- }
54
+ }
55
+ function startHoneyOverlayObserver(options) {
56
+ var _a, _b, _c;
57
+ if (options === void 0) { options = {}; }
58
+ var seen = [];
59
+ var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
60
+ var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
61
+ var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function () { });
62
+ var mo = new MutationObserver(function (mutations) {
63
+ for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
64
+ var m = mutations_1[_i];
65
+ if (m.type === "childList") {
66
+ for (var i = 0; i < m.addedNodes.length; i += 1) {
67
+ checkNode(m.addedNodes[i], seen, zNearMax, uuidGate, onMatch);
74
68
  }
75
- else if (m.type === "attributes") {
76
- var el = m.target;
77
- if (el instanceof HTMLDivElement &&
78
- el.id &&
79
- seen.indexOf(el) === -1 &&
80
- looksLikeTargetDiv(el, zNearMax, uuidGate)) {
81
- seen.push(el);
82
- onMatch(el);
83
- }
69
+ }
70
+ else if (m.type === "attributes") {
71
+ var el = m.target;
72
+ if (el instanceof HTMLDivElement &&
73
+ el.id &&
74
+ seen.indexOf(el) === -1 &&
75
+ looksLikeTargetDiv(el, zNearMax, uuidGate)) {
76
+ seen.push(el);
77
+ onMatch(el);
84
78
  }
85
79
  }
86
- });
87
- mo.observe(document.documentElement, {
88
- subtree: true,
89
- childList: true,
90
- attributes: true,
91
- attributeFilter: ["style", "class", "id"]
92
- });
93
- checkNode(document.documentElement, seen, zNearMax, uuidGate, onMatch);
94
- return {
95
- stop: function () { return mo.disconnect(); }
96
- };
97
- }
98
- fckHoney.startHoneyOverlayObserver = startHoneyOverlayObserver;
99
- function listen(onMatch, options) {
100
- if (options === void 0) { options = {}; }
101
- return startHoneyOverlayObserver(__assign(__assign({}, options), { onMatch: onMatch }));
102
- }
103
- fckHoney.listen = listen;
104
- })(fckHoney || (fckHoney = {}));
80
+ }
81
+ });
82
+ mo.observe(document.documentElement, {
83
+ subtree: true,
84
+ childList: true,
85
+ attributes: true,
86
+ attributeFilter: ["style", "class", "id"]
87
+ });
88
+ checkNode(document.documentElement, seen, zNearMax, uuidGate, onMatch);
89
+ return {
90
+ stop: function () { return mo.disconnect(); }
91
+ };
92
+ }
93
+ function listen(onMatch, options) {
94
+ if (options === void 0) { options = {}; }
95
+ return startHoneyOverlayObserver(__assign(__assign({}, options), { onMatch: onMatch }));
96
+ }
105
97
  if (typeof window !== "undefined") {
106
98
  window.fckHoney = window.fckHoney || {};
107
- window.fckHoney.startHoneyOverlayObserver = fckHoney.startHoneyOverlayObserver;
108
- window.fckHoney.listen = fckHoney.listen;
99
+ window.fckHoney.startHoneyOverlayObserver = startHoneyOverlayObserver;
100
+ window.fckHoney.listen = listen;
109
101
  }
@@ -12,11 +12,3 @@ export interface ListenHandle {
12
12
  }
13
13
  export declare function startHoneyOverlayObserver(options?: ObserverOptions): ObserverHandle;
14
14
  export declare function listen(onMatch: MatchCallback, options?: Omit<ObserverOptions, "onMatch">): ListenHandle;
15
- declare global {
16
- interface Window {
17
- fckHoney?: {
18
- startHoneyOverlayObserver?: typeof startHoneyOverlayObserver;
19
- listen?: typeof listen;
20
- };
21
- }
22
- }
package/package.json CHANGED
@@ -1,16 +1,23 @@
1
1
  {
2
2
  "name": "fck-honey",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Detects Honey browser extension overlays for merchants.",
5
5
  "license": "MIT",
6
6
  "main": "dist/honey-detect.js",
7
- "types": "dist/honey-detect.d.ts",
7
+ "module": "dist/esm/index.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/esm/index.js",
12
+ "default": "./dist/honey-detect.js"
13
+ }
14
+ },
8
15
  "jsdelivr": "dist/honey-detect.js",
9
16
  "files": [
10
17
  "dist"
11
18
  ],
12
19
  "scripts": {
13
- "build": "tsc -p tsconfig.json",
20
+ "build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.global.json",
14
21
  "prepublishOnly": "npm run build",
15
22
  "clean": "rm -rf dist"
16
23
  },