coupon-shield 0.3.11
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/LICENSE +21 -0
- package/README.md +62 -0
- package/dist/auto.js +305 -0
- package/dist/bundle-tmp/auto.js +28 -0
- package/dist/bundle-tmp/core.js +286 -0
- package/dist/bundle-tmp/global.js +6 -0
- package/dist/bundle-tmp/version.js +2 -0
- package/dist/couponshield.js +295 -0
- package/dist/esm/core.js +286 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/honey-detect.d.ts +22 -0
- package/dist/honey-detect.js +295 -0
- package/dist/index.js +115 -0
- package/dist/types/core.d.ts +20 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/version.d.ts +1 -0
- package/package.json +29 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
(function (factory) {
|
|
13
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
14
|
+
var v = factory(require, exports);
|
|
15
|
+
if (v !== undefined) module.exports = v;
|
|
16
|
+
}
|
|
17
|
+
else if (typeof define === "function" && define.amd) {
|
|
18
|
+
define(["require", "exports"], factory);
|
|
19
|
+
}
|
|
20
|
+
})(function (require, exports) {
|
|
21
|
+
"use strict";
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.startHoneyOverlayObserver = startHoneyOverlayObserver;
|
|
24
|
+
exports.listen = listen;
|
|
25
|
+
var DEFAULT_Z_NEAR_MAX = 2147480000;
|
|
26
|
+
var UUIDISH_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
27
|
+
function parseZIndex(cs) {
|
|
28
|
+
var z = parseInt(cs.zIndex, 10);
|
|
29
|
+
return isFinite(z) ? z : null;
|
|
30
|
+
}
|
|
31
|
+
function looksLikeTargetDiv(el, zNearMax, uuidGate) {
|
|
32
|
+
if (!el.id)
|
|
33
|
+
return false;
|
|
34
|
+
if (uuidGate && !UUIDISH_RE.test(el.id))
|
|
35
|
+
return false;
|
|
36
|
+
var cs = getComputedStyle(el);
|
|
37
|
+
var z = parseZIndex(cs);
|
|
38
|
+
if (z === null || z < zNearMax)
|
|
39
|
+
return false;
|
|
40
|
+
if (cs.display === "none")
|
|
41
|
+
return false;
|
|
42
|
+
if (el.shadowRoot)
|
|
43
|
+
return false;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
function checkNode(node, seen, zNearMax, uuidGate, onMatch) {
|
|
47
|
+
var _a;
|
|
48
|
+
if (!(node instanceof Element))
|
|
49
|
+
return;
|
|
50
|
+
if (node instanceof HTMLDivElement && seen.indexOf(node) === -1 && looksLikeTargetDiv(node, zNearMax, uuidGate)) {
|
|
51
|
+
seen.push(node);
|
|
52
|
+
onMatch(node);
|
|
53
|
+
}
|
|
54
|
+
var divs = (_a = node.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(node, "div[id]");
|
|
55
|
+
if (!divs)
|
|
56
|
+
return;
|
|
57
|
+
for (var i = 0; i < divs.length; i += 1) {
|
|
58
|
+
var d = divs[i];
|
|
59
|
+
if (seen.indexOf(d) === -1 && looksLikeTargetDiv(d, zNearMax, uuidGate)) {
|
|
60
|
+
seen.push(d);
|
|
61
|
+
onMatch(d);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function startHoneyOverlayObserver(options) {
|
|
66
|
+
var _a, _b, _c;
|
|
67
|
+
if (options === void 0) { options = {}; }
|
|
68
|
+
var seen = [];
|
|
69
|
+
var zNearMax = (_a = options.zNearMax) !== null && _a !== void 0 ? _a : DEFAULT_Z_NEAR_MAX;
|
|
70
|
+
var uuidGate = (_b = options.uuidGate) !== null && _b !== void 0 ? _b : true;
|
|
71
|
+
var onMatch = (_c = options.onMatch) !== null && _c !== void 0 ? _c : (function (el) {
|
|
72
|
+
// Default: warn only, leaving response up to caller.
|
|
73
|
+
console.warn("[honey-detect] matched near-max z-index div:", el);
|
|
74
|
+
});
|
|
75
|
+
var mo = new MutationObserver(function (mutations) {
|
|
76
|
+
for (var _i = 0, mutations_1 = mutations; _i < mutations_1.length; _i++) {
|
|
77
|
+
var m = mutations_1[_i];
|
|
78
|
+
if (m.type === "childList") {
|
|
79
|
+
for (var i = 0; i < m.addedNodes.length; i += 1) {
|
|
80
|
+
checkNode(m.addedNodes[i], seen, zNearMax, uuidGate, onMatch);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (m.type === "attributes") {
|
|
84
|
+
var el = m.target;
|
|
85
|
+
if (el instanceof HTMLDivElement &&
|
|
86
|
+
el.id &&
|
|
87
|
+
seen.indexOf(el) === -1 &&
|
|
88
|
+
looksLikeTargetDiv(el, zNearMax, uuidGate)) {
|
|
89
|
+
seen.push(el);
|
|
90
|
+
onMatch(el);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
mo.observe(document.documentElement, {
|
|
96
|
+
subtree: true,
|
|
97
|
+
childList: true,
|
|
98
|
+
attributes: true,
|
|
99
|
+
attributeFilter: ["style", "class", "id"]
|
|
100
|
+
});
|
|
101
|
+
checkNode(document.documentElement, seen, zNearMax, uuidGate, onMatch);
|
|
102
|
+
return {
|
|
103
|
+
stop: function () { return mo.disconnect(); }
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function listen(onMatch, options) {
|
|
107
|
+
if (options === void 0) { options = {}; }
|
|
108
|
+
return startHoneyOverlayObserver(__assign(__assign({}, options), { onMatch: onMatch }));
|
|
109
|
+
}
|
|
110
|
+
if (typeof window !== "undefined") {
|
|
111
|
+
window.fckHoney = window.fckHoney || {};
|
|
112
|
+
window.fckHoney.startHoneyOverlayObserver = startHoneyOverlayObserver;
|
|
113
|
+
window.fckHoney.listen = listen;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const version = "0.3.11";
|
|
2
|
+
export type WarnCallback = (message: string) => () => void;
|
|
3
|
+
export type DetectedVendor = "honey" | "Capital One Shopping" | "Rakuten";
|
|
4
|
+
export type MatchCallback = (warn: WarnCallback, el?: HTMLDivElement, vendor?: DetectedVendor) => void;
|
|
5
|
+
export interface ObserverOptions {
|
|
6
|
+
onMatch?: MatchCallback;
|
|
7
|
+
uuidGate?: boolean;
|
|
8
|
+
zNearMax?: number;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
removeHoney?: boolean;
|
|
11
|
+
unbindAfterSeconds?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ObserverHandle {
|
|
14
|
+
stop: () => void;
|
|
15
|
+
}
|
|
16
|
+
export interface ListenHandle {
|
|
17
|
+
stop: () => void;
|
|
18
|
+
}
|
|
19
|
+
export declare function startHoneyOverlayObserver(options?: ObserverOptions): ObserverHandle;
|
|
20
|
+
export declare function listen(onMatch: MatchCallback, options?: Omit<ObserverOptions, "onMatch">): ListenHandle;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./core";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "0.3.11";
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "coupon-shield",
|
|
3
|
+
"version": "0.3.11",
|
|
4
|
+
"description": "Detects Honey browser extension overlays for merchants.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/couponshield.js",
|
|
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/couponshield.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"jsdelivr": "dist/couponshield.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prebuild": "node scripts/write-version.cjs",
|
|
21
|
+
"build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.bundle.json && esbuild dist/bundle-tmp/global.js --bundle --format=iife --platform=browser --target=es5 --outfile=dist/couponshield.js && esbuild dist/bundle-tmp/auto.js --bundle --format=iife --platform=browser --target=es5 --outfile=dist/auto.js",
|
|
22
|
+
"prepublishOnly": "npm run build && node scripts/check-version.cjs",
|
|
23
|
+
"clean": "rm -rf dist"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"esbuild": "^0.25.12",
|
|
27
|
+
"typescript": "^5.9.3"
|
|
28
|
+
}
|
|
29
|
+
}
|