nodebb-plugin-ezoic-infinite 0.5.1 → 0.5.3
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 +38 -19
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -22,17 +22,16 @@ function parsePool(raw) {
|
|
|
22
22
|
));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* Harmony (topic page) selector:
|
|
27
|
-
* - Posts: [component="post"]
|
|
28
|
-
*/
|
|
29
25
|
function getTopicPosts() {
|
|
30
26
|
const $p = $('[component="post"]').not('.ezoic-ad-post');
|
|
31
27
|
if ($p.length) return $p;
|
|
32
|
-
// fallback
|
|
33
28
|
return $('.posts .post').not('.ezoic-ad-post');
|
|
34
29
|
}
|
|
35
30
|
|
|
31
|
+
function isLi($el) {
|
|
32
|
+
return ($el && $el.length && (($el.prop('tagName') || '').toUpperCase() === 'LI'));
|
|
33
|
+
}
|
|
34
|
+
|
|
36
35
|
function removePlaceholdersByPool(pool) {
|
|
37
36
|
pool.forEach(id => $('#ezoic-pub-ad-placeholder-' + id).remove());
|
|
38
37
|
}
|
|
@@ -51,6 +50,37 @@ function computeWindowSlots(totalItems, interval, poolSize) {
|
|
|
51
50
|
return out;
|
|
52
51
|
}
|
|
53
52
|
|
|
53
|
+
function makeBetweenWrapper($targetPost, placeholderId) {
|
|
54
|
+
if (isLi($targetPost)) {
|
|
55
|
+
return (
|
|
56
|
+
'<li class="ezoic-ad-between list-unstyled" data-ezoic-ad="1">' +
|
|
57
|
+
'<div id="ezoic-pub-ad-placeholder-' + placeholderId + '"></div>' +
|
|
58
|
+
'</li>'
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return '<div class="ezoic-ad-between" id="ezoic-pub-ad-placeholder-' + placeholderId + '"></div>';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function makeAdMessageWrapper($targetPost, placeholderId) {
|
|
65
|
+
if (isLi($targetPost)) {
|
|
66
|
+
return (
|
|
67
|
+
'<li class="post ezoic-ad-post" data-ezoic-ad="1">' +
|
|
68
|
+
'<div class="content">' +
|
|
69
|
+
'<div id="ezoic-pub-ad-placeholder-' + placeholderId + '"></div>' +
|
|
70
|
+
'</div>' +
|
|
71
|
+
'</li>'
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
'<div class="post ezoic-ad-post" data-ezoic-ad="1">' +
|
|
77
|
+
'<div class="content">' +
|
|
78
|
+
'<div id="ezoic-pub-ad-placeholder-' + placeholderId + '"></div>' +
|
|
79
|
+
'</div>' +
|
|
80
|
+
'</div>'
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
54
84
|
function insertBetweenPosts($posts, pool, interval) {
|
|
55
85
|
const total = $posts.length;
|
|
56
86
|
const slotsToRender = computeWindowSlots(total, interval, pool.length);
|
|
@@ -64,7 +94,7 @@ function insertBetweenPosts($posts, pool, interval) {
|
|
|
64
94
|
const $target = $posts.eq(index);
|
|
65
95
|
if (!$target.length) continue;
|
|
66
96
|
|
|
67
|
-
$target.after(
|
|
97
|
+
$target.after(makeBetweenWrapper($target, id));
|
|
68
98
|
activeIds.push(id);
|
|
69
99
|
}
|
|
70
100
|
return activeIds;
|
|
@@ -83,14 +113,7 @@ function insertAdMessagesBetweenReplies($posts, pool, interval) {
|
|
|
83
113
|
const $target = $posts.eq(index);
|
|
84
114
|
if (!$target.length) continue;
|
|
85
115
|
|
|
86
|
-
|
|
87
|
-
'<div class="post ezoic-ad-post" data-ezoic-ad="1">' +
|
|
88
|
-
'<div class="content">' +
|
|
89
|
-
'<div id="ezoic-pub-ad-placeholder-' + id + '"></div>' +
|
|
90
|
-
'</div>' +
|
|
91
|
-
'</div>';
|
|
92
|
-
|
|
93
|
-
$target.after(html);
|
|
116
|
+
$target.after(makeAdMessageWrapper($target, id));
|
|
94
117
|
activeIds.push(id);
|
|
95
118
|
}
|
|
96
119
|
return activeIds;
|
|
@@ -107,26 +130,22 @@ async function refreshAds() {
|
|
|
107
130
|
const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
|
|
108
131
|
|
|
109
132
|
const $posts = getTopicPosts();
|
|
110
|
-
if (!$posts.length) return;
|
|
133
|
+
if (!$posts.length) return;
|
|
111
134
|
|
|
112
|
-
// Clean first
|
|
113
135
|
removeAdWrappers();
|
|
114
136
|
removePlaceholdersByPool(betweenPool);
|
|
115
137
|
removePlaceholdersByPool(messagePool);
|
|
116
138
|
|
|
117
139
|
const activeIds = [];
|
|
118
140
|
|
|
119
|
-
// Between posts
|
|
120
141
|
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
121
142
|
activeIds.push(...insertBetweenPosts($posts, betweenPool, betweenInterval));
|
|
122
143
|
}
|
|
123
144
|
|
|
124
|
-
// "Ad message" between replies
|
|
125
145
|
if (cfg.enableMessageAds && messagePool.length) {
|
|
126
146
|
activeIds.push(...insertAdMessagesBetweenReplies($posts, messagePool, messageInterval));
|
|
127
147
|
}
|
|
128
148
|
|
|
129
|
-
// Ezoic render
|
|
130
149
|
if (activeIds.length && window.ezstandalone && typeof window.ezstandalone.destroyPlaceholders === 'function') {
|
|
131
150
|
try { window.ezstandalone.destroyPlaceholders(); } catch (e) {}
|
|
132
151
|
}
|