nodebb-plugin-ezoic-infinite 0.4.4 → 0.4.7
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/library.js +4 -2
- package/package.json +1 -1
- package/public/admin.js +9 -3
- package/public/client.js +66 -35
package/library.js
CHANGED
|
@@ -23,9 +23,11 @@ function parseBool(v, def = false) {
|
|
|
23
23
|
async function getAllGroups() {
|
|
24
24
|
const names = await db.getSortedSetRange('groups:createtime', 0, -1);
|
|
25
25
|
const filtered = names.filter(name => !groups.isPrivilegeGroup(name));
|
|
26
|
-
|
|
26
|
+
const data = await groups.getGroupsData(filtered);
|
|
27
|
+
// Sort alphabetically for ACP usability
|
|
28
|
+
data.sort((a, b) => String(a.name).localeCompare(String(b.name), 'fr', { sensitivity: 'base' }));
|
|
29
|
+
return data;
|
|
27
30
|
}
|
|
28
|
-
|
|
29
31
|
async function getSettings() {
|
|
30
32
|
const s = await meta.settings.get(SETTINGS_KEY);
|
|
31
33
|
return {
|
package/package.json
CHANGED
package/public/admin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* globals
|
|
1
|
+
/* globals ajaxify */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
(function () {
|
|
@@ -6,13 +6,19 @@
|
|
|
6
6
|
const $form = $('.ezoic-infinite-settings');
|
|
7
7
|
if (!$form.length) return;
|
|
8
8
|
|
|
9
|
-
require(['settings'], function (Settings) {
|
|
9
|
+
require(['settings', 'alerts'], function (Settings, alerts) {
|
|
10
10
|
Settings.load('ezoic-infinite', $form);
|
|
11
11
|
|
|
12
12
|
$('#save').off('click.ezoicInfinite').on('click.ezoicInfinite', function (e) {
|
|
13
13
|
e.preventDefault();
|
|
14
|
+
|
|
14
15
|
Settings.save('ezoic-infinite', $form, function () {
|
|
15
|
-
|
|
16
|
+
// Toast vert (NodeBB core)
|
|
17
|
+
if (alerts && typeof alerts.success === 'function') {
|
|
18
|
+
alerts.success('Enregistré');
|
|
19
|
+
} else if (window.app && typeof window.app.alertSuccess === 'function') {
|
|
20
|
+
window.app.alertSuccess('Enregistré');
|
|
21
|
+
}
|
|
16
22
|
});
|
|
17
23
|
});
|
|
18
24
|
});
|
package/public/client.js
CHANGED
|
@@ -16,26 +16,44 @@ async function fetchConfig() {
|
|
|
16
16
|
function parsePool(raw) {
|
|
17
17
|
if (!raw) return [];
|
|
18
18
|
return Array.from(new Set(
|
|
19
|
-
raw.split(/[\n,;\s]+/)
|
|
19
|
+
String(raw).split(/[\n,;\s]+/)
|
|
20
20
|
.map(x => parseInt(x, 10))
|
|
21
21
|
.filter(n => Number.isFinite(n) && n > 0)
|
|
22
22
|
));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Harmony selectors:
|
|
27
|
+
* - Topic page posts: [component="post"]
|
|
28
|
+
* - Category topics list: li[component="category/topic"]
|
|
29
|
+
* - Categories list: li[component="categories/category"]
|
|
30
|
+
*/
|
|
31
|
+
function getTopicPosts() {
|
|
32
|
+
const $p = $('[component="post"]').not('.ezoic-ad-post');
|
|
33
|
+
if ($p.length) return $p;
|
|
34
|
+
return $('.posts .post').not('.ezoic-ad-post');
|
|
35
|
+
}
|
|
36
|
+
|
|
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');
|
|
27
43
|
}
|
|
28
44
|
|
|
29
45
|
function removePlaceholdersByPool(pool) {
|
|
30
46
|
pool.forEach(id => $('#ezoic-pub-ad-placeholder-' + id).remove());
|
|
31
47
|
}
|
|
32
48
|
|
|
33
|
-
function
|
|
49
|
+
function removeAdWrappers() {
|
|
34
50
|
$('.ezoic-ad-post').remove();
|
|
51
|
+
$('.ezoic-ad-topic').remove();
|
|
52
|
+
$('.ezoic-ad-category').remove();
|
|
35
53
|
}
|
|
36
54
|
|
|
37
|
-
function computeWindowSlots(
|
|
38
|
-
const slots = Math.floor(
|
|
55
|
+
function computeWindowSlots(totalItems, interval, poolSize) {
|
|
56
|
+
const slots = Math.floor(totalItems / interval);
|
|
39
57
|
if (slots <= 0) return [];
|
|
40
58
|
const start = Math.max(1, slots - poolSize + 1);
|
|
41
59
|
const out = [];
|
|
@@ -43,13 +61,8 @@ function computeWindowSlots(totalPosts, interval, poolSize) {
|
|
|
43
61
|
return out;
|
|
44
62
|
}
|
|
45
63
|
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const $posts = $('.posts .post').not('.ezoic-ad-post');
|
|
50
|
-
const total = $posts.length;
|
|
51
|
-
if (!total) return [];
|
|
52
|
-
|
|
64
|
+
function insertBetween($items, pool, interval, wrapperClass) {
|
|
65
|
+
const total = $items.length;
|
|
53
66
|
const slotsToRender = computeWindowSlots(total, interval, pool.length);
|
|
54
67
|
if (!slotsToRender.length) return [];
|
|
55
68
|
|
|
@@ -57,23 +70,19 @@ function insertBetweenPosts(pool, interval) {
|
|
|
57
70
|
for (let i = 0; i < slotsToRender.length; i++) {
|
|
58
71
|
const slotNumber = slotsToRender[i];
|
|
59
72
|
const id = pool[i];
|
|
60
|
-
const
|
|
61
|
-
const $target = $
|
|
73
|
+
const index = slotNumber * interval - 1;
|
|
74
|
+
const $target = $items.eq(index);
|
|
62
75
|
if (!$target.length) continue;
|
|
63
76
|
|
|
64
|
-
|
|
77
|
+
const html = '<div class="' + wrapperClass + '" id="ezoic-pub-ad-placeholder-' + id + '"></div>';
|
|
78
|
+
$target.after(html);
|
|
65
79
|
activeIds.push(id);
|
|
66
80
|
}
|
|
67
81
|
return activeIds;
|
|
68
82
|
}
|
|
69
83
|
|
|
70
|
-
function
|
|
71
|
-
if (!isTopicPage()) return [];
|
|
72
|
-
|
|
73
|
-
const $posts = $('.posts .post').not('.ezoic-ad-post');
|
|
84
|
+
function insertAdMessagesBetweenReplies($posts, pool, interval) {
|
|
74
85
|
const total = $posts.length;
|
|
75
|
-
if (!total) return [];
|
|
76
|
-
|
|
77
86
|
const slotsToRender = computeWindowSlots(total, interval, pool.length);
|
|
78
87
|
if (!slotsToRender.length) return [];
|
|
79
88
|
|
|
@@ -81,8 +90,8 @@ function insertAdMessages(pool, interval) {
|
|
|
81
90
|
for (let i = 0; i < slotsToRender.length; i++) {
|
|
82
91
|
const slotNumber = slotsToRender[i];
|
|
83
92
|
const id = pool[i];
|
|
84
|
-
const
|
|
85
|
-
const $target = $posts.eq(
|
|
93
|
+
const index = slotNumber * interval - 1;
|
|
94
|
+
const $target = $posts.eq(index);
|
|
86
95
|
if (!$target.length) continue;
|
|
87
96
|
|
|
88
97
|
const html =
|
|
@@ -101,7 +110,6 @@ function insertAdMessages(pool, interval) {
|
|
|
101
110
|
async function refreshAds() {
|
|
102
111
|
const cfg = await fetchConfig();
|
|
103
112
|
if (!cfg || cfg.excluded) return;
|
|
104
|
-
if (!isTopicPage()) return;
|
|
105
113
|
|
|
106
114
|
const betweenPool = parsePool(cfg.placeholderIds);
|
|
107
115
|
const betweenInterval = Math.max(1, parseInt(cfg.intervalPosts, 10) || 6);
|
|
@@ -109,24 +117,46 @@ async function refreshAds() {
|
|
|
109
117
|
const messagePool = parsePool(cfg.messagePlaceholderIds);
|
|
110
118
|
const messageInterval = Math.max(1, parseInt(cfg.messageIntervalPosts, 10) || 3);
|
|
111
119
|
|
|
112
|
-
|
|
120
|
+
// Clean first
|
|
121
|
+
removeAdWrappers();
|
|
113
122
|
removePlaceholdersByPool(betweenPool);
|
|
114
123
|
removePlaceholdersByPool(messagePool);
|
|
115
124
|
|
|
116
125
|
const activeIds = [];
|
|
117
126
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
127
|
+
const $posts = getTopicPosts();
|
|
128
|
+
const $topics = getCategoryTopics();
|
|
129
|
+
const $cats = getCategoriesList();
|
|
130
|
+
|
|
131
|
+
if ($posts.length) {
|
|
132
|
+
// Topic page (between replies)
|
|
133
|
+
if (cfg.enableBetweenAds && betweenPool.length) {
|
|
134
|
+
activeIds.push(...insertBetween($posts, betweenPool, betweenInterval, 'ezoic-ad-between'));
|
|
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;
|
|
124
151
|
}
|
|
125
152
|
|
|
126
|
-
|
|
127
|
-
|
|
153
|
+
// Ezoic render (placeholders are present in DOM regardless)
|
|
154
|
+
if (activeIds.length && window.ezstandalone && typeof window.ezstandalone.destroyPlaceholders === 'function') {
|
|
155
|
+
try { window.ezstandalone.destroyPlaceholders(); } catch (e) {}
|
|
128
156
|
}
|
|
129
|
-
activeIds.forEach(id =>
|
|
157
|
+
activeIds.forEach(id => {
|
|
158
|
+
try { window.ezstandalone && typeof window.ezstandalone.showAds === 'function' && window.ezstandalone.showAds(id); } catch (e) {}
|
|
159
|
+
});
|
|
130
160
|
}
|
|
131
161
|
|
|
132
162
|
function debounceRefresh() {
|
|
@@ -135,3 +165,4 @@ function debounceRefresh() {
|
|
|
135
165
|
}
|
|
136
166
|
|
|
137
167
|
$(window).on('action:ajaxify.end action:posts.loaded action:topic.loaded', debounceRefresh);
|
|
168
|
+
setTimeout(debounceRefresh, 800);
|