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