nodebb-plugin-ezoic-infinite 0.1.1 → 0.2.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/library.js +10 -0
- package/package.json +3 -17
- package/plugin.json +17 -4
- package/public/admin.js +17 -2
- package/public/client.js +6 -19
package/library.js
CHANGED
|
@@ -34,6 +34,16 @@ async function isUserExcluded(uid, excludedGroups) {
|
|
|
34
34
|
return userGroups[0].some(g => excludedGroups.includes(g.name));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
plugin.addAdminNavigation = async (header) => {
|
|
38
|
+
header.plugins = header.plugins || [];
|
|
39
|
+
header.plugins.push({
|
|
40
|
+
route: '/plugins/ezoic-infinite',
|
|
41
|
+
icon: 'fa-ad',
|
|
42
|
+
name: 'Ezoic Infinite Ads'
|
|
43
|
+
});
|
|
44
|
+
return header;
|
|
45
|
+
};
|
|
46
|
+
|
|
37
47
|
plugin.init = async ({ router, middleware }) => {
|
|
38
48
|
router.get('/admin/plugins/ezoic-infinite', middleware.admin.buildHeader, async (req, res) => {
|
|
39
49
|
const settings = await getSettings();
|
package/package.json
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-ezoic-infinite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Ezoic ads with infinite scroll using a pool of placeholder IDs",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"nodebb",
|
|
8
|
-
"nodebb-plugin",
|
|
9
8
|
"ezoic",
|
|
10
|
-
"ads"
|
|
11
|
-
"infinite-scroll"
|
|
9
|
+
"ads"
|
|
12
10
|
],
|
|
13
|
-
"license": "MIT"
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": ""
|
|
17
|
-
},
|
|
18
|
-
"engines": {
|
|
19
|
-
"node": ">=18"
|
|
20
|
-
},
|
|
21
|
-
"peerDependenciesMeta": {
|
|
22
|
-
"nodebb": {
|
|
23
|
-
"optional": true
|
|
24
|
-
}
|
|
25
|
-
}
|
|
11
|
+
"license": "MIT"
|
|
26
12
|
}
|
package/plugin.json
CHANGED
|
@@ -4,10 +4,23 @@
|
|
|
4
4
|
"description": "Ezoic ads with infinite scroll using a pool of placeholder IDs",
|
|
5
5
|
"library": "./library.js",
|
|
6
6
|
"hooks": [
|
|
7
|
-
{
|
|
7
|
+
{
|
|
8
|
+
"hook": "static:app.load",
|
|
9
|
+
"method": "init"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"hook": "filter:admin.header.build",
|
|
13
|
+
"method": "addAdminNavigation"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"staticDirs": {
|
|
17
|
+
"public": "public"
|
|
18
|
+
},
|
|
19
|
+
"acpScripts": [
|
|
20
|
+
"public/admin.js"
|
|
21
|
+
],
|
|
22
|
+
"scripts": [
|
|
23
|
+
"public/client.js"
|
|
8
24
|
],
|
|
9
|
-
"staticDirs": { "public": "public" },
|
|
10
|
-
"acpScripts": ["public/admin.js"],
|
|
11
|
-
"scripts": ["public/client.js"],
|
|
12
25
|
"templates": "public/templates"
|
|
13
26
|
}
|
package/public/admin.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
/* globals app */
|
|
1
|
+
/* globals app, ajaxify, config */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
function getCsrfToken() {
|
|
5
|
+
return (ajaxify?.data?.csrf_token) || (config?.csrf_token) || '';
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
$(document).ready(() => {
|
|
5
9
|
$('#save').on('click', function (e) {
|
|
6
10
|
e.preventDefault();
|
|
7
11
|
|
|
12
|
+
const csrf = getCsrfToken();
|
|
13
|
+
if (!csrf) {
|
|
14
|
+
app.alertError('CSRF token introuvable');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
8
18
|
$.ajax({
|
|
9
19
|
method: 'PUT',
|
|
10
20
|
url: '/api/admin/settings/ezoic-infinite',
|
|
21
|
+
headers: {
|
|
22
|
+
'x-csrf-token': csrf
|
|
23
|
+
},
|
|
11
24
|
data: {
|
|
12
25
|
placeholderIds: $('#placeholderIds').val(),
|
|
13
26
|
intervalPosts: $('#intervalPosts').val(),
|
|
@@ -15,6 +28,8 @@ $(document).ready(() => {
|
|
|
15
28
|
}
|
|
16
29
|
})
|
|
17
30
|
.done(() => app.alertSuccess('Paramètres enregistrés'))
|
|
18
|
-
.fail(() =>
|
|
31
|
+
.fail((xhr) => {
|
|
32
|
+
app.alertError(xhr?.responseJSON?.error || 'Erreur lors de la sauvegarde');
|
|
33
|
+
});
|
|
19
34
|
});
|
|
20
35
|
});
|
package/public/client.js
CHANGED
|
@@ -21,18 +21,6 @@ function parsePool(raw) {
|
|
|
21
21
|
));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function destroyEzoic() {
|
|
25
|
-
if (window.ezstandalone?.destroyPlaceholders) {
|
|
26
|
-
window.ezstandalone.destroyPlaceholders();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function showAd(id) {
|
|
31
|
-
if (window.ezstandalone?.showAds) {
|
|
32
|
-
window.ezstandalone.showAds(id);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
24
|
async function refreshAds() {
|
|
37
25
|
const cfg = await fetchConfig();
|
|
38
26
|
if (!cfg || cfg.excluded) return;
|
|
@@ -40,14 +28,12 @@ async function refreshAds() {
|
|
|
40
28
|
const pool = parsePool(cfg.placeholderIds);
|
|
41
29
|
const interval = cfg.intervalPosts;
|
|
42
30
|
const $posts = $('.posts .post');
|
|
43
|
-
|
|
44
31
|
if (!pool.length || !$posts.length) return;
|
|
45
32
|
|
|
46
|
-
pool.forEach(id => $(
|
|
33
|
+
pool.forEach(id => $('#ezoic-pub-ad-placeholder-' + id).remove());
|
|
47
34
|
|
|
48
35
|
const slots = Math.floor($posts.length / interval);
|
|
49
36
|
const start = Math.max(1, slots - pool.length + 1);
|
|
50
|
-
|
|
51
37
|
const activeIds = [];
|
|
52
38
|
|
|
53
39
|
for (let slot = start, i = 0; slot <= slots; slot++, i++) {
|
|
@@ -55,13 +41,14 @@ async function refreshAds() {
|
|
|
55
41
|
const index = slot * interval - 1;
|
|
56
42
|
const $target = $posts.eq(index);
|
|
57
43
|
if (!$target.length) continue;
|
|
58
|
-
|
|
59
|
-
$target.after(`<div id="ezoic-pub-ad-placeholder-${id}"></div>`);
|
|
44
|
+
$target.after('<div id="ezoic-pub-ad-placeholder-' + id + '"></div>');
|
|
60
45
|
activeIds.push(id);
|
|
61
46
|
}
|
|
62
47
|
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
if (window.ezstandalone?.destroyPlaceholders) {
|
|
49
|
+
window.ezstandalone.destroyPlaceholders();
|
|
50
|
+
}
|
|
51
|
+
activeIds.forEach(id => window.ezstandalone?.showAds?.(id));
|
|
65
52
|
}
|
|
66
53
|
|
|
67
54
|
function debounceRefresh() {
|