@bebranded/bb-contents 1.0.84 → 1.0.85
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 +59 -29
- 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.85
|
|
5
5
|
* @author BeBranded
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @website https://www.bebranded.xyz
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
window._bbContentsInitialized = true;
|
|
33
33
|
|
|
34
34
|
// Log de démarrage simple (une seule fois)
|
|
35
|
-
console.log('bb-contents | v1.0.
|
|
35
|
+
console.log('bb-contents | v1.0.85');
|
|
36
36
|
|
|
37
37
|
// Configuration
|
|
38
38
|
const config = {
|
|
39
|
-
version: '1.0.
|
|
39
|
+
version: '1.0.85',
|
|
40
40
|
debug: false, // Debug désactivé pour rendu propre
|
|
41
41
|
prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
|
|
42
42
|
youtubeEndpoint: null, // URL du worker YouTube (à définir par l'utilisateur)
|
|
@@ -973,21 +973,36 @@
|
|
|
973
973
|
|
|
974
974
|
// Module YouTube Feed
|
|
975
975
|
youtube: {
|
|
976
|
-
// Détection des bots pour éviter les appels API inutiles
|
|
976
|
+
// OPTIMISATION: Détection améliorée des bots pour éviter les appels API inutiles
|
|
977
977
|
isBot: function() {
|
|
978
978
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
979
979
|
const botPatterns = [
|
|
980
980
|
'bot', 'crawler', 'spider', 'scraper', 'googlebot', 'bingbot', 'slurp',
|
|
981
981
|
'duckduckbot', 'baiduspider', 'yandexbot', 'facebookexternalhit', 'twitterbot',
|
|
982
|
-
'linkedinbot', 'whatsapp', 'telegrambot', 'discordbot', 'slackbot'
|
|
982
|
+
'linkedinbot', 'whatsapp', 'telegrambot', 'discordbot', 'slackbot', 'headless',
|
|
983
|
+
'phantom', 'selenium', 'puppeteer', 'playwright', 'lighthouse', 'gtmetrix',
|
|
984
|
+
'pagespeed', 'pingdom', 'uptime', 'monitor', 'check', 'test'
|
|
983
985
|
];
|
|
984
986
|
|
|
985
|
-
|
|
987
|
+
// Vérifications supplémentaires pour détecter plus de bots
|
|
988
|
+
const isBot = botPatterns.some(pattern => userAgent.includes(pattern)) ||
|
|
986
989
|
navigator.webdriver ||
|
|
987
|
-
!navigator.userAgent
|
|
990
|
+
!navigator.userAgent ||
|
|
991
|
+
!window.chrome || // Détecte les navigateurs headless
|
|
992
|
+
navigator.userAgent.includes('HeadlessChrome') ||
|
|
993
|
+
window.navigator.plugins.length === 0; // Bots n'ont souvent pas de plugins
|
|
994
|
+
|
|
995
|
+
if (isBot) {
|
|
996
|
+
// Log pour debug (en mode debug seulement)
|
|
997
|
+
if (bbContents.config.debug) {
|
|
998
|
+
bbContents.utils.log('Bot détecté, pas d\'appel API YouTube');
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
return isBot;
|
|
988
1003
|
},
|
|
989
1004
|
|
|
990
|
-
//
|
|
1005
|
+
// OPTIMISATION: Cache amélioré avec protection contre les appels multiples
|
|
991
1006
|
cache: {
|
|
992
1007
|
get: function(key) {
|
|
993
1008
|
try {
|
|
@@ -997,7 +1012,7 @@
|
|
|
997
1012
|
const data = JSON.parse(cached);
|
|
998
1013
|
const now = Date.now();
|
|
999
1014
|
|
|
1000
|
-
// Cache
|
|
1015
|
+
// OPTIMISATION: Cache plus long (24h maintenu)
|
|
1001
1016
|
if (now - data.timestamp > 24 * 60 * 60 * 1000) {
|
|
1002
1017
|
localStorage.removeItem(key);
|
|
1003
1018
|
return null;
|
|
@@ -1022,6 +1037,21 @@
|
|
|
1022
1037
|
}
|
|
1023
1038
|
},
|
|
1024
1039
|
|
|
1040
|
+
// OPTIMISATION: Protection globale contre les appels multiples
|
|
1041
|
+
_activeRequests: new Set(),
|
|
1042
|
+
|
|
1043
|
+
isRequestActive: function(cacheKey) {
|
|
1044
|
+
return this._activeRequests.has(cacheKey);
|
|
1045
|
+
},
|
|
1046
|
+
|
|
1047
|
+
markRequestActive: function(cacheKey) {
|
|
1048
|
+
this._activeRequests.add(cacheKey);
|
|
1049
|
+
},
|
|
1050
|
+
|
|
1051
|
+
markRequestComplete: function(cacheKey) {
|
|
1052
|
+
this._activeRequests.delete(cacheKey);
|
|
1053
|
+
},
|
|
1054
|
+
|
|
1025
1055
|
detect: function(scope) {
|
|
1026
1056
|
return scope.querySelector('[bb-youtube-channel]') !== null;
|
|
1027
1057
|
},
|
|
@@ -1075,18 +1105,18 @@
|
|
|
1075
1105
|
}
|
|
1076
1106
|
|
|
1077
1107
|
if (!endpoint) {
|
|
1078
|
-
//
|
|
1108
|
+
// OPTIMISATION: Réduire drastiquement les retries (de 50 à 10)
|
|
1079
1109
|
const retryCount = element.getAttribute('data-youtube-retry-count') || '0';
|
|
1080
1110
|
const retries = parseInt(retryCount);
|
|
1081
1111
|
|
|
1082
|
-
if (retries <
|
|
1112
|
+
if (retries < 10) { // 10 * 500ms = 5 secondes max (plus espacé)
|
|
1083
1113
|
element.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Configuration YouTube en cours...</div>';
|
|
1084
1114
|
element.setAttribute('data-youtube-retry-count', (retries + 1).toString());
|
|
1085
1115
|
|
|
1086
|
-
//
|
|
1116
|
+
// OPTIMISATION: Espacer les retries (500ms au lieu de 100ms)
|
|
1087
1117
|
setTimeout(() => {
|
|
1088
1118
|
this.initElement(element);
|
|
1089
|
-
},
|
|
1119
|
+
}, 500);
|
|
1090
1120
|
return;
|
|
1091
1121
|
} else {
|
|
1092
1122
|
// Timeout après 5 secondes
|
|
@@ -1129,29 +1159,28 @@
|
|
|
1129
1159
|
return;
|
|
1130
1160
|
}
|
|
1131
1161
|
|
|
1132
|
-
//
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
if (!window[loadingKey]) {
|
|
1162
|
+
// OPTIMISATION: Protection globale contre les appels multiples
|
|
1163
|
+
if (this.isRequestActive(cacheKey)) {
|
|
1164
|
+
// Un appel est déjà en cours pour cette clé, attendre
|
|
1165
|
+
const checkActive = () => {
|
|
1166
|
+
if (!this.isRequestActive(cacheKey)) {
|
|
1138
1167
|
// L'autre appel est terminé, vérifier le cache
|
|
1139
1168
|
const newCachedData = this.cache.get(cacheKey);
|
|
1140
1169
|
if (newCachedData && newCachedData.value) {
|
|
1141
1170
|
this.generateYouTubeFeed(container, template, newCachedData.value, allowShorts, language);
|
|
1142
|
-
|
|
1171
|
+
} else {
|
|
1143
1172
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Erreur de chargement</div>';
|
|
1144
1173
|
}
|
|
1145
1174
|
} else {
|
|
1146
|
-
setTimeout(
|
|
1175
|
+
setTimeout(checkActive, 200); // Vérifier moins souvent
|
|
1147
1176
|
}
|
|
1148
1177
|
};
|
|
1149
|
-
|
|
1178
|
+
checkActive();
|
|
1150
1179
|
return;
|
|
1151
1180
|
}
|
|
1152
1181
|
|
|
1153
1182
|
// Marquer qu'un appel API est en cours
|
|
1154
|
-
|
|
1183
|
+
this.markRequestActive(cacheKey);
|
|
1155
1184
|
|
|
1156
1185
|
// Afficher un loader
|
|
1157
1186
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Chargement des vidéos YouTube...</div>';
|
|
@@ -1169,20 +1198,20 @@
|
|
|
1169
1198
|
throw new Error(data.error.message || 'Erreur API YouTube');
|
|
1170
1199
|
}
|
|
1171
1200
|
|
|
1172
|
-
// Sauvegarder en cache pour 24h
|
|
1201
|
+
// OPTIMISATION: Sauvegarder en cache pour 24h
|
|
1173
1202
|
this.cache.set(cacheKey, data);
|
|
1174
1203
|
// Données YouTube mises en cache pour 24h (économie API)
|
|
1175
1204
|
|
|
1176
1205
|
this.generateYouTubeFeed(container, template, data, allowShorts, language);
|
|
1177
1206
|
|
|
1178
|
-
// Libérer le verrou
|
|
1179
|
-
|
|
1207
|
+
// OPTIMISATION: Libérer le verrou avec la nouvelle méthode
|
|
1208
|
+
this.markRequestComplete(cacheKey);
|
|
1180
1209
|
})
|
|
1181
1210
|
.catch(error => {
|
|
1182
1211
|
// Erreur dans le module youtube
|
|
1183
1212
|
|
|
1184
|
-
// Libérer le verrou en cas d'erreur
|
|
1185
|
-
|
|
1213
|
+
// OPTIMISATION: Libérer le verrou en cas d'erreur
|
|
1214
|
+
this.markRequestComplete(cacheKey);
|
|
1186
1215
|
|
|
1187
1216
|
// En cas d'erreur, essayer de récupérer du cache même expiré
|
|
1188
1217
|
const expiredCache = localStorage.getItem(cacheKey);
|
|
@@ -1372,7 +1401,7 @@
|
|
|
1372
1401
|
return textarea.value;
|
|
1373
1402
|
},
|
|
1374
1403
|
|
|
1375
|
-
// Nettoyer le cache expiré
|
|
1404
|
+
// OPTIMISATION: Nettoyer le cache expiré (48h)
|
|
1376
1405
|
cleanCache: function() {
|
|
1377
1406
|
try {
|
|
1378
1407
|
const keys = Object.keys(localStorage);
|
|
@@ -1383,6 +1412,7 @@
|
|
|
1383
1412
|
if (key.startsWith('youtube_')) {
|
|
1384
1413
|
try {
|
|
1385
1414
|
const cached = JSON.parse(localStorage.getItem(key));
|
|
1415
|
+
// OPTIMISATION: Cache 24h maintenu
|
|
1386
1416
|
if (now - cached.timestamp > 24 * 60 * 60 * 1000) {
|
|
1387
1417
|
localStorage.removeItem(key);
|
|
1388
1418
|
cleaned++;
|