fck-honey 0.2.0 → 0.2.1
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 +10 -0
- package/dist/esm/index.js +45 -9
- package/dist/honey-detect.js +45 -9
- package/dist/types/index.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,3 +32,13 @@ listen((el) => {
|
|
|
32
32
|
console.log("Honey overlay detected:", el);
|
|
33
33
|
});
|
|
34
34
|
```
|
|
35
|
+
|
|
36
|
+
## Advanced Options
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
window.fckHoney.listen((el, warn) => {
|
|
40
|
+
// Optional: the element is removed automatically by default.
|
|
41
|
+
// warn() shows a built-in overlay message (returns a hide function).
|
|
42
|
+
warn("You must disable the Honey extension to continue.");
|
|
43
|
+
}, { removeHoney: true });
|
|
44
|
+
```
|
package/dist/esm/index.js
CHANGED
|
@@ -12,6 +12,36 @@ var __assign = (this && this.__assign) || function () {
|
|
|
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
14
|
var TARGET_SELECTOR = "div[id]";
|
|
15
|
+
var OVERLAY_STYLE_ID = "simple-overlay-styles";
|
|
16
|
+
function showOverlay(message) {
|
|
17
|
+
if (typeof document === "undefined")
|
|
18
|
+
return function () { };
|
|
19
|
+
if (!document.getElementById(OVERLAY_STYLE_ID)) {
|
|
20
|
+
var style = document.createElement("style");
|
|
21
|
+
style.id = OVERLAY_STYLE_ID;
|
|
22
|
+
style.textContent =
|
|
23
|
+
".simple-overlay{position:fixed;inset:0;background:rgba(0,0,0,0.6);z-index:999999;display:flex;align-items:center;justify-content:center;pointer-events:all;}" +
|
|
24
|
+
".simple-overlay-message{background:#ffffff;padding:16px 20px;border-radius:8px;font-size:14px;max-width:80%;text-align:center;box-shadow:0 10px 30px rgba(0,0,0,0.3);}";
|
|
25
|
+
document.head.appendChild(style);
|
|
26
|
+
}
|
|
27
|
+
var overlay = document.createElement("div");
|
|
28
|
+
overlay.className = "simple-overlay";
|
|
29
|
+
var messageEl = document.createElement("div");
|
|
30
|
+
messageEl.className = "simple-overlay-message";
|
|
31
|
+
messageEl.innerHTML = message;
|
|
32
|
+
overlay.appendChild(messageEl);
|
|
33
|
+
if (document.body) {
|
|
34
|
+
document.body.appendChild(overlay);
|
|
35
|
+
}
|
|
36
|
+
var prevOverflow = document.body ? document.body.style.overflow : "";
|
|
37
|
+
if (document.body)
|
|
38
|
+
document.body.style.overflow = "hidden";
|
|
39
|
+
return function hideOverlay() {
|
|
40
|
+
overlay.remove();
|
|
41
|
+
if (document.body)
|
|
42
|
+
document.body.style.overflow = prevOverflow;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
15
45
|
function parseZIndex(cs, el) {
|
|
16
46
|
var computed = parseInt(cs.zIndex, 10);
|
|
17
47
|
if (isFinite(computed))
|
|
@@ -51,12 +81,14 @@ function looksLikeTargetDiv(el, zNearMax, uuidGate, debug) {
|
|
|
51
81
|
console.log("+++ match", el);
|
|
52
82
|
return true;
|
|
53
83
|
}
|
|
54
|
-
function scanElement(el, seen, zNearMax, uuidGate, debug, onMatch) {
|
|
84
|
+
function scanElement(el, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn) {
|
|
55
85
|
var _a;
|
|
56
86
|
if (el instanceof HTMLDivElement && el.matches(TARGET_SELECTOR)) {
|
|
57
87
|
if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate, debug)) {
|
|
58
88
|
seen.push(el);
|
|
59
|
-
|
|
89
|
+
if (removeHoney && el.parentNode)
|
|
90
|
+
el.parentNode.removeChild(el);
|
|
91
|
+
onMatch(el, warn);
|
|
60
92
|
}
|
|
61
93
|
}
|
|
62
94
|
var divs = (_a = el.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(el, TARGET_SELECTOR);
|
|
@@ -66,18 +98,22 @@ function scanElement(el, seen, zNearMax, uuidGate, debug, onMatch) {
|
|
|
66
98
|
var d = divs[i];
|
|
67
99
|
if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate, debug)) {
|
|
68
100
|
seen.push(d);
|
|
69
|
-
|
|
101
|
+
if (removeHoney && d.parentNode)
|
|
102
|
+
d.parentNode.removeChild(d);
|
|
103
|
+
onMatch(d, warn);
|
|
70
104
|
}
|
|
71
105
|
}
|
|
72
106
|
}
|
|
73
107
|
export function startHoneyOverlayObserver(options) {
|
|
74
|
-
var _a, _b, _c, _d;
|
|
108
|
+
var _a, _b, _c, _d, _e;
|
|
75
109
|
if (options === void 0) { options = {}; }
|
|
76
110
|
var seen = [];
|
|
77
111
|
var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
|
|
78
112
|
var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
|
|
79
113
|
var debug = (_c = options.debug) !== null && _c !== void 0 ? _c : false;
|
|
80
|
-
var
|
|
114
|
+
var removeHoney = (_d = options.removeHoney) !== null && _d !== void 0 ? _d : true;
|
|
115
|
+
var warn = function (message) { return showOverlay(message); };
|
|
116
|
+
var onMatch = (_e = options.onMatch) !== null && _e !== void 0 ? _e : (function () { });
|
|
81
117
|
var mo = new MutationObserver(function (mutations) {
|
|
82
118
|
for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
|
|
83
119
|
var m = mutations_1[_i];
|
|
@@ -94,17 +130,17 @@ export function startHoneyOverlayObserver(options) {
|
|
|
94
130
|
for (var i = 0; i < m.addedNodes.length; i += 1) {
|
|
95
131
|
var node = m.addedNodes[i];
|
|
96
132
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
97
|
-
scanElement(node, seen, zNearMax, uuidGate, debug, onMatch);
|
|
133
|
+
scanElement(node, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
|
|
98
134
|
}
|
|
99
135
|
}
|
|
100
136
|
}
|
|
101
137
|
if (m.target instanceof Element) {
|
|
102
|
-
scanElement(m.target, seen, zNearMax, uuidGate, debug, onMatch);
|
|
138
|
+
scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
|
|
103
139
|
}
|
|
104
140
|
}
|
|
105
141
|
else if (m.type === "attributes") {
|
|
106
142
|
if (m.target instanceof Element) {
|
|
107
|
-
scanElement(m.target, seen, zNearMax, uuidGate, debug, onMatch);
|
|
143
|
+
scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
|
|
108
144
|
}
|
|
109
145
|
}
|
|
110
146
|
}
|
|
@@ -115,7 +151,7 @@ export function startHoneyOverlayObserver(options) {
|
|
|
115
151
|
attributes: true,
|
|
116
152
|
attributeFilter: ["style", "class", "id"]
|
|
117
153
|
});
|
|
118
|
-
scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, onMatch);
|
|
154
|
+
scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
|
|
119
155
|
return {
|
|
120
156
|
stop: function () { return mo.disconnect(); }
|
|
121
157
|
};
|
package/dist/honey-detect.js
CHANGED
|
@@ -13,6 +13,36 @@ var __assign = (this && this.__assign) || function () {
|
|
|
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
15
|
var TARGET_SELECTOR = "div[id]";
|
|
16
|
+
var OVERLAY_STYLE_ID = "simple-overlay-styles";
|
|
17
|
+
function showOverlay(message) {
|
|
18
|
+
if (typeof document === "undefined")
|
|
19
|
+
return function () { };
|
|
20
|
+
if (!document.getElementById(OVERLAY_STYLE_ID)) {
|
|
21
|
+
var style = document.createElement("style");
|
|
22
|
+
style.id = OVERLAY_STYLE_ID;
|
|
23
|
+
style.textContent =
|
|
24
|
+
".simple-overlay{position:fixed;inset:0;background:rgba(0,0,0,0.6);z-index:999999;display:flex;align-items:center;justify-content:center;pointer-events:all;}" +
|
|
25
|
+
".simple-overlay-message{background:#ffffff;padding:16px 20px;border-radius:8px;font-size:14px;max-width:80%;text-align:center;box-shadow:0 10px 30px rgba(0,0,0,0.3);}";
|
|
26
|
+
document.head.appendChild(style);
|
|
27
|
+
}
|
|
28
|
+
var overlay = document.createElement("div");
|
|
29
|
+
overlay.className = "simple-overlay";
|
|
30
|
+
var messageEl = document.createElement("div");
|
|
31
|
+
messageEl.className = "simple-overlay-message";
|
|
32
|
+
messageEl.innerHTML = message;
|
|
33
|
+
overlay.appendChild(messageEl);
|
|
34
|
+
if (document.body) {
|
|
35
|
+
document.body.appendChild(overlay);
|
|
36
|
+
}
|
|
37
|
+
var prevOverflow = document.body ? document.body.style.overflow : "";
|
|
38
|
+
if (document.body)
|
|
39
|
+
document.body.style.overflow = "hidden";
|
|
40
|
+
return function hideOverlay() {
|
|
41
|
+
overlay.remove();
|
|
42
|
+
if (document.body)
|
|
43
|
+
document.body.style.overflow = prevOverflow;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
16
46
|
function parseZIndex(cs, el) {
|
|
17
47
|
var computed = parseInt(cs.zIndex, 10);
|
|
18
48
|
if (isFinite(computed))
|
|
@@ -52,12 +82,14 @@ function looksLikeTargetDiv(el, zNearMax, uuidGate, debug) {
|
|
|
52
82
|
console.log("+++ match", el);
|
|
53
83
|
return true;
|
|
54
84
|
}
|
|
55
|
-
function scanElement(el, seen, zNearMax, uuidGate, debug, onMatch) {
|
|
85
|
+
function scanElement(el, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn) {
|
|
56
86
|
var _a;
|
|
57
87
|
if (el instanceof HTMLDivElement && el.matches(TARGET_SELECTOR)) {
|
|
58
88
|
if (seen.indexOf(el) === -1 && looksLikeTargetDiv(el, zNearMax, uuidGate, debug)) {
|
|
59
89
|
seen.push(el);
|
|
60
|
-
|
|
90
|
+
if (removeHoney && el.parentNode)
|
|
91
|
+
el.parentNode.removeChild(el);
|
|
92
|
+
onMatch(el, warn);
|
|
61
93
|
}
|
|
62
94
|
}
|
|
63
95
|
var divs = (_a = el.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(el, TARGET_SELECTOR);
|
|
@@ -67,18 +99,22 @@ function scanElement(el, seen, zNearMax, uuidGate, debug, onMatch) {
|
|
|
67
99
|
var d = divs[i];
|
|
68
100
|
if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate, debug)) {
|
|
69
101
|
seen.push(d);
|
|
70
|
-
|
|
102
|
+
if (removeHoney && d.parentNode)
|
|
103
|
+
d.parentNode.removeChild(d);
|
|
104
|
+
onMatch(d, warn);
|
|
71
105
|
}
|
|
72
106
|
}
|
|
73
107
|
}
|
|
74
108
|
function startHoneyOverlayObserver(options) {
|
|
75
|
-
var _a, _b, _c, _d;
|
|
109
|
+
var _a, _b, _c, _d, _e;
|
|
76
110
|
if (options === void 0) { options = {}; }
|
|
77
111
|
var seen = [];
|
|
78
112
|
var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
|
|
79
113
|
var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
|
|
80
114
|
var debug = (_c = options.debug) !== null && _c !== void 0 ? _c : false;
|
|
81
|
-
var
|
|
115
|
+
var removeHoney = (_d = options.removeHoney) !== null && _d !== void 0 ? _d : true;
|
|
116
|
+
var warn = function (message) { return showOverlay(message); };
|
|
117
|
+
var onMatch = (_e = options.onMatch) !== null && _e !== void 0 ? _e : (function () { });
|
|
82
118
|
var mo = new MutationObserver(function (mutations) {
|
|
83
119
|
for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
|
|
84
120
|
var m = mutations_1[_i];
|
|
@@ -95,17 +131,17 @@ function startHoneyOverlayObserver(options) {
|
|
|
95
131
|
for (var i = 0; i < m.addedNodes.length; i += 1) {
|
|
96
132
|
var node = m.addedNodes[i];
|
|
97
133
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
98
|
-
scanElement(node, seen, zNearMax, uuidGate, debug, onMatch);
|
|
134
|
+
scanElement(node, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
|
|
99
135
|
}
|
|
100
136
|
}
|
|
101
137
|
}
|
|
102
138
|
if (m.target instanceof Element) {
|
|
103
|
-
scanElement(m.target, seen, zNearMax, uuidGate, debug, onMatch);
|
|
139
|
+
scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
|
|
104
140
|
}
|
|
105
141
|
}
|
|
106
142
|
else if (m.type === "attributes") {
|
|
107
143
|
if (m.target instanceof Element) {
|
|
108
|
-
scanElement(m.target, seen, zNearMax, uuidGate, debug, onMatch);
|
|
144
|
+
scanElement(m.target, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
|
|
109
145
|
}
|
|
110
146
|
}
|
|
111
147
|
}
|
|
@@ -116,7 +152,7 @@ function startHoneyOverlayObserver(options) {
|
|
|
116
152
|
attributes: true,
|
|
117
153
|
attributeFilter: ["style", "class", "id"]
|
|
118
154
|
});
|
|
119
|
-
scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, onMatch);
|
|
155
|
+
scanElement(document.documentElement, seen, zNearMax, uuidGate, debug, removeHoney, onMatch, warn);
|
|
120
156
|
return {
|
|
121
157
|
stop: function () { return mo.disconnect(); }
|
|
122
158
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type WarnCallback = (message: string) => () => void;
|
|
2
|
+
export type MatchCallback = (el: HTMLDivElement, warn: WarnCallback) => void;
|
|
2
3
|
export interface ObserverOptions {
|
|
3
4
|
onMatch?: MatchCallback;
|
|
4
5
|
uuidGate?: boolean;
|
|
5
6
|
zNearMax?: number;
|
|
6
7
|
debug?: boolean;
|
|
8
|
+
removeHoney?: boolean;
|
|
7
9
|
}
|
|
8
10
|
export interface ObserverHandle {
|
|
9
11
|
stop: () => void;
|