nodebb-plugin-ezoic-infinite 0.6.0 → 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 +46 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.6.0",
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,28 +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
- return $('[data-pid]').filter(function () {
56
+
57
+ // Fallback: top-level data-pid that contains post content and isn't nested
58
+ const $top = $('[data-pid]').filter(function () {
44
59
  const $el = $(this);
45
60
  const hasContent = $el.find('[component="post/content"]').length > 0;
46
61
  const nested = $el.parents('[data-pid]').length > 0;
47
62
  return hasContent && !nested;
48
- }).not('.ezoic-ad-post');
63
+ });
64
+ return $top.not('.ezoic-ad-post');
49
65
  }
50
66
 
51
67
  function getCategoryTopicItems() {
52
- if (!isCategoryTemplate()) return $();
68
+ if (!guessIsCategoryPage()) return $();
53
69
  return $('li[component="category/topic"]').not('.ezoic-ad-topic');
54
70
  }
55
71
 
@@ -58,7 +74,6 @@ function tagName($el) {
58
74
  }
59
75
 
60
76
  function removeExistingEzoicNodes() {
61
- // Remove only the wrappers we created. Their inner placeholder divs go away with them.
62
77
  $('.ezoic-ad-post').remove();
63
78
  $('.ezoic-ad-between').remove();
64
79
  $('.ezoic-ad-topic').remove();
@@ -122,16 +137,32 @@ function insertAdMessagesBetweenReplies($posts, ids, interval) {
122
137
  return activeIds;
123
138
  }
124
139
 
125
- function ezoicShow(ids) {
140
+ function ezoicRender(ids) {
126
141
  if (!ids || !ids.length) return;
127
142
 
128
- // Ezoic supports showAds(101,102,103) and recommends a single call with all ids.
129
143
  window.ezstandalone = window.ezstandalone || {};
130
144
  window.ezstandalone.cmd = window.ezstandalone.cmd || [];
145
+
146
+ // Ezoic doc: showAds(101,102,103) within cmd.push for dynamic content citeturn0search0turn0search6
131
147
  window.ezstandalone.cmd.push(function () {
148
+ try {
149
+ if (typeof window.ezstandalone.refreshAds === 'function') {
150
+ window.ezstandalone.refreshAds.apply(window.ezstandalone, ids);
151
+ return;
152
+ }
153
+ } catch (e) {}
154
+
132
155
  try {
133
156
  if (typeof window.ezstandalone.showAds === 'function') {
134
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();
135
166
  }
136
167
  } catch (e) {}
137
168
  });
@@ -176,21 +207,21 @@ async function refreshAds() {
176
207
 
177
208
  const activeIds = [];
178
209
 
179
- // Category pages: BETWEEN only (between topics)
210
+ // Category pages: BETWEEN only
180
211
  if ($topicItems.length) {
181
212
  if (cfg.enableBetweenAds && betweenPool.length) {
182
213
  activeIds.push(...insertBetweenGeneric($topicItems, betweenPool, betweenInterval, 'ezoic-ad-topic'));
183
214
  }
184
- ezoicShow(activeIds);
215
+ ezoicRender(activeIds);
185
216
  return;
186
217
  }
187
218
 
188
- // Topic pages: MESSAGE only (between replies)
219
+ // Topic pages: MESSAGE only (as you requested)
189
220
  if ($posts.length) {
190
221
  if (cfg.enableMessageAds && messagePool.length) {
191
222
  activeIds.push(...insertAdMessagesBetweenReplies($posts, messagePool, messageInterval));
192
223
  }
193
- ezoicShow(activeIds);
224
+ ezoicRender(activeIds);
194
225
  }
195
226
  } finally {
196
227
  inFlight = false;