nodebb-plugin-ezoic-infinite 1.8.50 → 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 -10
  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,6 +135,17 @@ 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>',
@@ -160,25 +168,30 @@ plugin.addAdminNavigation = async (header) => {
160
168
  return header;
161
169
  };
162
170
 
163
- /**
164
- * Inject Ezoic scripts into <head> via templateData.customHTML.
165
- * NodeBB v4/Harmony: header.tpl has {{customHTML}} in <head>.
166
- */
167
171
  plugin.injectEzoicHead = async (data) => {
168
172
  try {
169
173
  const settings = await getSettings();
170
174
  const uid = data.req?.uid ?? 0;
171
175
  const excluded = await isUserExcluded(uid, settings.excludedGroups);
172
- 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 {
173
185
  const cfg = buildClientConfig(settings, false);
186
+ // Order: preconnects → global stubs → CMP scripts → sa.min.js → inline config
174
187
  data.templateData.customHTML =
175
188
  HEAD_PRECONNECTS + '\n' +
189
+ EZOIC_GLOBALS + '\n' +
176
190
  EZOIC_SCRIPTS + '\n' +
177
191
  serializeInlineConfig(cfg) +
178
192
  (data.templateData.customHTML || '');
179
193
  }
180
194
  } catch (err) {
181
- // Log but don't break rendering
182
195
  console.error('[ezoic-infinite] injectEzoicHead error:', err.message);
183
196
  }
184
197
  return data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.8.50",
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",