nodebb-plugin-ezoic-infinite 0.7.2 → 0.7.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
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
@@ -58,7 +58,11 @@ async function fetchConfig() {
58
58
  }
59
59
 
60
60
  function isTopicPage() {
61
- return $('[component="post/content"]').length > 0 || $('[component="post"][data-pid]').length > 0;
61
+ try {
62
+ if (ajaxify && ajaxify.data && ajaxify.data.tid) return true;
63
+ } catch (e) {}
64
+ if (/^\/topic\//.test(window.location.pathname)) return true;
65
+ return $('[component="post/content"]').length > 0;
62
66
  }
63
67
 
64
68
  function isCategoryTopicListPage() {
@@ -139,7 +143,51 @@ function removeOldestCategoryAd() {
139
143
  return true;
140
144
  }
141
145
 
146
+
147
+ function setupAdAutoHeight() {
148
+ if (window.__ezoicAutoHeightAttached) return;
149
+ window.__ezoicAutoHeightAttached = true;
150
+
151
+ try {
152
+ const ro = new ResizeObserver(function (entries) {
153
+ for (const entry of entries) {
154
+ const el = entry.target;
155
+ el.style.minHeight = '0px';
156
+ el.style.height = 'auto';
157
+ }
158
+ });
159
+
160
+ function attach() {
161
+ document.querySelectorAll('.ezoic-ad').forEach(function (wrap) {
162
+ if (wrap.__ezoicRO) return;
163
+ wrap.__ezoicRO = true;
164
+ ro.observe(wrap);
165
+
166
+ const ph = wrap.querySelector('[id^="ezoic-pub-ad-placeholder-"]');
167
+ if (ph && ph.firstElementChild && !ph.firstElementChild.__ezoicRO) {
168
+ ph.firstElementChild.__ezoicRO = true;
169
+ ro.observe(ph.firstElementChild);
170
+ }
171
+ });
172
+ }
173
+
174
+ attach();
175
+ setTimeout(attach, 500);
176
+ setTimeout(attach, 1500);
177
+ setTimeout(attach, 3000);
178
+
179
+ const mo = new MutationObserver(function () { attach(); });
180
+ mo.observe(document.body, { childList: true, subtree: true });
181
+ } catch (e) {}
182
+ }
183
+
142
184
  function callEzoic(ids) {
185
+ const key = Array.isArray(ids) ? ids.join(',') : String(ids);
186
+ if (window.__ezoicLastShowKey === key && Date.now() - (window.__ezoicLastShowAt || 0) < 2000) {
187
+ return;
188
+ }
189
+ window.__ezoicLastShowKey = key;
190
+ window.__ezoicLastShowAt = Date.now();
143
191
  if (!ids || !ids.length) return;
144
192
 
145
193
  window.ezstandalone = window.ezstandalone || {};
@@ -160,14 +208,28 @@ function callEzoic(ids) {
160
208
  return false;
161
209
  };
162
210
 
211
+ setupAdAutoHeight();
163
212
  window.ezstandalone.cmd.push(function () { run(); });
164
213
 
214
+ // Retry only if showAds isn't available yet (avoid duplicate calls)
165
215
  let tries = 0;
166
216
  const maxTries = 6;
167
- const timer = setInterval(function () {
217
+ const retry = function () {
168
218
  tries++;
169
- if (run() || tries >= maxTries) clearInterval(timer);
170
- }, 800);
219
+ const ok = run();
220
+ if (ok) return;
221
+ try {
222
+ if (typeof window.ezstandalone.showAds === 'function') return;
223
+ } catch (e) {}
224
+ if (tries < maxTries) setTimeout(retry, 800);
225
+ };
226
+ try {
227
+ if (typeof window.ezstandalone.showAds !== 'function') {
228
+ setTimeout(retry, 800);
229
+ }
230
+ } catch (e) {
231
+ setTimeout(retry, 800);
232
+ }
171
233
  }
172
234
 
173
235
  function getPostNumber($post) {
@@ -281,7 +343,8 @@ async function refreshAds() {
281
343
  const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
282
344
 
283
345
  const onTopic = isTopicPage();
284
- const onCategory = !onTopic && isCategoryTopicListPage();
346
+ const hasTopicList = isCategoryTopicListPage();
347
+ const onCategory = !onTopic && hasTopicList;
285
348
 
286
349
  const newIds = [];
287
350
 
@@ -315,9 +378,9 @@ function debounceRefresh() {
315
378
  debounceTimer = setTimeout(refreshAds, 220);
316
379
  }
317
380
 
318
- $(document).ready(debounceRefresh);
381
+ $(document).ready(function(){ setupAdAutoHeight(); debounceRefresh(); });
319
382
  $(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded action:topics.loaded action:category.loaded', debounceRefresh);
320
- setTimeout(debounceRefresh, 2200);
383
+ setTimeout(function(){ setupAdAutoHeight(); debounceRefresh(); }, 2200);
321
384
 
322
385
  // Fallback: some themes/devices don't emit the expected events for infinite scroll.
323
386
  // Observe DOM additions and trigger a refresh when new posts/topics are appended/prepended.
package/public/style.css CHANGED
@@ -1,2 +1,5 @@
1
- .ezoic-ad-post{margin:0.75rem 0;}
2
- .ezoic-ad-message-inner{padding:0.75rem 0;}
1
+ .ezoic-ad{min-height:0 !important;height:auto !important;padding:0 !important;}
2
+ .ezoic-ad-post{margin:0.5rem 0;}
3
+ .ezoic-ad-topic{margin:0.5rem 0;}
4
+ .ezoic-ad-message-inner{padding:0;margin:0;}
5
+ .ezoic-ad-message-inner > div{margin:0;padding:0;}