@bebranded/bb-contents 1.0.29-beta → 1.0.31-beta
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/bb-contents.js +126 -9
- package/package.json +1 -1
package/bb-contents.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* BeBranded Contents
|
|
3
3
|
* Contenus additionnels français pour Webflow
|
|
4
|
-
* @version 1.0.
|
|
4
|
+
* @version 1.0.31-beta
|
|
5
5
|
* @author BeBranded
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @website https://www.bebranded.xyz
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
// Configuration
|
|
19
19
|
const config = {
|
|
20
|
-
version: '1.0.
|
|
21
|
-
debug:
|
|
20
|
+
version: '1.0.31-beta',
|
|
21
|
+
debug: false, // Désactivé par défaut pour une console propre
|
|
22
22
|
prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
|
|
23
23
|
i18n: {
|
|
24
24
|
copied: 'Lien copié !'
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
// Utilitaires
|
|
36
36
|
utils: {
|
|
37
37
|
log: function(...args) {
|
|
38
|
-
if (config.debug) {
|
|
38
|
+
if (bbContents.config.debug) {
|
|
39
39
|
console.log('[BB Contents]', ...args);
|
|
40
40
|
}
|
|
41
41
|
},
|
|
@@ -76,6 +76,9 @@
|
|
|
76
76
|
|
|
77
77
|
// Initialisation
|
|
78
78
|
init: function() {
|
|
79
|
+
// Console simple et épurée
|
|
80
|
+
console.log('bb-contents | v' + this.config.version);
|
|
81
|
+
|
|
79
82
|
this.utils.log('Initialisation v' + this.config.version);
|
|
80
83
|
|
|
81
84
|
// Déterminer la portée
|
|
@@ -526,11 +529,69 @@
|
|
|
526
529
|
|
|
527
530
|
// Module YouTube Feed
|
|
528
531
|
youtube: {
|
|
532
|
+
// Détection des bots pour éviter les appels API inutiles
|
|
533
|
+
isBot: function() {
|
|
534
|
+
const userAgent = navigator.userAgent.toLowerCase();
|
|
535
|
+
const botPatterns = [
|
|
536
|
+
'bot', 'crawler', 'spider', 'scraper', 'googlebot', 'bingbot', 'slurp',
|
|
537
|
+
'duckduckbot', 'baiduspider', 'yandexbot', 'facebookexternalhit', 'twitterbot',
|
|
538
|
+
'linkedinbot', 'whatsapp', 'telegrambot', 'discordbot', 'slackbot'
|
|
539
|
+
];
|
|
540
|
+
|
|
541
|
+
return botPatterns.some(pattern => userAgent.includes(pattern)) ||
|
|
542
|
+
navigator.webdriver ||
|
|
543
|
+
!navigator.userAgent;
|
|
544
|
+
},
|
|
545
|
+
|
|
546
|
+
// Gestion du cache localStorage
|
|
547
|
+
cache: {
|
|
548
|
+
get: function(key) {
|
|
549
|
+
try {
|
|
550
|
+
const cached = localStorage.getItem(key);
|
|
551
|
+
if (!cached) return null;
|
|
552
|
+
|
|
553
|
+
const data = JSON.parse(cached);
|
|
554
|
+
const now = Date.now();
|
|
555
|
+
|
|
556
|
+
// Cache expiré après 24h
|
|
557
|
+
if (now - data.timestamp > 24 * 60 * 60 * 1000) {
|
|
558
|
+
localStorage.removeItem(key);
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
return data.value;
|
|
563
|
+
} catch (e) {
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
|
|
568
|
+
set: function(key, value) {
|
|
569
|
+
try {
|
|
570
|
+
const data = {
|
|
571
|
+
value: value,
|
|
572
|
+
timestamp: Date.now()
|
|
573
|
+
};
|
|
574
|
+
localStorage.setItem(key, JSON.stringify(data));
|
|
575
|
+
} catch (e) {
|
|
576
|
+
// Ignorer les erreurs de localStorage
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
|
|
529
581
|
detect: function(scope) {
|
|
530
582
|
return scope.querySelector('[bb-youtube-channel]') !== null;
|
|
531
583
|
},
|
|
532
584
|
|
|
533
585
|
init: function(scope) {
|
|
586
|
+
// Vérifier si c'est un bot - pas d'appel API
|
|
587
|
+
if (this.isBot()) {
|
|
588
|
+
bbContents.utils.log('Bot détecté, pas de chargement YouTube (économie API)');
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// Nettoyer le cache expiré au démarrage
|
|
593
|
+
this.cleanCache();
|
|
594
|
+
|
|
534
595
|
const elements = scope.querySelectorAll('[bb-youtube-channel]');
|
|
535
596
|
if (elements.length === 0) return;
|
|
536
597
|
|
|
@@ -585,6 +646,16 @@
|
|
|
585
646
|
// Marquer l'élément comme traité par le module YouTube
|
|
586
647
|
element.setAttribute('data-bb-youtube-processed', 'true');
|
|
587
648
|
|
|
649
|
+
// Vérifier le cache d'abord
|
|
650
|
+
const cacheKey = `youtube_${channelId}_${videoCount}_${allowShorts}`;
|
|
651
|
+
const cachedData = this.cache.get(cacheKey);
|
|
652
|
+
|
|
653
|
+
if (cachedData) {
|
|
654
|
+
bbContents.utils.log('Données YouTube récupérées du cache (économie API)');
|
|
655
|
+
this.generateYouTubeFeed(container, template, cachedData, allowShorts);
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
|
|
588
659
|
// Afficher un loader
|
|
589
660
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Chargement des vidéos YouTube...</div>';
|
|
590
661
|
|
|
@@ -600,10 +671,29 @@
|
|
|
600
671
|
if (data.error) {
|
|
601
672
|
throw new Error(data.error.message || 'Erreur API YouTube');
|
|
602
673
|
}
|
|
674
|
+
|
|
675
|
+
// Sauvegarder en cache pour 24h
|
|
676
|
+
this.cache.set(cacheKey, data);
|
|
677
|
+
bbContents.utils.log('Données YouTube mises en cache pour 24h (économie API)');
|
|
678
|
+
|
|
603
679
|
this.generateYouTubeFeed(container, template, data, allowShorts);
|
|
604
680
|
})
|
|
605
681
|
.catch(error => {
|
|
606
682
|
bbContents.utils.log('Erreur dans le module youtube:', error);
|
|
683
|
+
|
|
684
|
+
// En cas d'erreur, essayer de récupérer du cache même expiré
|
|
685
|
+
const expiredCache = localStorage.getItem(cacheKey);
|
|
686
|
+
if (expiredCache) {
|
|
687
|
+
try {
|
|
688
|
+
const cachedData = JSON.parse(expiredCache);
|
|
689
|
+
bbContents.utils.log('Utilisation du cache expiré en cas d\'erreur API');
|
|
690
|
+
this.generateYouTubeFeed(container, template, cachedData.value, allowShorts);
|
|
691
|
+
return;
|
|
692
|
+
} catch (e) {
|
|
693
|
+
// Ignorer les erreurs de parsing
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
607
697
|
container.innerHTML = `<div style="padding: 20px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; color: #dc2626;"><strong>Erreur de chargement</strong><br>${error.message}</div>`;
|
|
608
698
|
});
|
|
609
699
|
});
|
|
@@ -741,6 +831,37 @@
|
|
|
741
831
|
const textarea = document.createElement('textarea');
|
|
742
832
|
textarea.innerHTML = text;
|
|
743
833
|
return textarea.value;
|
|
834
|
+
},
|
|
835
|
+
|
|
836
|
+
// Nettoyer le cache expiré
|
|
837
|
+
cleanCache: function() {
|
|
838
|
+
try {
|
|
839
|
+
const keys = Object.keys(localStorage);
|
|
840
|
+
const now = Date.now();
|
|
841
|
+
let cleaned = 0;
|
|
842
|
+
|
|
843
|
+
keys.forEach(key => {
|
|
844
|
+
if (key.startsWith('youtube_')) {
|
|
845
|
+
try {
|
|
846
|
+
const cached = JSON.parse(localStorage.getItem(key));
|
|
847
|
+
if (now - cached.timestamp > 24 * 60 * 60 * 1000) {
|
|
848
|
+
localStorage.removeItem(key);
|
|
849
|
+
cleaned++;
|
|
850
|
+
}
|
|
851
|
+
} catch (e) {
|
|
852
|
+
// Supprimer les clés corrompues
|
|
853
|
+
localStorage.removeItem(key);
|
|
854
|
+
cleaned++;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
if (cleaned > 0) {
|
|
860
|
+
bbContents.utils.log(`Cache YouTube nettoyé: ${cleaned} entrées supprimées`);
|
|
861
|
+
}
|
|
862
|
+
} catch (e) {
|
|
863
|
+
// Ignorer les erreurs de nettoyage
|
|
864
|
+
}
|
|
744
865
|
}
|
|
745
866
|
}
|
|
746
867
|
};
|
|
@@ -769,9 +890,5 @@
|
|
|
769
890
|
// Initialisation
|
|
770
891
|
initBBContents();
|
|
771
892
|
|
|
772
|
-
// Message de confirmation
|
|
773
|
-
console.log(
|
|
774
|
-
'%cBeBranded Contents v' + config.version + ' chargé avec succès !',
|
|
775
|
-
'color: #422eff; font-weight: bold; font-size: 14px;'
|
|
776
|
-
);
|
|
893
|
+
// Message de confirmation supprimé pour une console plus propre
|
|
777
894
|
})();
|