mistral.ai
Table des matières
Mistral AI est une société française, donc soumise au droit français et européen (RGPD, etc.), mais pas au droit états-unien. Cependant, en 2026, une partie des serveurs Mistral AI est encore hébergée sous droits états-uniens, avec la menace que cela implique sur les données personnelles à cause de la loi états-unienne CLOUD Act. Contrairement à la plupart des autres sociétés de LLM, Mistral AI ne revend aucune donnée personnelle. Mais comme les autres, elle les utilise pour entraîner ses assistants, sauf pour les comptes utilisateurs dont certains paramètres ont été désactivés. Pour refuser l'utilisation des données personnelles pour l'entraînement, il faut :
- Créer un compte mistral.ai (gratuit) : https://chat.mistral.ai/chat
- Désactiver les options idoines dans https://chat.mistral.ai/work?profile_dialog=privacy et dans https://admin.mistral.ai/vibe/privacy
Note : Souscrire à Mistral Vibe Pro1), affiche quelques options supplémentaires et lève le bridage qui gèle les longues conversations pendant 2 heures consécutives.
Bookmarklets pour Mistral Vibe
Bon à savoir :
L'extension Firefox Markdown Viewer permet d'afficher de façon agréable et conviviale, tous les fichiers distants et locaux formatés au format Markdown.
⚠️ Pour que cette extension puisse lire les fichiers locaux au format Markdown, il faut configurer les autorisations comme suit :
- Dans le Gestionnaire d'extensions Firefox (addons), sélectionner Markdown Viewer > Onglet "Autorisations et données" : activer la permission "Accéder aux fichiers présents sur votre ordinateur"
- Dans l'onglet affichant un fichier Markdown, cliquer sur l'icône "m" de l'extension Markdown Viewer puis sur "ADVANCED OPTIONS" : un nouvel onglet affiche "File Access avec les 2 paramètres
file://qui doivent être activés : Cliquer sur le bouton "REFRESH" –> Firefox affiche une boîte de dialogue affichant "Markdown Viewer demande des paramètres supplémentaires. Nouvelles autorisations : Accéder à vos donner pour tous les sites web" –> Cliquer sur le bouton "Autoriser" - 3. Revenir sur l'onglet affichant le fichier markdown et rafraîchir la page
Bookmarklet d'export de conversation dans un fichier .md
Contenu d'un bookmarklet (en licence licence : WTFPL 2.0) qui permet d'exporter dans un fichier .md (Markdown), le verbatim de la conversation Mistral Vibe en cours sans la "réflexion" de l'assistant.
Fichier : file-mistral-chat-export-bookmarklet.js
javascript:(function () { /* ================================================================== file-mistral-chat-export-bookmarklet.js Télécharge la conversation mistral.ai affichée au format Markdown, VERSION BRÈVE : ignore les sections « Raisonnement (interne de l'assistant) » des messages (parties data-message-part-type= "reasoning"). Tout le reste est identique à la version full. Nom du fichier exporté : YYYY.MM.DD mistral.ai - TITRE_CONVERSATION.md Version 2.2 — 13/10/2026 : - renommé file-mistral-chat-export-brief-bookmarklet.js -> file-mistral-chat-export-bookmarklet.js ; suffixe « (brief) » retiré du nom du fichier exporté ; - tableaux interactifs (rich-ui, rendus par React) convertis au format Markdown, d'après le DOM réel du build du 12/10/2026 : grille CSS plate (en-têtes role="columnheader", cellules role="cell", sans role="row"), colonne d'options et cellules videuses exclues via data-rich-table-ui-only ; - correctif 2.1 : le marquage temporaire data-mistral-export-skip était retiré avant la conversion Markdown, ce qui laissait fuiter le contenu des tableaux React dans le texte ; il est désormais retiré après buildMarkdown(). Licence : WTFPL 2.0 (Do What The Fuck You Want To Public License) https://www.wtfpl.net/txt/copying/ ================================================================== */ var SKIP = { SCRIPT: 1, STYLE: 1, NOSCRIPT: 1, SVG: 1, PATH: 1, CIRCLE: 1, BUTTON: 1 }; var BLOCKS = { P: 1, H1: 1, H2: 1, H3: 1, H4: 1, H5: 1, H6: 1, UL: 1, OL: 1, PRE: 1, TABLE: 1, BLOCKQUOTE: 1, HR: 1, FIGURE: 1, FIGCAPTION: 1, DIV: 1, SECTION: 1, ARTICLE: 1, ADDRESS: 1, FIELDSET: 1 }; function clean(s) { return String(s) .replace(/[\t \u00a0\u200b]+/g, ' ') .replace(/ *\n */g, '\n') .replace(/\n{3,}/g, '\n\n') .replace(/^\n+/, '') .replace(/\n+$/, ''); } function stampNow(d) { var date = d.toLocaleDateString('fr-FR'); var time = d.toLocaleTimeString('fr-FR'); var tz = ''; try { var parts = new Intl.DateTimeFormat('fr-FR', { timeZoneName: 'short' }).formatToParts(d); for (var i = 0; i < parts.length; i++) if (parts[i].type === 'timeZoneName') tz = parts[i].value; } catch (e) { tz = ''; } return { date: date, time: time, tz: tz, text: 'le ' + date + ' à ' + time + (tz ? ' (' + tz + ')' : '') }; } function roleLabel(role) { if (role === 'user') return 'Utilisateur'; if (role === 'assistant') return 'Assistant'; return 'Message (' + (role || 'rôle inconnu') + ')'; } function getTitle(doc) { var t = (doc.title || '').trim(); if (!t) { var m = doc.querySelector('meta[property="og:title"]'); if (m) t = (m.getAttribute('content') || '').trim(); } return t || 'Conversation mistral.ai'; } function sanitizeTitle(t) { t = String(t).replace(/[<>:"/\\|?*\u0000-\u001f]/g, '').replace(/\s+/g, ' ').trim(); t = t.replace(/[. ]+$/, ''); if (t.length > 120) t = t.slice(0, 120).trim(); return t || 'Conversation'; } function fileNameFor(title, now, ext, suffix) { var y = now.getFullYear(); var mo = String(now.getMonth() + 1).padStart(2, '0'); var da = String(now.getDate()).padStart(2, '0'); return y + '.' + mo + '.' + da + ' mistral.ai - ' + sanitizeTitle(title) + (suffix || '') + '.' + ext; } /* ---------- Conversion HTML -> Markdown ---------- */ function inl(nodes) { var s = '', i, n, t; for (i = 0; i < nodes.length; i++) { n = nodes[i]; if (n.nodeType === 3) { s += n.data.replace(/\s+/g, ' '); continue; } if (n.nodeType !== 1) continue; var tg = n.tagName; if (SKIP[tg]) continue; if (n.getAttribute && n.getAttribute('data-mistral-export-skip')) continue; if (tg === 'BR') { s += '\n'; continue; } if (tg === 'STRONG' || tg === 'B') { t = inl(n.childNodes).trim(); if (t) s += '**' + t + '**'; continue; } if (tg === 'EM' || tg === 'I') { t = inl(n.childNodes).trim(); if (t) s += '*' + t + '*'; continue; } if (tg === 'CODE') { t = String(n.textContent).replace(/`/g, "'").trim(); if (t) s += '`' + t + '`'; continue; } if (tg === 'A') { var href = n.getAttribute('href') || ''; t = inl(n.childNodes).trim() || href; s += '[' + t + '](' + href + ')'; continue; } if (tg === 'IMG') { s += ' || '') + ')'; continue; } s += inl(n.childNodes); } return s; } function list(el, ordered, indent) { var s = '', idx = 0, i, j, k; var kids = el.children; for (i = 0; i < kids.length; i++) { var li = kids[i]; if (li.tagName !== 'LI') continue; idx++; var inlineNodes = [], nested = []; for (j = 0; j < li.childNodes.length; j++) { var c = li.childNodes[j]; if (c.nodeType === 1 && (c.tagName === 'UL' || c.tagName === 'OL')) nested.push(c); else inlineNodes.push(c); } var line = clean(inl(inlineNodes).replace(/[ \t]*\n[ \t]*/g, '\n')); s += indent + (ordered ? (idx + '. ') : '- ') + line.replace(/\n/g, '\n' + indent + ' ') + '\n'; for (k = 0; k < nested.length; k++) s += list(nested[k], nested[k].tagName === 'OL', indent + ' '); } return s + '\n'; } function table(el) { var rows = el.querySelectorAll('tr'); var lines = [], i, j; for (i = 0; i < rows.length; i++) { var cells = [], kids = rows[i].children; for (j = 0; j < kids.length; j++) { if (kids[j].tagName === 'TD' || kids[j].tagName === 'TH') { cells.push(inl(kids[j].childNodes).replace(/\s+/g, ' ').replace(/\|/g, '\\|').trim()); } } if (cells.length) lines.push('| ' + cells.join(' | ') + ' |'); } if (!lines.length) return ''; var sep = '|'; for (i = 0; i < lines[0].split('|').length - 2; i++) sep += ' --- |'; return lines[0] + '\n' + sep + '\n' + lines.slice(1).join('\n') + '\n\n'; } function blocks(el) { var s = '', buf = '', i; function flush() { var t = clean(buf); if (t) s += t + '\n\n'; buf = ''; } var kids = el.childNodes; for (i = 0; i < kids.length; i++) { var n = kids[i]; if (n.nodeType === 3) { buf += n.data; continue; } if (n.nodeType !== 1) continue; var tg = n.tagName; if (SKIP[tg]) continue; /* tableaux interactifs : exclus du parcours, restitués en Markdown */ if (n.getAttribute && n.getAttribute('data-mistral-export-skip')) continue; /* vignettes de durée des lecteurs audio joints (ex. "00:06") */ if (tg === 'DIV' && /^\d{1,2}:\d{2}(:\d{2})?$/.test(String(n.textContent).trim())) continue; if (!BLOCKS[tg]) { buf += inl([n]); continue; } flush(); var t, lvl; if (tg === 'P') { t = clean(inl(n.childNodes)); if (t) s += t + '\n\n'; } else if (tg === 'H1' || tg === 'H2' || tg === 'H3' || tg === 'H4' || tg === 'H5' || tg === 'H6') { lvl = parseInt(tg.charAt(1), 10); t = inl(n.childNodes).replace(/\n/g, ' ').trim(); if (t) s += '######'.slice(0, lvl) + ' ' + t + '\n\n'; } else if (tg === 'UL') { s += list(n, false, ''); } else if (tg === 'OL') { s += list(n, true, ''); } else if (tg === 'PRE') { s += '```\n' + String(n.textContent).replace(/\n+$/, '') + '\n```\n\n'; } else if (tg === 'TABLE') { s += table(n); } else if (tg === 'BLOCKQUOTE') { var inner = blocks(n).trim(); if (inner) s += inner.split('\n').map(function (l) { return '> ' + l; }).join('\n') + '\n\n'; } else if (tg === 'HR') { s += '---\n\n'; } else { s += blocks(n); } } flush(); return s; } /* ---------- Tableaux interactifs (rendus par React) ---------- */ function sepLineFor(line) { var sep = '|', n = line.split('|').length - 2, i; for (i = 0; i < n; i++) sep += ' --- |'; return sep; } function cellText(el) { return String(el.textContent).replace(/\s+/g, ' ').replace(/\|/g, '\\|').trim(); } function richTableToMarkdown(tbl) { /* 1. tableaux avec lignes explicites (role="row" ou tr) */ var rows = tbl.querySelectorAll('[role="row"], tr'), i, j; if (rows.length) { var lns = []; for (i = 0; i < rows.length; i++) { var cs = rows[i].querySelectorAll('[role="cell"], [role="columnheader"], [role="rowheader"], th, td'); var ln = []; for (j = 0; j < cs.length; j++) { if (cs[j].getAttribute('data-rich-table-ui-only')) continue; var ct = cellText(cs[j]); if (ct) ln.push(ct); } if (ln.length) lns.push('| ' + ln.join(' | ') + ' |'); } if (lns.length) return lns[0] + '\n' + sepLineFor(lns[0]) + '\n' + lns.slice(1).join('\n'); } /* 2. grille CSS plate (build 2026.10.12) : les cellules sont des enfants directs du conteneur role="table", sans role="row" ; la colonne d'options et les cellules videuses portent data-rich-table-ui-only et sont exclues */ var heads = [], cells = [], all = tbl.querySelectorAll('[role="columnheader"], [role="cell"], [role="rowheader"], th, td'); for (i = 0; i < all.length; i++) { var c = all[i]; if (c.getAttribute('data-rich-table-ui-only')) continue; if (c.getAttribute('aria-hidden') === 'true' && !String(c.textContent).trim()) continue; var rl = c.getAttribute('role') || (c.tagName === 'TH' ? 'columnheader' : ''); if (rl === 'columnheader' || rl === 'rowheader') heads.push(c); else cells.push(c); } while (heads.length && !cellText(heads[heads.length - 1])) heads.pop(); if (!heads.length && !cells.length) return ''; var ncols = heads.length; if (!ncols) { var gm = /repeat\(\s*(\d+)/.exec(tbl.getAttribute('style') || ''); if (gm) ncols = parseInt(gm[1], 10); } if (!ncols || ncols > cells.length) ncols = Math.max(1, Math.ceil(Math.sqrt(cells.length))); var L = []; if (heads.length) { var hl = []; for (i = 0; i < heads.length; i++) hl.push(cellText(heads[i])); L.push('| ' + hl.join(' | ') + ' |'); } for (i = 0; i < cells.length; i += ncols) { var row = []; for (j = i; j < Math.min(i + ncols, cells.length); j++) row.push(cellText(cells[j])); L.push('| ' + row.join(' | ') + ' |'); } if (!L.length) return ''; return L[0] + '\n' + sepLineFor(L[0]) + '\n' + L.slice(1).join('\n'); } function collectRichTables(msg) { var found = msg.querySelectorAll('[data-rich-table-inner-html], [role="table"], [role="grid"]'); var out = [], i, k; for (i = 0; i < found.length; i++) { var t = found[i]; /* une éventuelle cellule marquée remonte à son conteneur de tableau */ try { t = t.closest('[role="table"], [role="grid"]') || t; } catch (e) {} var dup = false; for (k = 0; k < out.length; k++) if (out[k] === t || out[k].contains(t)) { dup = true; break; } if (dup) continue; if (!t.querySelector('[role="cell"], [role="columnheader"], [role="rowheader"], th, td')) continue; /* exclu des parcours texte ; restitué au format Markdown */ t.setAttribute('data-mistral-export-skip', '1'); out.push(t); } return out; } function attachTables(container, rtables) { var got = [], k; for (k = 0; k < rtables.length; k++) { if (rtables[k] && container.contains(rtables[k])) { got.push(richTableToMarkdown(rtables[k])); rtables[k] = null; } } return got; } /* ---------- Collecte des messages ---------- */ function collectMessages(doc) { var root = doc.querySelector('[data-testid="conversation-layout"]') || doc.body || doc.documentElement; var found = root.querySelectorAll('[data-message-author-role]'); var msgs = []; for (var i = 0; i < found.length; i++) { var m = found[i]; var role = (m.getAttribute('data-message-author-role') || '').toLowerCase(); var rtables = collectRichTables(m); var parts = m.querySelectorAll('[data-message-part-type]'); var items = []; if (parts.length) { for (var j = 0; j < parts.length; j++) { items.push({ type: (parts[j].getAttribute('data-message-part-type') || '').toLowerCase(), el: parts[j], tables: attachTables(parts[j], rtables) }); } var loose = [], k; for (k = 0; k < rtables.length; k++) if (rtables[k]) loose.push(richTableToMarkdown(rtables[k])); if (loose.length) items.push({ type: 'answer', el: null, tables: loose }); if (m.querySelectorAll('[data-canva-minified]').length) items.push({ type: 'canvas', el: null }); } else { items.push({ type: 'answer', el: m, tables: attachTables(m, rtables) }); } msgs.push({ role: role, parts: items }); } /* NB : le marquage data-mistral-export-skip est volontairement retiré APRÈS buildMarkdown() (voir Export) : la conversion Markdown doit écarter les tableaux interactifs déjà convertis en Markdown. */ return msgs; } function buildMarkdown(msgs, title, st, href) { var L = []; var nbUser = 0, nbAsst = 0, i, j; for (i = 0; i < msgs.length; i++) { if (msgs[i].role === 'user') nbUser++; else if (msgs[i].role === 'assistant') nbAsst++; } L.push('# ' + title); L.push(''); L.push('> **Exporté depuis [mistral.ai](' + href + ')** ' + st.text + ' — version brève, sans le raisonnement interne de l\'assistant.'); L.push('> **' + msgs.length + ' messages** — ' + nbUser + ' de l\'utilisateur, ' + nbAsst + ' de l\'assistant.'); L.push("> *Note : l'heure d'émission de chaque message n'est pas exposée par l'interface mistral.ai ; l'horodatage ci-dessus correspond au moment de l'export.*"); L.push(''); L.push('---'); L.push(''); for (i = 0; i < msgs.length; i++) { var msg = msgs[i]; L.push('______________________________________________________________________'); L.push('## Msg ' + (i + 1) + '/' + msgs.length + ' - ' + roleLabel(msg.role)); L.push(''); for (j = 0; j < msg.parts.length; j++) { var p = msg.parts[j]; /* version brève : les parties « reasoning » sont ignorées */ if (p.type === 'reasoning') continue; if (p.type === 'canvas') { L.push('*[Canvas associé à ce message — son contenu ne fait pas partie du fil de conversation et n\'est pas inclus dans cet export.]*'); L.push(''); } else { var at = p.el ? clean(blocks(p.el)) : ''; if (at) { L.push(at); L.push(''); } for (var q = 0; q < (p.tables || []).length; q++) { L.push(p.tables[q]); L.push(''); } } } } return L.join('\n').replace(/\n{3,}/g, '\n\n').trim() + '\n'; } /* ---------- Export ---------- */ var now = new Date(); var st = stampNow(now); var title = getTitle(document); var msgs = collectMessages(document); if (!msgs.length) { alert("❌ Aucun message trouvé. Ouvrez une conversation mistral.ai dans cet onglet puis réessayez."); return; } var href = (typeof location !== 'undefined' && location && location.href) ? location.href : ''; var md = buildMarkdown(msgs, title, st, href); /* retrait du marquage temporaire APRÈS la conversion Markdown */ var marked = document.querySelectorAll('[data-mistral-export-skip]'); for (var q = 0; q < marked.length; q++) marked[q].removeAttribute('data-mistral-export-skip'); var filename = fileNameFor(title, now, 'md', ''); var blob = new Blob([md], { type: 'text/markdown;charset=utf-8' }); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); setTimeout(function () { document.body.removeChild(a); URL.revokeObjectURL(url); }, 500); alert('✅ Fichier "' + filename + '" téléchargé (' + msgs.length + ' messages, ' + md.length + ' caractères).'); })();
Bookmarklet d'export de conversation complète dans un fichier .md
Contenu d'un bookmarklet (en licence licence : WTFPL 2.0) qui permet d'exporter dans un fichier .md (Markdown), le verbatim COMPLET de la conversation Mistral Vibe en cours avec la "réflexion" de l'assistant.
Fichier : file-mistral-chat-export-full-bookmarklet.js
javascript:(function () { /* ================================================================== file-mistral-chat-export-full-bookmarklet.js Télécharge le verbatim COMPLET de la conversation mistral.ai affichée, au format Markdown. Nom du fichier exporté : YYYY.MM.DD mistral.ai - TITRE_CONVERSATION (full).md Optimisations par rapport à la version du 25/08/2026 : - sélection des messages via [data-message-author-role] (l'ancien sélecteur ".select-none" ratait les réponses) ; - parties de message via [data-message-part-type] ("answer" = réponse, "reasoning" = raisonnement interne) ; - conversion HTML -> Markdown (titres, gras, italique, listes, tableaux, liens, images, blocs de code) au lieu d'un simple innerText aplati ; - horodatage d'export unique dans l'en-tête du fichier, en-tête de section « Msg N/total - Rôle » par message ; - nom de fichier conforme, titre nettoyé (accents conservés) ; - tableaux interactifs (rich-ui, rendus par React) convertis au format Markdown, d'après le DOM réel du build du 12/10/2026 : grille CSS plate (en-têtes role="columnheader", cellules role="cell", sans role="row"), colonne d'options et cellules videuses exclues via data-rich-table-ui-only. Version : 2.2 — 13/10/2026 TODO: zones d'étapes (libellés d'outils, commandes et sorties d'outils) — non exportées à ce jour (elles vivent hors des parties de message) ; nécessite une capture DOM d'une étape d'outil dépliée pour être implémenté. Correctif 2.1 : le marquage temporaire data-mistral-export-skip était retiré avant la conversion Markdown, ce qui laissait fuiter le contenu des tableaux React dans le texte ; il est désormais retiré après buildMarkdown(). Licence : WTFPL 2.0 (Do What The Fuck You Want To Public License) https://www.wtfpl.net/txt/copying/ ================================================================== */ var SKIP = { SCRIPT: 1, STYLE: 1, NOSCRIPT: 1, SVG: 1, PATH: 1, CIRCLE: 1, BUTTON: 1 }; var BLOCKS = { P: 1, H1: 1, H2: 1, H3: 1, H4: 1, H5: 1, H6: 1, UL: 1, OL: 1, PRE: 1, TABLE: 1, BLOCKQUOTE: 1, HR: 1, FIGURE: 1, FIGCAPTION: 1, DIV: 1, SECTION: 1, ARTICLE: 1, ADDRESS: 1, FIELDSET: 1 }; function clean(s) { return String(s) .replace(/[\t \u00a0\u200b]+/g, ' ') .replace(/ *\n */g, '\n') .replace(/\n{3,}/g, '\n\n') .replace(/^\n+/, '') .replace(/\n+$/, ''); } function stampNow(d) { var date = d.toLocaleDateString('fr-FR'); var time = d.toLocaleTimeString('fr-FR'); var tz = ''; try { var parts = new Intl.DateTimeFormat('fr-FR', { timeZoneName: 'short' }).formatToParts(d); for (var i = 0; i < parts.length; i++) if (parts[i].type === 'timeZoneName') tz = parts[i].value; } catch (e) { tz = ''; } return { date: date, time: time, tz: tz, text: 'le ' + date + ' à ' + time + (tz ? ' (' + tz + ')' : '') }; } function roleLabel(role) { if (role === 'user') return 'Utilisateur'; if (role === 'assistant') return 'Assistant'; return 'Message (' + (role || 'rôle inconnu') + ')'; } function getTitle(doc) { var t = (doc.title || '').trim(); if (!t) { var m = doc.querySelector('meta[property="og:title"]'); if (m) t = (m.getAttribute('content') || '').trim(); } return t || 'Conversation mistral.ai'; } function sanitizeTitle(t) { t = String(t).replace(/[<>:"/\\|?*\u0000-\u001f]/g, '').replace(/\s+/g, ' ').trim(); t = t.replace(/[. ]+$/, ''); if (t.length > 120) t = t.slice(0, 120).trim(); return t || 'Conversation'; } function fileNameFor(title, now, ext, suffix) { var y = now.getFullYear(); var mo = String(now.getMonth() + 1).padStart(2, '0'); var da = String(now.getDate()).padStart(2, '0'); return y + '.' + mo + '.' + da + ' mistral.ai - ' + sanitizeTitle(title) + (suffix || '') + '.' + ext; } /* ---------- Conversion HTML -> Markdown ---------- */ function inl(nodes) { var s = '', i, n, t; for (i = 0; i < nodes.length; i++) { n = nodes[i]; if (n.nodeType === 3) { s += n.data.replace(/\s+/g, ' '); continue; } if (n.nodeType !== 1) continue; var tg = n.tagName; if (SKIP[tg]) continue; if (n.getAttribute && n.getAttribute('data-mistral-export-skip')) continue; if (tg === 'BR') { s += '\n'; continue; } if (tg === 'STRONG' || tg === 'B') { t = inl(n.childNodes).trim(); if (t) s += '**' + t + '**'; continue; } if (tg === 'EM' || tg === 'I') { t = inl(n.childNodes).trim(); if (t) s += '*' + t + '*'; continue; } if (tg === 'CODE') { t = String(n.textContent).replace(/`/g, "'").trim(); if (t) s += '`' + t + '`'; continue; } if (tg === 'A') { var href = n.getAttribute('href') || ''; t = inl(n.childNodes).trim() || href; s += '[' + t + '](' + href + ')'; continue; } if (tg === 'IMG') { s += ' || '') + ')'; continue; } s += inl(n.childNodes); } return s; } function list(el, ordered, indent) { var s = '', idx = 0, i, j, k; var kids = el.children; for (i = 0; i < kids.length; i++) { var li = kids[i]; if (li.tagName !== 'LI') continue; idx++; var inlineNodes = [], nested = []; for (j = 0; j < li.childNodes.length; j++) { var c = li.childNodes[j]; if (c.nodeType === 1 && (c.tagName === 'UL' || c.tagName === 'OL')) nested.push(c); else inlineNodes.push(c); } var line = clean(inl(inlineNodes).replace(/[ \t]*\n[ \t]*/g, '\n')); s += indent + (ordered ? (idx + '. ') : '- ') + line.replace(/\n/g, '\n' + indent + ' ') + '\n'; for (k = 0; k < nested.length; k++) s += list(nested[k], nested[k].tagName === 'OL', indent + ' '); } return s + '\n'; } function table(el) { var rows = el.querySelectorAll('tr'); var lines = [], i, j; for (i = 0; i < rows.length; i++) { var cells = [], kids = rows[i].children; for (j = 0; j < kids.length; j++) { if (kids[j].tagName === 'TD' || kids[j].tagName === 'TH') { cells.push(inl(kids[j].childNodes).replace(/\s+/g, ' ').replace(/\|/g, '\\|').trim()); } } if (cells.length) lines.push('| ' + cells.join(' | ') + ' |'); } if (!lines.length) return ''; var sep = '|'; for (i = 0; i < lines[0].split('|').length - 2; i++) sep += ' --- |'; return lines[0] + '\n' + sep + '\n' + lines.slice(1).join('\n') + '\n\n'; } function blocks(el) { var s = '', buf = '', i; function flush() { var t = clean(buf); if (t) s += t + '\n\n'; buf = ''; } var kids = el.childNodes; for (i = 0; i < kids.length; i++) { var n = kids[i]; if (n.nodeType === 3) { buf += n.data; continue; } if (n.nodeType !== 1) continue; var tg = n.tagName; if (SKIP[tg]) continue; /* tableaux interactifs : exclus du parcours, restitués en Markdown */ if (n.getAttribute && n.getAttribute('data-mistral-export-skip')) continue; /* vignettes de durée des lecteurs audio joints (ex. "00:06") */ if (tg === 'DIV' && /^\d{1,2}:\d{2}(:\d{2})?$/.test(String(n.textContent).trim())) continue; if (!BLOCKS[tg]) { buf += inl([n]); continue; } flush(); var t, lvl; if (tg === 'P') { t = clean(inl(n.childNodes)); if (t) s += t + '\n\n'; } else if (tg === 'H1' || tg === 'H2' || tg === 'H3' || tg === 'H4' || tg === 'H5' || tg === 'H6') { lvl = parseInt(tg.charAt(1), 10); t = inl(n.childNodes).replace(/\n/g, ' ').trim(); if (t) s += '######'.slice(0, lvl) + ' ' + t + '\n\n'; } else if (tg === 'UL') { s += list(n, false, ''); } else if (tg === 'OL') { s += list(n, true, ''); } else if (tg === 'PRE') { s += '```\n' + String(n.textContent).replace(/\n+$/, '') + '\n```\n\n'; } else if (tg === 'TABLE') { s += table(n); } else if (tg === 'BLOCKQUOTE') { var inner = blocks(n).trim(); if (inner) s += inner.split('\n').map(function (l) { return '> ' + l; }).join('\n') + '\n\n'; } else if (tg === 'HR') { s += '---\n\n'; } else { s += blocks(n); } } flush(); return s; } function mdOf(el) { return blocks(el); } /* ---------- Tableaux interactifs (rendus par React) ---------- */ function sepLineFor(line) { var sep = '|', n = line.split('|').length - 2, i; for (i = 0; i < n; i++) sep += ' --- |'; return sep; } function cellText(el) { return String(el.textContent).replace(/\s+/g, ' ').replace(/\|/g, '\\|').trim(); } function richTableToMarkdown(tbl) { /* 1. tableaux avec lignes explicites (role="row" ou tr) */ var rows = tbl.querySelectorAll('[role="row"], tr'), i, j; if (rows.length) { var lns = []; for (i = 0; i < rows.length; i++) { var cs = rows[i].querySelectorAll('[role="cell"], [role="columnheader"], [role="rowheader"], th, td'); var ln = []; for (j = 0; j < cs.length; j++) { if (cs[j].getAttribute('data-rich-table-ui-only')) continue; var ct = cellText(cs[j]); if (ct) ln.push(ct); } if (ln.length) lns.push('| ' + ln.join(' | ') + ' |'); } if (lns.length) return lns[0] + '\n' + sepLineFor(lns[0]) + '\n' + lns.slice(1).join('\n'); } /* 2. grille CSS plate (build 2026.10.12) : les cellules sont des enfants directs du conteneur role="table", sans role="row" ; la colonne d'options et les cellules videuses portent data-rich-table-ui-only et sont exclues */ var heads = [], cells = [], all = tbl.querySelectorAll('[role="columnheader"], [role="cell"], [role="rowheader"], th, td'); for (i = 0; i < all.length; i++) { var c = all[i]; if (c.getAttribute('data-rich-table-ui-only')) continue; if (c.getAttribute('aria-hidden') === 'true' && !String(c.textContent).trim()) continue; var rl = c.getAttribute('role') || (c.tagName === 'TH' ? 'columnheader' : ''); if (rl === 'columnheader' || rl === 'rowheader') heads.push(c); else cells.push(c); } while (heads.length && !cellText(heads[heads.length - 1])) heads.pop(); if (!heads.length && !cells.length) return ''; var ncols = heads.length; if (!ncols) { var gm = /repeat\(\s*(\d+)/.exec(tbl.getAttribute('style') || ''); if (gm) ncols = parseInt(gm[1], 10); } if (!ncols || ncols > cells.length) ncols = Math.max(1, Math.ceil(Math.sqrt(cells.length))); var L = []; if (heads.length) { var hl = []; for (i = 0; i < heads.length; i++) hl.push(cellText(heads[i])); L.push('| ' + hl.join(' | ') + ' |'); } for (i = 0; i < cells.length; i += ncols) { var row = []; for (j = i; j < Math.min(i + ncols, cells.length); j++) row.push(cellText(cells[j])); L.push('| ' + row.join(' | ') + ' |'); } if (!L.length) return ''; return L[0] + '\n' + sepLineFor(L[0]) + '\n' + L.slice(1).join('\n'); } function collectRichTables(msg) { var found = msg.querySelectorAll('[data-rich-table-inner-html], [role="table"], [role="grid"]'); var out = [], i, k; for (i = 0; i < found.length; i++) { var t = found[i]; /* une éventuelle cellule marquée remonte à son conteneur de tableau */ try { t = t.closest('[role="table"], [role="grid"]') || t; } catch (e) {} var dup = false; for (k = 0; k < out.length; k++) if (out[k] === t || out[k].contains(t)) { dup = true; break; } if (dup) continue; if (!t.querySelector('[role="cell"], [role="columnheader"], [role="rowheader"], th, td')) continue; /* exclu des parcours texte ; restitué au format Markdown */ t.setAttribute('data-mistral-export-skip', '1'); out.push(t); } return out; } function attachTables(container, rtables) { var got = [], k; for (k = 0; k < rtables.length; k++) { if (rtables[k] && container.contains(rtables[k])) { got.push(richTableToMarkdown(rtables[k])); rtables[k] = null; } } return got; } /* ---------- Collecte des messages ---------- */ function collectMessages(doc) { var root = doc.querySelector('[data-testid="conversation-layout"]') || doc.body || doc.documentElement; var found = root.querySelectorAll('[data-message-author-role]'); var msgs = []; for (var i = 0; i < found.length; i++) { var m = found[i]; var role = (m.getAttribute('data-message-author-role') || '').toLowerCase(); var rtables = collectRichTables(m); var parts = m.querySelectorAll('[data-message-part-type]'); var items = []; if (parts.length) { for (var j = 0; j < parts.length; j++) { items.push({ type: (parts[j].getAttribute('data-message-part-type') || '').toLowerCase(), el: parts[j], tables: attachTables(parts[j], rtables) }); } var loose = [], k; for (k = 0; k < rtables.length; k++) if (rtables[k]) loose.push(richTableToMarkdown(rtables[k])); if (loose.length) items.push({ type: 'answer', el: null, tables: loose }); if (m.querySelectorAll('[data-canva-minified]').length) items.push({ type: 'canvas', el: null }); } else { items.push({ type: 'answer', el: m, tables: attachTables(m, rtables) }); } msgs.push({ role: role, parts: items }); } /* NB : le marquage data-mistral-export-skip est volontairement retiré APRÈS buildMarkdown() (voir Export) : la conversion Markdown doit écarter les tableaux interactifs déjà convertis en Markdown. */ return msgs; } function buildMarkdown(msgs, title, st, href) { var L = []; var nbUser = 0, nbAsst = 0, i, j; for (i = 0; i < msgs.length; i++) { if (msgs[i].role === 'user') nbUser++; else if (msgs[i].role === 'assistant') nbAsst++; } L.push('# ' + title); L.push(''); L.push('> **Exporté depuis [mistral.ai](' + href + ')** ' + st.text + '.'); L.push('> **' + msgs.length + ' messages** — ' + nbUser + ' de l\'utilisateur, ' + nbAsst + ' de l\'assistant.'); L.push("> *Note : l'heure d'émission de chaque message n'est pas exposée par l'interface mistral.ai ; l'horodatage ci-dessus correspond au moment de l'export.*"); L.push(''); L.push('---'); L.push(''); for (i = 0; i < msgs.length; i++) { var msg = msgs[i]; L.push('______________________________________________________________________'); L.push('## Msg ' + (i + 1) + '/' + msgs.length + ' - ' + roleLabel(msg.role)); L.push(''); for (j = 0; j < msg.parts.length; j++) { var p = msg.parts[j]; if (p.type === 'reasoning') { var rt = clean(blocks(p.el)); L.push('> **Raisonnement (interne de l\'assistant) :**'); L.push('>'); L.push(rt.split('\n').map(function (l) { return '> ' + l; }).join('\n')); L.push(''); for (var q = 0; q < (p.tables || []).length; q++) { L.push(p.tables[q]); L.push(''); } } else if (p.type === 'canvas') { L.push('*[Canvas associé à ce message — son contenu ne fait pas partie du fil de conversation et n\'est pas inclus dans cet export.]*'); L.push(''); } else { var at = p.el ? clean(blocks(p.el)) : ''; if (at) { L.push(at); L.push(''); } for (var q = 0; q < (p.tables || []).length; q++) { L.push(p.tables[q]); L.push(''); } } } } return L.join('\n').replace(/\n{3,}/g, '\n\n').trim() + '\n'; } /* ---------- Export ---------- */ var now = new Date(); var st = stampNow(now); var title = getTitle(document); var msgs = collectMessages(document); if (!msgs.length) { alert("❌ Aucun message trouvé. Ouvrez une conversation mistral.ai dans cet onglet puis réessayez."); return; } var href = (typeof location !== 'undefined' && location && location.href) ? location.href : ''; var md = buildMarkdown(msgs, title, st, href); /* retrait du marquage temporaire APRÈS la conversion Markdown */ var marked = document.querySelectorAll('[data-mistral-export-skip]'); for (var q = 0; q < marked.length; q++) marked[q].removeAttribute('data-mistral-export-skip'); var filename = fileNameFor(title, now, 'md', ' (full)'); var blob = new Blob([md], { type: 'text/markdown;charset=utf-8' }); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); setTimeout(function () { document.body.removeChild(a); URL.revokeObjectURL(url); }, 500); alert('✅ Fichier "' + filename + '" téléchargé (' + msgs.length + ' messages, ' + md.length + ' caractères).'); })();
