nodebb-plugin-niki-loyalty 1.0.6 → 1.0.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/package.json +1 -1
- package/static/lib/client.js +50 -30
package/package.json
CHANGED
package/static/lib/client.js
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
$(document).ready(function () {
|
|
4
4
|
// --- AYARLAR ---
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
const NIKI_LOGO_PATH = config.relative_path + '/plugins/nodebb-plugin-niki-loyalty/static/logo.png';
|
|
5
|
+
// 1. Logo Ayarı (Senin çalışan linkin)
|
|
6
|
+
const NIKI_LOGO_URL = "https://i.ibb.co/nZvtpss/logo-placeholder.png";
|
|
8
7
|
|
|
9
8
|
// Widget HTML Şablonu
|
|
10
9
|
const widgetHtml = `
|
|
11
10
|
<div id="niki-floating-widget" class="niki-hidden">
|
|
12
11
|
<div class="niki-widget-content" onclick="ajaxify.go('niki-wallet')">
|
|
13
|
-
<img src="${
|
|
12
|
+
<img src="${NIKI_LOGO_URL}" class="niki-widget-logo" alt="Niki">
|
|
14
13
|
<div class="niki-widget-text">
|
|
15
14
|
<span class="niki-lbl">PUANIM</span>
|
|
16
15
|
<span class="niki-val" id="niki-live-points">...</span>
|
|
@@ -19,59 +18,82 @@ $(document).ready(function () {
|
|
|
19
18
|
</div>
|
|
20
19
|
`;
|
|
21
20
|
|
|
22
|
-
// 1. Widget
|
|
21
|
+
// 1. Widget Başlatma ve Veri Yönetimi
|
|
23
22
|
function initNikiWidget() {
|
|
24
|
-
// Eğer giriş yapmamışsa çalışma
|
|
25
23
|
if (!app.user.uid || app.user.uid <= 0) return;
|
|
26
24
|
|
|
27
|
-
// Widget
|
|
25
|
+
// Widget yoksa ekle
|
|
28
26
|
if ($('#niki-floating-widget').length === 0) {
|
|
29
27
|
$('body').append(widgetHtml);
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
//
|
|
30
|
+
// --- HIZLI YÜKLEME (CACHE) ---
|
|
31
|
+
// Önce hafızadaki son puanı hemen göster (Bekletme yapmaz)
|
|
32
|
+
const cachedPoints = localStorage.getItem('niki_last_points');
|
|
33
|
+
if (cachedPoints !== null) {
|
|
34
|
+
$('#niki-live-points').text(cachedPoints);
|
|
35
|
+
$('#niki-floating-widget').removeClass('niki-hidden');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Logo Kontrolü (Garanti olsun)
|
|
39
|
+
fixLogo();
|
|
40
|
+
|
|
41
|
+
// --- GÜNCEL VERİ ÇEKME ---
|
|
42
|
+
// Arka planda sunucuya sor: "Puan değişti mi?"
|
|
33
43
|
$.get('/api/niki-loyalty/wallet-data', function(data) {
|
|
44
|
+
const freshPoints = data.points || 0;
|
|
45
|
+
|
|
34
46
|
// Puanı güncelle
|
|
35
|
-
$('#niki-live-points').text(
|
|
47
|
+
$('#niki-live-points').text(freshPoints);
|
|
48
|
+
$('#niki-floating-widget').removeClass('niki-hidden'); // İlk kez açılıyorsa göster
|
|
36
49
|
|
|
37
|
-
//
|
|
38
|
-
|
|
50
|
+
// Yeni puanı hafızaya at (Bir sonraki giriş için)
|
|
51
|
+
localStorage.setItem('niki_last_points', freshPoints);
|
|
52
|
+
|
|
53
|
+
// Logoyu tekrar kontrol et (Resim geç yüklendiyse)
|
|
54
|
+
fixLogo();
|
|
39
55
|
}).fail(function() {
|
|
40
|
-
// Hata olursa
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
// Hata olursa ve cache yoksa 0 yaz
|
|
57
|
+
if (cachedPoints === null) {
|
|
58
|
+
$('#niki-live-points').text('0');
|
|
59
|
+
$('#niki-floating-widget').removeClass('niki-hidden');
|
|
60
|
+
}
|
|
43
61
|
});
|
|
44
62
|
}
|
|
45
63
|
|
|
46
|
-
//
|
|
64
|
+
// Logo Düzeltici (Senin çalışan kodun entegresi)
|
|
65
|
+
function fixLogo() {
|
|
66
|
+
const img = document.querySelector("img.niki-widget-logo");
|
|
67
|
+
if (img && img.src !== NIKI_LOGO_URL) {
|
|
68
|
+
img.src = NIKI_LOGO_URL;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Başlat
|
|
47
73
|
initNikiWidget();
|
|
48
74
|
|
|
49
|
-
//
|
|
75
|
+
// Sayfa Geçişlerinde Tekrar Çalıştır
|
|
50
76
|
$(window).on('action:ajaxify.end', function () {
|
|
51
77
|
initNikiWidget();
|
|
78
|
+
setTimeout(fixLogo, 500); // 0.5sn sonra son bir kontrol
|
|
52
79
|
});
|
|
53
80
|
|
|
54
|
-
// --- AKTİFLİK
|
|
81
|
+
// --- AKTİFLİK SİSTEMİ (Heartbeat) ---
|
|
55
82
|
let activeSeconds = 0;
|
|
56
83
|
let isUserActive = false;
|
|
57
84
|
let idleTimer;
|
|
58
85
|
|
|
59
|
-
// Hareket algılayınca sayacı sıfırla
|
|
60
86
|
function resetIdleTimer() {
|
|
61
87
|
isUserActive = true;
|
|
62
88
|
clearTimeout(idleTimer);
|
|
63
|
-
idleTimer = setTimeout(() => { isUserActive = false; }, 30000);
|
|
89
|
+
idleTimer = setTimeout(() => { isUserActive = false; }, 30000);
|
|
64
90
|
}
|
|
65
91
|
$(window).on('mousemove scroll keydown click touchstart', resetIdleTimer);
|
|
66
92
|
|
|
67
|
-
// Her saniye kontrol et
|
|
68
93
|
setInterval(() => {
|
|
69
|
-
// Sadece "Topic" sayfalarında, sekme görünürse ve kullanıcı aktifse say
|
|
70
94
|
if (ajaxify.data.template.topic && document.visibilityState === 'visible' && isUserActive) {
|
|
71
95
|
activeSeconds++;
|
|
72
96
|
}
|
|
73
|
-
|
|
74
|
-
// 60 saniye dolunca sunucuya bildir
|
|
75
97
|
if (activeSeconds >= 60) {
|
|
76
98
|
sendHeartbeat();
|
|
77
99
|
activeSeconds = 0;
|
|
@@ -81,20 +103,18 @@ $(document).ready(function () {
|
|
|
81
103
|
function sendHeartbeat() {
|
|
82
104
|
$.post('/api/niki-loyalty/heartbeat', { _csrf: config.csrf_token }, function(res) {
|
|
83
105
|
if (res.earned) {
|
|
84
|
-
// Puanı
|
|
106
|
+
// Puanı güncelle
|
|
85
107
|
$('#niki-live-points').text(res.total);
|
|
86
|
-
|
|
87
|
-
|
|
108
|
+
// Hafızayı da güncelle
|
|
109
|
+
localStorage.setItem('niki_last_points', res.total);
|
|
110
|
+
|
|
88
111
|
showNikiToast(`+${res.points} Puan Kazandın! ☕`);
|
|
89
|
-
|
|
90
|
-
// Widget'ı zıplat
|
|
91
112
|
$('#niki-floating-widget').addClass('niki-bounce');
|
|
92
113
|
setTimeout(() => $('#niki-floating-widget').removeClass('niki-bounce'), 500);
|
|
93
114
|
}
|
|
94
115
|
});
|
|
95
116
|
}
|
|
96
117
|
|
|
97
|
-
// Özel Bildirim (Toast) Fonksiyonu
|
|
98
118
|
function showNikiToast(msg) {
|
|
99
119
|
$('.niki-toast').remove();
|
|
100
120
|
const toast = $(`<div class="niki-toast"><i class="fa fa-paw"></i> ${msg}</div>`);
|
|
@@ -102,7 +122,7 @@ $(document).ready(function () {
|
|
|
102
122
|
setTimeout(() => { toast.addClass('show'); }, 100);
|
|
103
123
|
setTimeout(() => {
|
|
104
124
|
toast.removeClass('show');
|
|
105
|
-
setTimeout(() => toast.remove(),
|
|
125
|
+
setTimeout(() => toast.remove(), 3000);
|
|
106
126
|
}, 3000);
|
|
107
127
|
}
|
|
108
128
|
});
|