nodebb-plugin-ezoic-infinite 1.4.40 → 1.4.42

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 (2) hide show
  1. package/package.json +1 -1
  2. package/public/client.js +25 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.4.40",
3
+ "version": "1.4.42",
4
4
  "description": "Production-ready Ezoic infinite ads integration for NodeBB 4.x",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/client.js CHANGED
@@ -39,6 +39,8 @@
39
39
  timer: null,
40
40
 
41
41
  obs: null,
42
+ canShowAds: true,
43
+ activeTimeouts: new Set(),
42
44
  lastScrollRun: 0,
43
45
  __scrollBound: false,
44
46
  };
@@ -325,10 +327,6 @@
325
327
 
326
328
  function callShowAdsWhenReady(id) {
327
329
  if (!id) return;
328
-
329
- if (window.location.pathname !== '/') {
330
- console.log('[TIMING] callShowAdsWhenReady ID:', id);
331
- }
332
330
 
333
331
  const now = Date.now(), last = state.lastShowById.get(id) || 0;
334
332
  if (now - last < 3500) return;
@@ -337,6 +335,19 @@
337
335
  try {
338
336
  window.ezstandalone = window.ezstandalone || {};
339
337
  if (typeof window.ezstandalone.showAds === 'function') {
338
+ // DEBUG: Logger infos du placeholder avant showAds
339
+ const ph = document.getElementById(phId);
340
+ if (ph) {
341
+ const wrapper = ph.closest('.ezoic-ad');
342
+ const wordCount = (document.body.innerText || '').split(/\s+/).length;
343
+ console.log('[UNUSED?] ID', id, {
344
+ inDOM: !!ph,
345
+ visible: ph.offsetHeight > 0,
346
+ wordCount: wordCount,
347
+ wrapperClass: wrapper ? wrapper.className : 'no-wrapper',
348
+ viewport: window.innerHeight
349
+ });
350
+ }
340
351
  state.lastShowById.set(id, Date.now());
341
352
  window.ezstandalone.showAds(id);
342
353
  return true;
@@ -352,23 +363,16 @@
352
363
  if (state.pageKey !== startPageKey) return;
353
364
  // Abort if another concurrent call is already handling this id
354
365
  if (state.pendingById.has(id)) return;
355
-
366
+
356
367
  attempts += 1;
357
368
  const el = document.getElementById(phId);
358
369
  if (el && el.isConnected) {
359
- if (window.location.pathname !== '/') {
360
- console.log('[TIMING] Placeholder', id, 'trouvé dans DOM, appel showAds');
361
- }
362
-
363
370
  // Double-check pageKey juste avant doCall (au cas où cleanup appelé entre-temps)
364
371
  if (state.pageKey !== startPageKey) {
365
- if (window.location.pathname !== '/') {
366
- console.log('[TIMING] ABORT ID', id, '- navigation détectée avant showAds');
367
- }
368
372
  // Note: les timeouts seront nettoyés par cleanup()
369
373
  return;
370
374
  }
371
-
375
+
372
376
  // Si doCall() réussit, Ezoic est chargé et showAds a été appelé → sortir
373
377
  if (doCall()) {
374
378
  state.pendingById.delete(id);
@@ -564,9 +568,9 @@
564
568
  // showAds() continuent à s'exécuter après la navigation
565
569
  state.activeTimeouts.forEach(id => clearTimeout(id));
566
570
  state.activeTimeouts.clear();
567
-
571
+
568
572
  if (state.obs) { state.obs.disconnect(); state.obs = null; }
569
- state.canInsert = false;
573
+ state.canShowAds = false;
570
574
  state.scheduled = false;
571
575
  clearTimeout(state.timer);
572
576
  state.timer = null;
@@ -580,10 +584,10 @@
580
584
 
581
585
  async function runCore() {
582
586
  // Attendre que canInsert soit true (protection race condition navigation)
583
- if (!state.canInsert) {
587
+ if (!state.canShowAds) {
584
588
  return;
585
589
  }
586
-
590
+
587
591
  patchShowAds();
588
592
 
589
593
  const cfg = await fetchConfig();
@@ -622,7 +626,6 @@
622
626
 
623
627
  enforceNoAdjacentAds();
624
628
 
625
-
626
629
  // If nothing inserted and list isn't in DOM yet (first click), retry a bit
627
630
  let count = 0;
628
631
  if (kind === 'topic') count = getPostContainers().length;
@@ -673,14 +676,14 @@
673
676
  $(window).on('action:ajaxify.end.ezoicInfinite', () => {
674
677
  state.pageKey = getPageKey();
675
678
  ensureObserver();
676
-
679
+
677
680
  // CRITIQUE: Attendre 300ms avant de permettre l'insertion de nouveaux placeholders
678
681
  // pour laisser les anciens showAds() (en cours) se terminer ou échouer proprement
679
682
  // Sinon race condition: NodeBB vide le DOM pendant que Ezoic essaie d'accéder aux placeholders
680
- state.canInsert = false;
683
+ state.canShowAds = false;
681
684
  setTimeout(() => {
682
- state.canInsert = true;
683
- }, 1000);
685
+ state.canShowAds = true;
686
+ }, 500);
684
687
  });
685
688
 
686
689
  $(window).on('action:category.loaded.ezoicInfinite', () => {