nodebb-plugin-ezoic-infinite 0.5.9 → 0.6.0

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 +12 -37
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.0",
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
@@ -40,16 +40,12 @@ function getTopicPosts() {
40
40
  if (!isTopicTemplate()) return $();
41
41
  const $primary = $('[component="post"][data-pid]');
42
42
  if ($primary.length) return $primary.not('.ezoic-ad-post');
43
-
44
- const $top = $('[data-pid]').filter(function () {
43
+ return $('[data-pid]').filter(function () {
45
44
  const $el = $(this);
46
45
  const hasContent = $el.find('[component="post/content"]').length > 0;
47
46
  const nested = $el.parents('[data-pid]').length > 0;
48
47
  return hasContent && !nested;
49
- });
50
- if ($top.length) return $top.not('.ezoic-ad-post');
51
-
52
- return $('.posts .post').not('.ezoic-ad-post');
48
+ }).not('.ezoic-ad-post');
53
49
  }
54
50
 
55
51
  function getCategoryTopicItems() {
@@ -62,10 +58,10 @@ function tagName($el) {
62
58
  }
63
59
 
64
60
  function removeExistingEzoicNodes() {
61
+ // Remove only the wrappers we created. Their inner placeholder divs go away with them.
65
62
  $('.ezoic-ad-post').remove();
66
63
  $('.ezoic-ad-between').remove();
67
64
  $('.ezoic-ad-topic').remove();
68
- $('[id^="ezoic-pub-ad-placeholder-"]').remove();
69
65
  }
70
66
 
71
67
  function computeWindowSlots(totalItems, interval, poolSize) {
@@ -126,31 +122,13 @@ function insertAdMessagesBetweenReplies($posts, ids, interval) {
126
122
  return activeIds;
127
123
  }
128
124
 
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) {
125
+ function ezoicShow(ids) {
142
126
  if (!ids || !ids.length) return;
143
127
 
128
+ // Ezoic supports showAds(101,102,103) and recommends a single call with all ids.
144
129
  window.ezstandalone = window.ezstandalone || {};
145
130
  window.ezstandalone.cmd = window.ezstandalone.cmd || [];
146
-
147
131
  window.ezstandalone.cmd.push(function () {
148
- try {
149
- if (typeof window.ezstandalone.destroyPlaceholders === 'function') {
150
- window.ezstandalone.destroyPlaceholders.apply(window.ezstandalone, ids);
151
- }
152
- } catch (e) {}
153
-
154
132
  try {
155
133
  if (typeof window.ezstandalone.showAds === 'function') {
156
134
  window.ezstandalone.showAds.apply(window.ezstandalone, ids);
@@ -196,32 +174,29 @@ async function refreshAds() {
196
174
 
197
175
  removeExistingEzoicNodes();
198
176
 
199
- const combinedUnique = uniqueConcat(betweenPool, messagePool);
200
177
  const activeIds = [];
201
178
 
202
- // Category topic list page: use BETWEEN only
179
+ // Category pages: BETWEEN only (between topics)
203
180
  if ($topicItems.length) {
204
181
  if (cfg.enableBetweenAds && betweenPool.length) {
205
- activeIds.push(...insertBetweenGeneric($topicItems, combinedUnique.slice(0, betweenPool.length), betweenInterval, 'ezoic-ad-topic'));
182
+ activeIds.push(...insertBetweenGeneric($topicItems, betweenPool, betweenInterval, 'ezoic-ad-topic'));
206
183
  }
207
- ezoicCall(activeIds);
184
+ ezoicShow(activeIds);
208
185
  return;
209
186
  }
210
187
 
211
- // Topic page: ONLY message ads (as requested)
188
+ // Topic pages: MESSAGE only (between replies)
212
189
  if ($posts.length) {
213
190
  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));
191
+ activeIds.push(...insertAdMessagesBetweenReplies($posts, messagePool, messageInterval));
217
192
  }
218
- ezoicCall(activeIds);
193
+ ezoicShow(activeIds);
219
194
  }
220
195
  } finally {
221
196
  inFlight = false;
222
197
  if (rerunRequested) {
223
198
  rerunRequested = false;
224
- setTimeout(refreshAds, 50);
199
+ setTimeout(refreshAds, 80);
225
200
  }
226
201
  }
227
202
  }