nodebb-plugin-ezoic-infinite 0.5.9 → 0.6.1

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 +41 -35
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.5.9",
3
+ "version": "0.6.1",
4
4
  "description": "Ezoic ads with infinite scroll using a pool of placeholder IDs",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/client.js CHANGED
@@ -28,32 +28,44 @@ function parsePool(raw) {
28
28
  ));
29
29
  }
30
30
 
31
- function isTopicTemplate() {
32
- return !!(ajaxify && ajaxify.data && (ajaxify.data.template === 'topic' || ajaxify.data.template === 'topicEvents'));
31
+ function guessIsTopicPage() {
32
+ // Prefer ajaxify template, fallback to DOM presence
33
+ try {
34
+ if (ajaxify && ajaxify.data && ajaxify.data.template) {
35
+ return ['topic', 'topicEvents'].includes(ajaxify.data.template);
36
+ }
37
+ } catch (e) {}
38
+ return $('[component="post/content"]').length > 0;
33
39
  }
34
40
 
35
- function isCategoryTemplate() {
36
- return !!(ajaxify && ajaxify.data && ajaxify.data.template === 'category');
41
+ function guessIsCategoryPage() {
42
+ try {
43
+ if (ajaxify && ajaxify.data && ajaxify.data.template) {
44
+ return ajaxify.data.template === 'category';
45
+ }
46
+ } catch (e) {}
47
+ return $('li[component="category/topic"]').length > 0;
37
48
  }
38
49
 
39
50
  function getTopicPosts() {
40
- if (!isTopicTemplate()) return $();
51
+ if (!guessIsTopicPage()) return $();
52
+
53
+ // Harmony standard wrapper
41
54
  const $primary = $('[component="post"][data-pid]');
42
55
  if ($primary.length) return $primary.not('.ezoic-ad-post');
43
56
 
57
+ // Fallback: top-level data-pid that contains post content and isn't nested
44
58
  const $top = $('[data-pid]').filter(function () {
45
59
  const $el = $(this);
46
60
  const hasContent = $el.find('[component="post/content"]').length > 0;
47
61
  const nested = $el.parents('[data-pid]').length > 0;
48
62
  return hasContent && !nested;
49
63
  });
50
- if ($top.length) return $top.not('.ezoic-ad-post');
51
-
52
- return $('.posts .post').not('.ezoic-ad-post');
64
+ return $top.not('.ezoic-ad-post');
53
65
  }
54
66
 
55
67
  function getCategoryTopicItems() {
56
- if (!isCategoryTemplate()) return $();
68
+ if (!guessIsCategoryPage()) return $();
57
69
  return $('li[component="category/topic"]').not('.ezoic-ad-topic');
58
70
  }
59
71
 
@@ -65,7 +77,6 @@ function removeExistingEzoicNodes() {
65
77
  $('.ezoic-ad-post').remove();
66
78
  $('.ezoic-ad-between').remove();
67
79
  $('.ezoic-ad-topic').remove();
68
- $('[id^="ezoic-pub-ad-placeholder-"]').remove();
69
80
  }
70
81
 
71
82
  function computeWindowSlots(totalItems, interval, poolSize) {
@@ -126,34 +137,32 @@ function insertAdMessagesBetweenReplies($posts, ids, interval) {
126
137
  return activeIds;
127
138
  }
128
139
 
129
- function uniqueConcat(a, b) {
130
- const seen = new Set();
131
- const out = [];
132
- [...a, ...b].forEach((x) => {
133
- if (!seen.has(x)) {
134
- seen.add(x);
135
- out.push(x);
136
- }
137
- });
138
- return out;
139
- }
140
-
141
- function ezoicCall(ids) {
140
+ function ezoicRender(ids) {
142
141
  if (!ids || !ids.length) return;
143
142
 
144
143
  window.ezstandalone = window.ezstandalone || {};
145
144
  window.ezstandalone.cmd = window.ezstandalone.cmd || [];
146
145
 
146
+ // Ezoic doc: showAds(101,102,103) within cmd.push for dynamic content citeturn0search0turn0search6
147
147
  window.ezstandalone.cmd.push(function () {
148
148
  try {
149
- if (typeof window.ezstandalone.destroyPlaceholders === 'function') {
150
- window.ezstandalone.destroyPlaceholders.apply(window.ezstandalone, ids);
149
+ if (typeof window.ezstandalone.refreshAds === 'function') {
150
+ window.ezstandalone.refreshAds.apply(window.ezstandalone, ids);
151
+ return;
151
152
  }
152
153
  } catch (e) {}
153
154
 
154
155
  try {
155
156
  if (typeof window.ezstandalone.showAds === 'function') {
156
157
  window.ezstandalone.showAds.apply(window.ezstandalone, ids);
158
+ return;
159
+ }
160
+ } catch (e) {}
161
+
162
+ // Last resort: call showAds() with no args = "all placeholders" citeturn0search0turn0search6
163
+ try {
164
+ if (typeof window.ezstandalone.showAds === 'function') {
165
+ window.ezstandalone.showAds();
157
166
  }
158
167
  } catch (e) {}
159
168
  });
@@ -196,32 +205,29 @@ async function refreshAds() {
196
205
 
197
206
  removeExistingEzoicNodes();
198
207
 
199
- const combinedUnique = uniqueConcat(betweenPool, messagePool);
200
208
  const activeIds = [];
201
209
 
202
- // Category topic list page: use BETWEEN only
210
+ // Category pages: BETWEEN only
203
211
  if ($topicItems.length) {
204
212
  if (cfg.enableBetweenAds && betweenPool.length) {
205
- activeIds.push(...insertBetweenGeneric($topicItems, combinedUnique.slice(0, betweenPool.length), betweenInterval, 'ezoic-ad-topic'));
213
+ activeIds.push(...insertBetweenGeneric($topicItems, betweenPool, betweenInterval, 'ezoic-ad-topic'));
206
214
  }
207
- ezoicCall(activeIds);
215
+ ezoicRender(activeIds);
208
216
  return;
209
217
  }
210
218
 
211
- // Topic page: ONLY message ads (as requested)
219
+ // Topic pages: MESSAGE only (as you requested)
212
220
  if ($posts.length) {
213
221
  if (cfg.enableMessageAds && messagePool.length) {
214
- // Use messagePool slice from the combined unique set, but keep it stable
215
- const idsForMessage = combinedUnique.slice(0, messagePool.length);
216
- activeIds.push(...insertAdMessagesBetweenReplies($posts, idsForMessage, messageInterval));
222
+ activeIds.push(...insertAdMessagesBetweenReplies($posts, messagePool, messageInterval));
217
223
  }
218
- ezoicCall(activeIds);
224
+ ezoicRender(activeIds);
219
225
  }
220
226
  } finally {
221
227
  inFlight = false;
222
228
  if (rerunRequested) {
223
229
  rerunRequested = false;
224
- setTimeout(refreshAds, 50);
230
+ setTimeout(refreshAds, 80);
225
231
  }
226
232
  }
227
233
  }