nodebb-plugin-ezoic-infinite 0.4.7 → 0.5.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.
- package/package.json +1 -1
- package/public/client.js +20 -44
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -23,33 +23,23 @@ function parsePool(raw) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Harmony
|
|
27
|
-
* -
|
|
28
|
-
* - Category topics list: li[component="category/topic"]
|
|
29
|
-
* - Categories list: li[component="categories/category"]
|
|
26
|
+
* Harmony (topic page) selector:
|
|
27
|
+
* - Posts: [component="post"]
|
|
30
28
|
*/
|
|
31
29
|
function getTopicPosts() {
|
|
32
30
|
const $p = $('[component="post"]').not('.ezoic-ad-post');
|
|
33
31
|
if ($p.length) return $p;
|
|
32
|
+
// fallback
|
|
34
33
|
return $('.posts .post').not('.ezoic-ad-post');
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
function getCategoryTopics() {
|
|
38
|
-
return $('li[component="category/topic"]').not('.ezoic-ad-topic');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getCategoriesList() {
|
|
42
|
-
return $('li[component="categories/category"]').not('.ezoic-ad-category');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
36
|
function removePlaceholdersByPool(pool) {
|
|
46
37
|
pool.forEach(id => $('#ezoic-pub-ad-placeholder-' + id).remove());
|
|
47
38
|
}
|
|
48
39
|
|
|
49
40
|
function removeAdWrappers() {
|
|
50
41
|
$('.ezoic-ad-post').remove();
|
|
51
|
-
$('.ezoic-ad-
|
|
52
|
-
$('.ezoic-ad-category').remove();
|
|
42
|
+
$('.ezoic-ad-between').remove();
|
|
53
43
|
}
|
|
54
44
|
|
|
55
45
|
function computeWindowSlots(totalItems, interval, poolSize) {
|
|
@@ -61,8 +51,8 @@ function computeWindowSlots(totalItems, interval, poolSize) {
|
|
|
61
51
|
return out;
|
|
62
52
|
}
|
|
63
53
|
|
|
64
|
-
function
|
|
65
|
-
const total = $
|
|
54
|
+
function insertBetweenPosts($posts, pool, interval) {
|
|
55
|
+
const total = $posts.length;
|
|
66
56
|
const slotsToRender = computeWindowSlots(total, interval, pool.length);
|
|
67
57
|
if (!slotsToRender.length) return [];
|
|
68
58
|
|
|
@@ -71,11 +61,10 @@ function insertBetween($items, pool, interval, wrapperClass) {
|
|
|
71
61
|
const slotNumber = slotsToRender[i];
|
|
72
62
|
const id = pool[i];
|
|
73
63
|
const index = slotNumber * interval - 1;
|
|
74
|
-
const $target = $
|
|
64
|
+
const $target = $posts.eq(index);
|
|
75
65
|
if (!$target.length) continue;
|
|
76
66
|
|
|
77
|
-
|
|
78
|
-
$target.after(html);
|
|
67
|
+
$target.after('<div class="ezoic-ad-between" id="ezoic-pub-ad-placeholder-' + id + '"></div>');
|
|
79
68
|
activeIds.push(id);
|
|
80
69
|
}
|
|
81
70
|
return activeIds;
|
|
@@ -117,6 +106,9 @@ async function refreshAds() {
|
|
|
117
106
|
const messagePool = parsePool(cfg.messagePlaceholderIds);
|
|
118
107
|
const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
|
|
119
108
|
|
|
109
|
+
const $posts = getTopicPosts();
|
|
110
|
+
if (!$posts.length) return; // only topic pages
|
|
111
|
+
|
|
120
112
|
// Clean first
|
|
121
113
|
removeAdWrappers();
|
|
122
114
|
removePlaceholdersByPool(betweenPool);
|
|
@@ -124,33 +116,17 @@ async function refreshAds() {
|
|
|
124
116
|
|
|
125
117
|
const activeIds = [];
|
|
126
118
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
if (cfg.enableMessageAds && messagePool.length) {
|
|
137
|
-
activeIds.push(...insertAdMessagesBetweenReplies($posts, messagePool, messageInterval));
|
|
138
|
-
}
|
|
139
|
-
} else if ($topics.length) {
|
|
140
|
-
// Category topic list (between topics)
|
|
141
|
-
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
142
|
-
activeIds.push(...insertBetween($topics, betweenPool, betweenInterval, 'ezoic-ad-topic'));
|
|
143
|
-
}
|
|
144
|
-
} else if ($cats.length) {
|
|
145
|
-
// Categories list (between categories)
|
|
146
|
-
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
147
|
-
activeIds.push(...insertBetween($cats, betweenPool, betweenInterval, 'ezoic-ad-category'));
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
return;
|
|
119
|
+
// Between posts
|
|
120
|
+
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
121
|
+
activeIds.push(...insertBetweenPosts($posts, betweenPool, betweenInterval));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// "Ad message" between replies
|
|
125
|
+
if (cfg.enableMessageAds && messagePool.length) {
|
|
126
|
+
activeIds.push(...insertAdMessagesBetweenReplies($posts, messagePool, messageInterval));
|
|
151
127
|
}
|
|
152
128
|
|
|
153
|
-
// Ezoic render
|
|
129
|
+
// Ezoic render
|
|
154
130
|
if (activeIds.length && window.ezstandalone && typeof window.ezstandalone.destroyPlaceholders === 'function') {
|
|
155
131
|
try { window.ezstandalone.destroyPlaceholders(); } catch (e) {}
|
|
156
132
|
}
|