-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.js
More file actions
264 lines (228 loc) · 7.67 KB
/
content.js
File metadata and controls
264 lines (228 loc) · 7.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// Plugin DIMA - content.js - Version consolidée
// Détection de manipulation cognitive - M82 Project
// Version: 3.0 Refactored with ContentExtractor
// Note: All dependencies are loaded via manifest.json in correct order
// ============================================================================
// PARTIE 1: DÉTECTION DE SITES SUSPECTS (NOUVEAU)
// ============================================================================
/**
* Vérifie si le site actuel est dans la liste des sites suspects
* Cette fonction est fournie par suspiciousSitesManager.js
* et fonctionne automatiquement dès le chargement de la page
*/
function checkCurrentSiteInSuspiciousList() {
const currentUrl = window.location.href;
// Utiliser la fonction fournie par suspiciousSitesManager.js
const result = checkSuspiciousSite(currentUrl);
if (result.isSuspicious) {
console.log('⚠️ DIMA: Site suspect détecté!');
console.log('Source:', result.siteInfo.source);
console.log('Raison:', result.siteInfo.reason);
console.log('Niveau de risque:', result.siteInfo.riskLevel);
// Afficher une alerte visuelle
showSuspiciousSiteAlert(result);
}
}
/**
* Affiche une alerte pour un site suspect
*/
function showSuspiciousSiteAlert(result) {
// Créer un bandeau d'alerte en haut de la page
const alertBanner = document.createElement('div');
alertBanner.id = 'dima-suspicious-site-alert';
alertBanner.style.cssText = `
position: fixed;
top: 0;
left: 0;
right: 0;
background: linear-gradient(135deg, ${result.riskConfig.color}, ${result.riskConfig.color}dd);
color: white;
padding: 15px 20px;
z-index: 999999;
box-shadow: 0 2px 10px rgba(0,0,0,0.3);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
display: flex;
align-items: center;
justify-content: space-between;
animation: slideDown 0.5s ease-out;
`;
alertBanner.innerHTML = `
<div style="display: flex; align-items: center; gap: 15px; flex: 1;">
<span style="font-size: 24px;">${result.riskConfig.icon}</span>
<div>
<div style="font-weight: bold; font-size: 16px; margin-bottom: 5px;">
${result.riskConfig.label} - ${result.siteInfo.source}
</div>
<div style="font-size: 14px; opacity: 0.95;">
${result.siteInfo.reason}
</div>
<a href="${result.siteInfo.reportUrl}" target="_blank"
style="color: white; text-decoration: underline; font-size: 13px; margin-top: 5px; display: inline-block;">
→ Consulter le rapport source
</a>
</div>
</div>
<button id="dima-close-alert" style="
background: rgba(255,255,255,0.2);
border: 1px solid rgba(255,255,255,0.3);
color: white;
padding: 8px 15px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: background 0.3s;
">
✕ Fermer
</button>
`;
// Animation CSS
const style = document.createElement('style');
style.textContent = `
@keyframes slideDown {
from {
transform: translateY(-100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
#dima-close-alert:hover {
background: rgba(255,255,255,0.3) !important;
}
`;
document.head.appendChild(style);
// Ajouter au body
document.body.insertBefore(alertBanner, document.body.firstChild);
// Gérer la fermeture
document.getElementById('dima-close-alert').addEventListener('click', () => {
alertBanner.style.animation = 'slideDown 0.3s ease-out reverse';
setTimeout(() => alertBanner.remove(), 300);
});
// Ajuster le padding du body pour ne pas cacher le contenu
document.body.style.paddingTop = `${alertBanner.offsetHeight}px`;
}
// ============================================================================
// PARTIE 2: ANALYSE DIMA du site visité
// ============================================================================
// ===== CLASSE PRINCIPALE DIMA =====
class DIMAAnalyzer {
constructor() {
this.analysisResults = null;
this.cache = new Map();
this.settings = {
maxContentLength: 5000,
minKeywordLength: 3,
analysisDelay: 2000,
debugMode: false,
enhancedKeywords: true,
}; // Initialize ContentExtractor with settings
this.contentExtractor = new window.ContentExtractor(this.settings);
this.pageType = this.contentExtractor.detectPageType();
// Initialize TechniqueAnalyzer with dependencies
this.techniqueAnalyzer = new window.TechniqueAnalyzer(
this.settings,
window.DIMA_ENHANCED_KEYWORDS,
window.CONTEXT_PATTERNS,
window.DIMA_TECHNIQUES,
this.pageType
);
// Initialize UIManager
this.uiManager = new window.UIManager(this.settings);
this.uiManager.setPageType(this.pageType);
this.init();
}
init() {
this.log("Initialisation DIMA avec mots-clés améliorés...");
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () => {
this.delayedInit();
});
} else {
this.delayedInit();
}
}
delayedInit() {
setTimeout(() => {
try {
this.analyzeCurrentPage();
} catch (error) {
console.error("DIMA: Erreur lors de l'analyse:", error);
}
}, this.settings.analysisDelay);
}
log(message, data = null) {
if (this.settings.debugMode) {
console.log(`DIMA: ${message}`, data || "");
}
}
analyzeCurrentPage() {
try {
this.log("Analyse de la page...");
const cacheKey = window.location.href + document.title;
if (this.cache.has(cacheKey)) {
this.analysisResults = this.cache.get(cacheKey);
this.uiManager.createButton(this.analysisResults);
return;
}
const title = this.contentExtractor.extractTitle();
const content = this.contentExtractor.extractContent();
this.log("Titre extrait:", title);
this.log("Contenu extrait:", `${content.length} caractères`);
this.analysisResults = this.techniqueAnalyzer.performAnalysis(
title,
content
);
this.cache.set(cacheKey, this.analysisResults);
this.log("Analyse terminée, score:", this.analysisResults.globalScore);
this.uiManager.createButton(this.analysisResults);
} catch (error) {
console.error("DIMA: Erreur dans analyzeCurrentPage:", error);
}
}
}
// ===== INITIALISATION ET STYLES =====
// CSS pour les animations
const style = document.createElement("style");
style.textContent = `
@keyframes dimaFadeIn {
from { opacity: 0; transform: scale(0.9); }
to { opacity: 1; transform: scale(1); }
}
#dima-btn {
animation: dimaFadeIn 0.5s ease-out;
}
`;
document.head.appendChild(style);
// Initialisation sécurisée avec gestion d'erreurs améliorée
console.log("DIMA: Script chargé - Version complète avec mots-clés améliorés");
// Vérifier que toutes les dépendances sont chargées
function checkDependencies() {
return (
window.DIMA_TECHNIQUES &&
window.DIMA_ENHANCED_KEYWORDS &&
window.CONTEXT_PATTERNS &&
window.ContentExtractor &&
window.TechniqueAnalyzer &&
window.UIManager
);
}
// Initialiser avec retry si nécessaire
function initializeDIMA() {
if (!checkDependencies()) {
console.log("DIMA: Attente du chargement des dépendances...");
setTimeout(initializeDIMA, 100);
return;
}
try {
const analyzer = new DIMAAnalyzer();
console.log(
`DIMA: Analyseur initialisé pour page de type: ${analyzer.pageType}`
);
} catch (error) {
console.error("DIMA: Erreur d'initialisation critique:", error);
}
}
// Démarrer l'initialisation
initializeDIMA();