nodebb-plugin-ezoic-infinite 0.5.8 → 0.5.9

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 +18 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
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,7 +28,16 @@ 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'));
33
+ }
34
+
35
+ function isCategoryTemplate() {
36
+ return !!(ajaxify && ajaxify.data && ajaxify.data.template === 'category');
37
+ }
38
+
31
39
  function getTopicPosts() {
40
+ if (!isTopicTemplate()) return $();
32
41
  const $primary = $('[component="post"][data-pid]');
33
42
  if ($primary.length) return $primary.not('.ezoic-ad-post');
34
43
 
@@ -44,8 +53,7 @@ function getTopicPosts() {
44
53
  }
45
54
 
46
55
  function getCategoryTopicItems() {
47
- // Only on category topic list pages
48
- if (!ajaxify || !ajaxify.data || ajaxify.data.template !== 'category') return $();
56
+ if (!isCategoryTemplate()) return $();
49
57
  return $('li[component="category/topic"]').not('.ezoic-ad-topic');
50
58
  }
51
59
 
@@ -191,29 +199,24 @@ async function refreshAds() {
191
199
  const combinedUnique = uniqueConcat(betweenPool, messagePool);
192
200
  const activeIds = [];
193
201
 
194
- if (!$posts.length && $topicItems.length) {
202
+ // Category topic list page: use BETWEEN only
203
+ if ($topicItems.length) {
195
204
  if (cfg.enableBetweenAds && betweenPool.length) {
196
205
  activeIds.push(...insertBetweenGeneric($topicItems, combinedUnique.slice(0, betweenPool.length), betweenInterval, 'ezoic-ad-topic'));
197
206
  }
207
+ ezoicCall(activeIds);
208
+ return;
198
209
  }
199
210
 
211
+ // Topic page: ONLY message ads (as requested)
200
212
  if ($posts.length) {
201
- let cursor = 0;
202
-
203
- if (cfg.enableBetweenAds && betweenPool.length) {
204
- const idsForBetween = combinedUnique.slice(cursor, cursor + betweenPool.length);
205
- cursor += idsForBetween.length;
206
- activeIds.push(...insertBetweenGeneric($posts, idsForBetween, betweenInterval, 'ezoic-ad-between'));
207
- }
208
-
209
213
  if (cfg.enableMessageAds && messagePool.length) {
210
- const idsForMessage = combinedUnique.slice(cursor, cursor + messagePool.length);
211
- cursor += idsForMessage.length;
214
+ // Use messagePool slice from the combined unique set, but keep it stable
215
+ const idsForMessage = combinedUnique.slice(0, messagePool.length);
212
216
  activeIds.push(...insertAdMessagesBetweenReplies($posts, idsForMessage, messageInterval));
213
217
  }
218
+ ezoicCall(activeIds);
214
219
  }
215
-
216
- ezoicCall(activeIds);
217
220
  } finally {
218
221
  inFlight = false;
219
222
  if (rerunRequested) {