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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-niki-loyalty",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Niki The Cat Coffee Loyalty System - Earn points while studying on IEU Forum.",
5
5
  "main": "library.js",
6
6
  "nbbpm": {
@@ -2,8 +2,8 @@
2
2
 
3
3
  $(document).ready(function () {
4
4
  // --- AYARLAR ---
5
- // Buraya logonun linkini koy. Eğer link yoksa geçici bir kedi ikonu koydum.
6
- const NIKI_LOGO_URL = 'https://i.ibb.co/nZvtpss/logo-placeholder.png';
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 Ekrana Koyma ve Veri Çekme Fonksiyonu
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 zaten varsa tekrar ekleme, sadece veriyi güncelle
25
+ // Widget yoksa ekle
27
26
  if ($('#niki-floating-widget').length === 0) {
28
27
  $('body').append(widgetHtml);
29
28
  }
30
29
 
31
- // VERİYİ DOĞRU YERDEN ÇEK: wallet-data API'si (Kesin çözüm)
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(data.points || 0);
47
+ $('#niki-live-points').text(freshPoints);
48
+ $('#niki-floating-widget').removeClass('niki-hidden'); // İlk kez açılıyorsa göster
35
49
 
36
- // Widget'ı görünür yap
37
- $('#niki-floating-widget').removeClass('niki-hidden');
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 0 yaz ama widget'ı yine de göster
40
- $('#niki-live-points').text('0');
41
- $('#niki-floating-widget').removeClass('niki-hidden');
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
- // 2. Sayfa İlk Açıldığında Çalıştır
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
- // 3. Sayfa Değiştiğinde (Menülerde gezerken) Tekrar Çalıştır
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 VE PUAN KAZANMA SİSTEMİ ---
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); // 30sn hareketsizse pasif ol
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ı anlık güncelle
106
+ // Puanı güncelle
84
107
  $('#niki-live-points').text(res.total);
85
-
86
- // Bildirim göster
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(), 300);
125
+ setTimeout(() => toast.remove(), 3000);
105
126
  }, 3000);
106
127
  }
107
128
  });
Binary file