nodebb-plugin-ezoic-infinite 1.5.4 → 1.5.6
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 +52 -35
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -10,15 +10,6 @@
|
|
|
10
10
|
(function () {
|
|
11
11
|
const CFG_URL = '/api/plugins/ezoic-infinite/config';
|
|
12
12
|
|
|
13
|
-
// Ensure Ezoic globals exist early (prevents `cmd`/`_ezaq` crashes)
|
|
14
|
-
function bootEzGlobals(){
|
|
15
|
-
window._ezaq = window._ezaq || [];
|
|
16
|
-
window.ezstandalone = window.ezstandalone || {};
|
|
17
|
-
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
bootEzGlobals();
|
|
21
|
-
|
|
22
13
|
// -------------------------
|
|
23
14
|
// Utilities
|
|
24
15
|
// -------------------------
|
|
@@ -87,39 +78,64 @@
|
|
|
87
78
|
return args.flat().map(String);
|
|
88
79
|
}
|
|
89
80
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// -------------------------
|
|
93
|
-
function ensureEzGlobals() {
|
|
94
|
-
window._ezaq = window._ezaq || [];
|
|
95
|
-
window.ezstandalone = window.ezstandalone || {};
|
|
96
|
-
window.ezstandalone.cmd = window.ezstandalone.cmd || [];
|
|
97
|
-
}
|
|
81
|
+
function wrapShowAds(original) {
|
|
82
|
+
if (!original || original.__nodebbSafeWrapped) return original;
|
|
98
83
|
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
? window.ezstandalone.showAds
|
|
103
|
-
: null;
|
|
84
|
+
const wrapped = function (...args) {
|
|
85
|
+
const ids = normalizeIds(args);
|
|
86
|
+
if (!ids.length) return;
|
|
104
87
|
|
|
105
|
-
|
|
88
|
+
for (const id of ids) {
|
|
89
|
+
// Ensure placeholder exists somewhere (pool), so ez-standalone won't log "does not exist"
|
|
90
|
+
Pool.ensurePlaceholder(id);
|
|
91
|
+
|
|
92
|
+
const el = document.getElementById(id);
|
|
93
|
+
if (el && document.body.contains(el)) {
|
|
94
|
+
try {
|
|
95
|
+
// Call one-by-one to avoid batch logging on missing nodes
|
|
96
|
+
original.call(window.ezstandalone, id);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
// swallow: Ezoic can throw if called during transitions
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
106
103
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (!el) continue;
|
|
104
|
+
wrapped.__nodebbSafeWrapped = true;
|
|
105
|
+
return wrapped;
|
|
106
|
+
}
|
|
111
107
|
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
function installShowAdsHook() {
|
|
109
|
+
// If ezstandalone already exists, wrap now.
|
|
110
|
+
if (window.ezstandalone && window.ezstandalone.showAds) {
|
|
111
|
+
window.ezstandalone.showAds = wrapShowAds(window.ezstandalone.showAds);
|
|
112
|
+
}
|
|
114
113
|
|
|
115
|
-
|
|
114
|
+
// Hook future assignment (no polling)
|
|
115
|
+
try {
|
|
116
|
+
if (!window.ezstandalone) window.ezstandalone = {};
|
|
117
|
+
const ez = window.ezstandalone;
|
|
118
|
+
|
|
119
|
+
// If already has a setter installed, do nothing
|
|
120
|
+
const desc = Object.getOwnPropertyDescriptor(ez, 'showAds');
|
|
121
|
+
if (desc && (desc.set || desc.get)) return;
|
|
122
|
+
|
|
123
|
+
let _showAds = ez.showAds;
|
|
124
|
+
Object.defineProperty(ez, 'showAds', {
|
|
125
|
+
configurable: true,
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get() { return _showAds; },
|
|
128
|
+
set(v) { _showAds = wrapShowAds(v); }
|
|
129
|
+
});
|
|
116
130
|
|
|
117
|
-
|
|
131
|
+
// Re-assign current value through setter
|
|
132
|
+
ez.showAds = _showAds;
|
|
133
|
+
} catch (e) {
|
|
134
|
+
// If defineProperty fails, best-effort wrap is still in place above.
|
|
135
|
+
}
|
|
118
136
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function ezCmd(fn) {
|
|
122
137
|
|
|
138
|
+
function ezCmd(fn) {
|
|
123
139
|
// Tokenize so queued callbacks don't run after navigation
|
|
124
140
|
const tokenAtSchedule = navToken;
|
|
125
141
|
window.ezstandalone = window.ezstandalone || {};
|
|
@@ -215,6 +231,7 @@ function ezCmd(fn) {
|
|
|
215
231
|
|
|
216
232
|
if (c.excluded) return; // HARD stop: never inject for excluded users
|
|
217
233
|
|
|
234
|
+
installShowAdsHook();
|
|
218
235
|
this.initObservers();
|
|
219
236
|
|
|
220
237
|
if (c.enableBetweenAds) this.injectBetweenTopics(c);
|
|
@@ -361,7 +378,7 @@ function ezCmd(fn) {
|
|
|
361
378
|
|
|
362
379
|
// First load
|
|
363
380
|
once('DOMContentLoaded', () => {
|
|
364
|
-
|
|
381
|
+
installShowAdsHook();
|
|
365
382
|
prefetchConfig();
|
|
366
383
|
Ad.scheduleScan();
|
|
367
384
|
});
|