nodebb-plugin-ezoic-infinite 1.5.1 → 1.5.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/package.json +1 -1
- package/public/client.js +22 -49
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
|
|
3
|
+
// Safety stub: some Ezoic scripts expect a global queue even when ads are disabled
|
|
4
|
+
window._ezaq = window._ezaq || [];
|
|
2
5
|
/**
|
|
3
6
|
* Ezoic Infinite Ads for NodeBB 4.x
|
|
4
7
|
* - Event-driven only (ajaxify hooks + MutationObserver + IntersectionObserver)
|
|
@@ -8,15 +11,6 @@
|
|
|
8
11
|
*/
|
|
9
12
|
|
|
10
13
|
(function () {
|
|
11
|
-
|
|
12
|
-
// --- Safety stubs: prevent crashes if Ezoic scripts execute when ads are disabled/excluded ---
|
|
13
|
-
window._ezaq = window._ezaq || [];
|
|
14
|
-
window.ezstandalone = window.ezstandalone || {};
|
|
15
|
-
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
16
|
-
if (typeof window.ezstandalone.showAds !== 'function') {
|
|
17
|
-
window.ezstandalone.showAds = function () {};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
14
|
const CFG_URL = '/api/plugins/ezoic-infinite/config';
|
|
21
15
|
|
|
22
16
|
// -------------------------
|
|
@@ -99,18 +93,13 @@ if (typeof window.ezstandalone.showAds !== 'function') {
|
|
|
99
93
|
Pool.ensurePlaceholder(id);
|
|
100
94
|
|
|
101
95
|
const el = document.getElementById(id);
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
// Call one-by-one to avoid batch logging on missing nodes
|
|
111
|
-
original.call(window.ezstandalone, id);
|
|
112
|
-
} catch (e) {
|
|
113
|
-
// swallow: Ezoic can throw if called during transitions
|
|
96
|
+
if (el && document.body.contains(el)) {
|
|
97
|
+
try {
|
|
98
|
+
// Call one-by-one to avoid batch logging on missing nodes
|
|
99
|
+
original.call(window.ezstandalone, id);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
// swallow: Ezoic can throw if called during transitions
|
|
102
|
+
}
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
105
|
};
|
|
@@ -119,35 +108,19 @@ if (typeof window.ezstandalone.showAds !== 'function') {
|
|
|
119
108
|
return wrapped;
|
|
120
109
|
}
|
|
121
110
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// If already has a setter installed, do nothing
|
|
134
|
-
const desc = Object.getOwnPropertyDescriptor(ez, 'showAds');
|
|
135
|
-
if (desc && (desc.set || desc.get)) return;
|
|
136
|
-
|
|
137
|
-
let _showAds = ez.showAds;
|
|
138
|
-
Object.defineProperty(ez, 'showAds', {
|
|
139
|
-
configurable: true,
|
|
140
|
-
enumerable: true,
|
|
141
|
-
get() { return _showAds; },
|
|
142
|
-
set(v) { _showAds = wrapShowAds(v); }
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// Re-assign current value through setter
|
|
146
|
-
ez.showAds = _showAds;
|
|
147
|
-
} catch (e) {
|
|
148
|
-
// If defineProperty fails, best-effort wrap is still in place above.
|
|
149
|
-
}
|
|
111
|
+
|
|
112
|
+
function installShowAdsHook() {
|
|
113
|
+
// NOTE: Do NOT use Object.defineProperty accessor tricks on `ezstandalone.showAds`.
|
|
114
|
+
// Ezoic's standalone loader may validate that property as a plain writable function,
|
|
115
|
+
// and accessor hooks can cause `defineScript failed` / `displayScript failed`.
|
|
116
|
+
// Instead, we only wrap it once it exists (event-driven paths will call this again).
|
|
117
|
+
const ez = window.ezstandalone;
|
|
118
|
+
if (!ez) return;
|
|
119
|
+
if (!Array.isArray(ez.cmd)) ez.cmd = [];
|
|
120
|
+
if (typeof ez.showAds === 'function' && !ez.showAds.__ezoicInfiniteWrapped) {
|
|
121
|
+
ez.showAds = wrapShowAds(ez.showAds);
|
|
150
122
|
}
|
|
123
|
+
}
|
|
151
124
|
|
|
152
125
|
function ezCmd(fn) {
|
|
153
126
|
// Tokenize so queued callbacks don't run after navigation
|