nodebb-plugin-ezoic-infinite 1.8.51 → 1.8.52

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.
Files changed (3) hide show
  1. package/library.js +23 -15
  2. package/package.json +1 -1
  3. package/public/client.js +296 -564
package/library.js CHANGED
@@ -87,11 +87,8 @@ async function isUserExcluded(uid, excludedGroups) {
87
87
  const value = (userGroups[0] || []).some(g => excludedSet.has(g.name));
88
88
 
89
89
  _excludeCache.set(key, { value, at: Date.now() });
90
-
91
- // Limit cache size to prevent unbounded growth
92
90
  if (_excludeCache.size > 1000) {
93
- const oldest = _excludeCache.keys().next().value;
94
- _excludeCache.delete(oldest);
91
+ _excludeCache.delete(_excludeCache.keys().next().value);
95
92
  }
96
93
 
97
94
  return value;
@@ -138,15 +135,21 @@ const HEAD_PRECONNECTS = [
138
135
  '<link rel="dns-prefetch" href="https://securepubads.g.doubleclick.net">',
139
136
  ].join('\n');
140
137
 
138
+ // CRITICAL: The global stubs MUST be the very first <script> block, before
139
+ // any Ezoic script (CMP, sa.min.js). sa.min.js is async and can execute as
140
+ // soon as it downloads — if it runs before the stub, _ezaq is undefined.
141
+ const EZOIC_GLOBALS = [
142
+ '<script>',
143
+ 'window._ezaq = window._ezaq || {};',
144
+ 'window.ezstandalone = window.ezstandalone || {};',
145
+ 'window.ezstandalone.cmd = window.ezstandalone.cmd || [];',
146
+ '</script>',
147
+ ].join('\n');
148
+
141
149
  const EZOIC_SCRIPTS = [
142
150
  '<script data-cfasync="false" src="https://cmp.gatekeeperconsent.com/min.js"></script>',
143
151
  '<script data-cfasync="false" src="https://the.gatekeeperconsent.com/cmp.min.js"></script>',
144
152
  '<script async src="//www.ezojs.com/ezoic/sa.min.js"></script>',
145
- '<script>',
146
- 'var _ezaq = window._ezaq = window._ezaq || [];',
147
- 'var ezstandalone = window.ezstandalone = window.ezstandalone || {};',
148
- 'ezstandalone.cmd = ezstandalone.cmd || [];',
149
- '</script>',
150
153
  ].join('\n');
151
154
 
152
155
  // ── Hooks ────────────────────────────────────────────────────────────────────
@@ -165,25 +168,30 @@ plugin.addAdminNavigation = async (header) => {
165
168
  return header;
166
169
  };
167
170
 
168
- /**
169
- * Inject Ezoic scripts into <head> via templateData.customHTML.
170
- * NodeBB v4/Harmony: header.tpl has {{customHTML}} in <head>.
171
- */
172
171
  plugin.injectEzoicHead = async (data) => {
173
172
  try {
174
173
  const settings = await getSettings();
175
174
  const uid = data.req?.uid ?? 0;
176
175
  const excluded = await isUserExcluded(uid, settings.excludedGroups);
177
- if (!excluded) {
176
+
177
+ if (excluded) {
178
+ const cfg = buildClientConfig(settings, true);
179
+ // Minimal stub only — no Ezoic scripts loaded for excluded users
180
+ data.templateData.customHTML =
181
+ EZOIC_GLOBALS + '\n' +
182
+ serializeInlineConfig(cfg) +
183
+ (data.templateData.customHTML || '');
184
+ } else {
178
185
  const cfg = buildClientConfig(settings, false);
186
+ // Order: preconnects → global stubs → CMP scripts → sa.min.js → inline config
179
187
  data.templateData.customHTML =
180
188
  HEAD_PRECONNECTS + '\n' +
189
+ EZOIC_GLOBALS + '\n' +
181
190
  EZOIC_SCRIPTS + '\n' +
182
191
  serializeInlineConfig(cfg) +
183
192
  (data.templateData.customHTML || '');
184
193
  }
185
194
  } catch (err) {
186
- // Log but don't break rendering
187
195
  console.error('[ezoic-infinite] injectEzoicHead error:', err.message);
188
196
  }
189
197
  return data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.8.51",
3
+ "version": "1.8.52",
4
4
  "description": "Production-ready Ezoic infinite ads integration for NodeBB 4.x",
5
5
  "main": "library.js",
6
6
  "license": "MIT",