nodebb-plugin-ezoic-infinite 0.5.5 → 0.5.6

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 +32 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
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
@@ -39,11 +39,14 @@ function getTopicPosts() {
39
39
  return $('.posts .post').not('.ezoic-ad-post');
40
40
  }
41
41
 
42
+ function getCategoryTopicItems() {
43
+ return $('li[component="category/topic"]').not('.ezoic-ad-topic');
44
+ }
45
+
42
46
  function tagName($el) {
43
47
  return ($el && $el.length ? (($el.prop('tagName') || '').toUpperCase()) : '');
44
48
  }
45
49
 
46
- // Remove *all* nodes with a given id (duplicates are possible if misconfigured)
47
50
  function removePlaceholdersByPool(pool) {
48
51
  pool.forEach(id => $('[id="ezoic-pub-ad-placeholder-' + id + '"]').remove());
49
52
  }
@@ -51,6 +54,7 @@ function removePlaceholdersByPool(pool) {
51
54
  function removeAdWrappers() {
52
55
  $('.ezoic-ad-post').remove();
53
56
  $('.ezoic-ad-between').remove();
57
+ $('.ezoic-ad-topic').remove();
54
58
  }
55
59
 
56
60
  function computeWindowSlots(totalItems, interval, poolSize) {
@@ -70,8 +74,8 @@ function makeWrapperLike($target, classes, innerHtml) {
70
74
  return '<div class="' + classes + '" data-ezoic-ad="1">' + innerHtml + '</div>';
71
75
  }
72
76
 
73
- function insertBetweenPosts($posts, ids, interval) {
74
- const total = $posts.length;
77
+ function insertBetweenGeneric($items, ids, interval, wrapperClass) {
78
+ const total = $items.length;
75
79
  const slotsToRender = computeWindowSlots(total, interval, ids.length);
76
80
  if (!slotsToRender.length) return [];
77
81
 
@@ -80,10 +84,10 @@ function insertBetweenPosts($posts, ids, interval) {
80
84
  const slotNumber = slotsToRender[i];
81
85
  const id = ids[i];
82
86
  const index = slotNumber * interval - 1;
83
- const $target = $posts.eq(index);
87
+ const $target = $items.eq(index);
84
88
  if (!$target.length) continue;
85
89
 
86
- const html = makeWrapperLike($target, 'ezoic-ad-between', '<div id="ezoic-pub-ad-placeholder-' + id + '"></div>');
90
+ const html = makeWrapperLike($target, wrapperClass, '<div id="ezoic-pub-ad-placeholder-' + id + '"></div>');
87
91
  $target.after(html);
88
92
  activeIds.push(id);
89
93
  }
@@ -135,33 +139,41 @@ async function refreshAds() {
135
139
  const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
136
140
 
137
141
  const $posts = getTopicPosts();
138
- if (!$posts.length) return;
142
+ const $topicItems = getCategoryTopicItems();
143
+
144
+ if (!$posts.length && !$topicItems.length) return;
139
145
 
140
- // Clean first (remove wrappers + any placeholders, even duplicates)
141
146
  removeAdWrappers();
142
147
  removePlaceholdersByPool(uniqueConcat(betweenPool, messagePool));
143
148
 
144
- // IMPORTANT:
145
- // IDs must be UNIQUE on the page. If admin reuses the same IDs for both pools,
146
- // we allocate unique IDs across "between posts" and "message ads" to avoid duplicates.
147
149
  const combinedUnique = uniqueConcat(betweenPool, messagePool);
148
150
 
149
151
  const activeIds = [];
150
- let cursor = 0;
151
152
 
152
- if (cfg.enableBetweenAds && betweenPool.length) {
153
- const idsForBetween = combinedUnique.slice(cursor, cursor + betweenPool.length);
154
- cursor += idsForBetween.length;
155
- activeIds.push(...insertBetweenPosts($posts, idsForBetween, betweenInterval));
153
+ // Category topic list page: inject between topic items
154
+ if (!$posts.length && $topicItems.length) {
155
+ if (cfg.enableBetweenAds && betweenPool.length) {
156
+ activeIds.push(...insertBetweenGeneric($topicItems, combinedUnique.slice(0, betweenPool.length), betweenInterval, 'ezoic-ad-topic'));
157
+ }
156
158
  }
157
159
 
158
- if (cfg.enableMessageAds && messagePool.length) {
159
- const idsForMessage = combinedUnique.slice(cursor, cursor + messagePool.length);
160
- cursor += idsForMessage.length;
161
- activeIds.push(...insertAdMessagesBetweenReplies($posts, idsForMessage, messageInterval));
160
+ // Topic page: inject between replies + message ads
161
+ if ($posts.length) {
162
+ let cursor = 0;
163
+
164
+ if (cfg.enableBetweenAds && betweenPool.length) {
165
+ const idsForBetween = combinedUnique.slice(cursor, cursor + betweenPool.length);
166
+ cursor += idsForBetween.length;
167
+ activeIds.push(...insertBetweenGeneric($posts, idsForBetween, betweenInterval, 'ezoic-ad-between'));
168
+ }
169
+
170
+ if (cfg.enableMessageAds && messagePool.length) {
171
+ const idsForMessage = combinedUnique.slice(cursor, cursor + messagePool.length);
172
+ cursor += idsForMessage.length;
173
+ activeIds.push(...insertAdMessagesBetweenReplies($posts, idsForMessage, messageInterval));
174
+ }
162
175
  }
163
176
 
164
- // Ezoic render
165
177
  if (activeIds.length && window.ezstandalone && typeof window.ezstandalone.destroyPlaceholders === 'function') {
166
178
  try { window.ezstandalone.destroyPlaceholders(); } catch (e) {}
167
179
  }