Spaces:
Sleeping
Sleeping
Upload philosophie.html
Browse files264 unmodified lines26526626726826927027127227327427527627767 unmodified lines3453463473483493503513523533543555 unmodified lines36136236336436536634 unmodified lines40140240340440540635 unmodified lines4424434444454464477 unmodified lines4554564574584594604614624634644654664674684694704714724734744754764774784794804814824834842 unmodified lines4874884894904914924934944954964971 unmodified line49950050150250350450528 unmodified lines53453553653753853954015 unmodified lines5565575585595605615625635645655663 unmodified lines5705715725735745755765775781 unmodified line5805815825835845855865875885895905915925935942 unmodified lines59759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563610 unmodified lines6476486496506516526536546556566576586596606616626636646656666676686696706716726732 unmodified lines6766776786796806816826836846856866876886896906916926936946952 unmodified lines6986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697705 unmodified lines776777778779780781782783264 unmodified lines<!-- Course Selection --><div class="space-y-3"><label class="block text-sm font-medium text-gray-700">Sélection du cours</label><select id="course-select" class="w-full"><option value="">Choisir un cours...</option></select><div class="course-meta hidden"><div class="bg-gradient-to-r from-gray-50 to-white rounded-xl p-4 border border-gray-100"><div class="flex justify-between items-center"><span id="course-author" class="flex items-center space-x-2"><svg class="h-5 w-5 text-violet-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />67 unmodified lines</div></div><script>$(document).ready(function() {// Initialisation de Select2$('#course-select').select2({placeholder: 'Choisir un cours...',templateResult: function (course) {if (!course.id) {return course.text;5 unmodified lines`);},templateSelection: function (course) {return course.text; // Seul le titre est affiché dans la sélection},34 unmodified lines}addButtonAnimation('submit-btn');addButtonAnimation('copy-btn');// Gestion du changement de type avec affichage personnalisé$('#type-select').change(function() {35 unmodified lines$(newOption).data('author', course.author); // Ajouter l'auteur comme dataselect.append(newOption);});}).fail(function() {7 unmodified lines// Gestion du changement de cours avec animations$('#course-select').on('change', function() {const courseId = $(this).val();if (courseId) {$.ajax({url: `/api/philosophy/courses/${courseId}`,method: 'GET',beforeSend: function() {$('.course-meta').addClass('animate-pulse');},success: function(course) {$('.course-meta').removeClass('hidden animate-pulse').addClass('animate-fadeIn');$('#course-author span').text(`Pr. ${course.author}`);$('#course-date span').text(new Date(course.updated_at).toLocaleDateString('fr-FR', {day: 'numeric',month: 'long',year: 'numeric' }));// Afficher une notification de succèsToast.fire({icon: 'success',title: 'Cours chargé avec succès'});},error: function() {Toast.fire({icon: 'error',title: 'Erreur',2 unmodified lines}});} else {$('.course-meta').addClass('animate-fadeOut').on('animationend', function() {$(this).addClass('hidden').removeClass('animate-fadeOut');});}});// Gestion de la soumission avec conversion en Markdown et sauvegarde1 unmodified lineconst question = $('#question').val().trim();if (!question) {// Gestion de l'erreur si la question est vide (inchangée)return;}28 unmodified lines};$.ajax({url: '/submit_philo',method: 'POST',contentType: 'application/json',data: JSON.stringify(data),15 unmodified linestimer: 2000});},error: function() {Swal.fire({icon: 'error',title: 'Erreur de génération',text: 'Une erreur est survenue lors de la génération de votre dissertation.',customClass: {popup: 'rounded-2xl',confirmButton: 'bg-violet-600 hover:bg-violet-700 text-white font-medium py-2 px-4 rounded-lg transition-colors duration-200'3 unmodified lines});});function saveDissertation(title, content) {let savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];savedDissertations.push({ title, content, timestamp: Date.now() });localStorage.setItem('dissertations', JSON.stringify(savedDissertations));updateSavedDissertationsList();1 unmodified line}function deleteDissertation(index) {let savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];savedDissertations.splice(index, 1);localStorage.setItem('dissertations', JSON.stringify(savedDissertations));updateSavedDissertationsList();Toast.fire({icon: 'success',title: 'Dissertation supprimée avec succès'});}// Fonction pour afficher les dissertations sauvegardées (avec sections repliables et suppression)2 unmodified linesdissertationsList.empty(); // Vider la liste actuellelet savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];if (savedDissertations.length === 0) {dissertationsList.append('<p class="text-gray-500">Aucune dissertation sauvegardée.</p>');return;}savedDissertations.forEach((diss, index) => {const date = moment(diss.timestamp).format('LLL');const collapsible = $(`<button class="collapsible rounded-xl border border-gray-100 flex justify-between w-full"><span>${diss.title}</span><span class="text-gray-500 text-sm">${date}</span></button>`);const deleteButton = $('<button class="text-red-500 hover:text-red-700 ml-2">Supprimer</button>');const content = $('<div class="content prose prose-violet max-w-none p-4"></div>').html(marked.parse(diss.content)); // Convertir en HTMLcollapsible.append(deleteButton); // Ajouter le bouton supprimerdissertationsList.append(collapsible, content);// Gestionnaire d'événement pour chaque section repliablecollapsible.click(function(event) {// Empêcher la propagation de l'événement click sur le bouton "Supprimer"if (event.target === deleteButton[0]) {return;}content.slideToggle("fast");collapsible.toggleClass("active");});deleteButton.click(function() {// Supprimer la dissertation correspondantedeleteDissertation(index);});});}10 unmodified linesconst temp = document.createElement('div');temp.innerHTML = responseDiv.innerHTML;// Fonction récursive pour extraire le texte en préservant les sauts de lignefunction extractText(node) {let text = '';node.childNodes.forEach(child => {if (child.nodeType === 3) { // Nœud textetext += child.textContent;} else if (child.nodeType === 1) { // Élément// Ajouter des sauts de ligne pour les éléments de blocif (window.getComputedStyle(child).display === 'block') {text += '\n';}text += extractText(child);if (window.getComputedStyle(child).display === 'block') {text += '\n';}}});return text;}textToCopy = extractText(temp).trim();// Animation et copie$(this).addClass('scale-95 bg-violet-100');2 unmodified linesnavigator.clipboard.writeText(textToCopy).then(() => {$(this).removeClass('scale-95 bg-violet-100').addClass('bg-green-50 text-green-700');setTimeout(() => {$(this).removeClass('bg-green-50 text-green-700');}, 1000);Toast.fire({icon: 'success',title: 'Copié avec succès',text: 'Le contenu a été copié dans votre presse-papiers',timer: 2000});}).catch((err) => {// Fallback pour les appareils mobiles qui ne supportent pas l'API Clipboardtry {// Créer un élément textarea temporaire2 unmodified linestextarea.style.position = 'fixed'; // Évite le défilementtextarea.style.opacity = '0';document.body.appendChild(textarea);// Sélectionner et copier le textetextarea.select();document.execCommand('copy');// Nettoyerdocument.body.removeChild(textarea);// Feedback positif$(this).removeClass('scale-95 bg-violet-100').addClass('bg-green-50 text-green-700');setTimeout(() => {$(this).removeClass('bg-green-50 text-green-700');}, 1000);Toast.fire({icon: 'success',title: 'Copié avec succès',timer: 2000});} catch (fallbackErr) {// Si même le fallback échoue$(this).removeClass('scale-95 bg-violet-100').addClass('bg-red-50 text-red-700');setTimeout(() => {$(this).removeClass('bg-red-50 text-red-700');}, 1000);Toast.fire({icon: 'error',title: 'Erreur de copie',text: 'Impossible de copier le contenu',timer: 3000});}});});// Ajout des styles d'animation personnalisésconst style = document.createElement('style');style.textContent = `@keyframes fadeIn {from { opacity: 0; transform: translateY(10px); }to { opacity: 1; transform: translateY(0); }}@keyframes slideUp {from { opacity: 0; transform: translateY(20px); }to { opacity: 1; transform: translateY(0); }}@keyframes shake {0%, 100% { transform: translateX(0); }25% { transform: translateX(-5px); }75% { transform: translateX(5px); }}.animate-fadeIn {animation: fadeIn 0.5s ease-out forwards;}.animate-slideUp {animation: slideUp 0.5s ease-out forwards;}.animate-shake {animation: shake 0.5s ease-in-out;}`;document.head.appendChild(style);// Met à jour le label initial avec la valeur par défaut du selectconst initialSelectValue = $('#type-select').val();5 unmodified linesinitialLabelText = `Type ${initialSelectValue} - ${initialSelectedText}`;}$('#current-type-label').text(initialLabelText);});</script></body></html>264 unmodified lines26526626726826927027127227327427527627767 unmodified lines3453463473483493503513523533543553563573583593603613623633643653665 unmodified lines37237337437537637737834 unmodified lines41341441541641741841935 unmodified lines4554564574584594604614627 unmodified lines4704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035042 unmodified lines5075085095105115125135145155165175185195205215225235241 unmodified line52652752852953053153253353453553653753828 unmodified lines56756856957057157257315 unmodified lines5895905915925935945955965975985996006016026036043 unmodified lines6086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597601 unmodified line7627637647657667677687697707717727737747757767777787797807817827837847857867877887897907912 unmodified lines79479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186210 unmodified lines8738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119122 unmodified lines9159169179189199209219229239249259269279289299309319329339349352 unmodified lines93893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610275 unmodified lines10331034103510361037103810391040264 unmodified lines<!-- Course Selection --><div class="space-y-3"><label class="block text-sm font-medium text-gray-700">Sélection du cours (Optionnel)</label><select id="course-select" class="w-full"><option value="">Choisir un cours pour contextualiser...</option></select><div class="course-meta hidden mt-2"><div class="bg-gradient-to-r from-gray-50 to-white rounded-xl p-4 border border-gray-100"><div class="flex justify-between items-center text-sm"><span id="course-author" class="flex items-center space-x-2"><svg class="h-5 w-5 text-violet-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />67 unmodified lines</div></div><!-- DeepThink Floating Action Button --><button id="deepthink-btn"title="Utiliser DeepThink (1 fois/jour)"class="fixed bottom-6 right-6 z-50 bg-gradient-to-br from-purple-600 to-blue-500 hover:from-purple-700 hover:to-blue-600 text-white p-4 rounded-full shadow-lg hover:shadow-xl transition-all duration-300 transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:scale-100 disabled:hover:shadow-lg"><svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z" /></svg><span class="sr-only">DeepThink</span> <!-- Screen reader text --></button><script>$(document).ready(function() {// Initialisation de Select2$('#course-select').select2({placeholder: 'Choisir un cours pour contextualiser...',allowClear: true, // Permet de déselectionnertemplateResult: function (course) {if (!course.id) {return course.text;5 unmodified lines`);},templateSelection: function (course) {if (!course.id) { return course.text; } // Placeholder textreturn course.text; // Seul le titre est affiché dans la sélection},34 unmodified lines}addButtonAnimation('submit-btn');addButtonAnimation('copy-btn');addButtonAnimation('deepthink-btn'); // Add animation to deepthink button// Gestion du changement de type avec affichage personnalisé$('#type-select').change(function() {35 unmodified lines$(newOption).data('author', course.author); // Ajouter l'auteur comme dataselect.append(newOption);});// Important: Trigger update after adding options for Select2select.trigger('change.select2');}).fail(function() {7 unmodified lines// Gestion du changement de cours avec animations$('#course-select').on('change', function() {const courseId = $(this).val();const $courseMeta = $('.course-meta'); // Cache the elementif (courseId) {$.ajax({url: `/api/philosophy/courses/${courseId}`,method: 'GET',beforeSend: function() {$courseMeta.addClass('animate-pulse').removeClass('hidden'); // Show pulsing placeholder// Clear previous data immediately for better UX$('#course-author span').text('');$('#course-date span').text('');},success: function(course) {$('#course-author span').text(`Pr. ${course.author}`);$('#course-date span').text(new Date(course.updated_at).toLocaleDateString('fr-FR', {day: 'numeric',month: 'long',year: 'numeric' }));// Fade in content after data is loaded$courseMeta.removeClass('animate-pulse').addClass('animate-fadeIn');// Afficher une notification de succès discrète/*Toast.fire({icon: 'success',title: 'Cours chargé'});*/},error: function() {$courseMeta.addClass('hidden').removeClass('animate-pulse animate-fadeIn'); // Hide on errorToast.fire({icon: 'error',title: 'Erreur',2 unmodified lines}});} else {// Fade out if a course was previously selected, then hideif (!$courseMeta.hasClass('hidden')) {$courseMeta.addClass('animate-fadeOut').on('animationend', function() {$(this).addClass('hidden').removeClass('animate-fadeOut animate-fadeIn');// Clear data when deselected$('#course-author span').text('');$('#course-date span').text('');// Unbind animationend to prevent multiple executions$(this).off('animationend');});}}});// Gestion de la soumission avec conversion en Markdown et sauvegarde1 unmodified lineconst question = $('#question').val().trim();if (!question) {Toast.fire({icon: 'warning',title: 'Sujet Requis',text: 'Veuillez saisir un sujet de dissertation.'});$('#question').addClass('animate-shake border-red-500').focus();setTimeout(() => $('#question').removeClass('animate-shake border-red-500'), 600);return;}28 unmodified lines};$.ajax({url: '/submit_philo', // Standard endpointmethod: 'POST',contentType: 'application/json',data: JSON.stringify(data),15 unmodified linestimer: 2000});},error: function(jqXHR) {Swal.close();let errorMsg = 'Une erreur est survenue lors de la génération de votre dissertation.';if (jqXHR.responseJSON && jqXHR.responseJSON.error) {errorMsg = jqXHR.responseJSON.error;}Swal.fire({icon: 'error',title: 'Erreur de génération',text: errorMsg,customClass: {popup: 'rounded-2xl',confirmButton: 'bg-violet-600 hover:bg-violet-700 text-white font-medium py-2 px-4 rounded-lg transition-colors duration-200'3 unmodified lines});});// --- START: DeepThink Functionality ---const DEEPTHINK_COOLDOWN_MS = 24 * 60 * 60 * 1000; // 24 hours in millisecondsconst DEEPTHINK_STORAGE_KEY = 'lastDeepThinkUsage';const $deepThinkBtn = $('#deepthink-btn');function checkDeepThinkCooldown() {const lastUsage = localStorage.getItem(DEEPTHINK_STORAGE_KEY);if (!lastUsage) {$deepThinkBtn.prop('disabled', false).attr('title', 'Utiliser DeepThink (1 fois/jour)');return true; // Available}const lastUsageTime = parseInt(lastUsage, 10);const now = Date.now();const timeElapsed = now - lastUsageTime;if (timeElapsed >= DEEPTHINK_COOLDOWN_MS) {$deepThinkBtn.prop('disabled', false).attr('title', 'Utiliser DeepThink (1 fois/jour)');return true; // Available} else {const remainingTime = DEEPTHINK_COOLDOWN_MS - timeElapsed;const hours = Math.floor(remainingTime / (60 * 60 * 1000));const minutes = Math.floor((remainingTime % (60 * 60 * 1000)) / (60 * 1000));$deepThinkBtn.prop('disabled', true).attr('title', `DeepThink disponible dans ${hours}h ${minutes}m`);return false; // Not available}}// Check cooldown on page loadcheckDeepThinkCooldown();// Periodically check cooldown (e.g., every minute) in case the tab stays opensetInterval(checkDeepThinkCooldown, 60000);// Click handler for DeepThink button$deepThinkBtn.click(function() {if (!checkDeepThinkCooldown()) {Toast.fire({icon: 'warning',title: 'DeepThink Non Disponible',text: $deepThinkBtn.attr('title') // Show remaining time from title});return;}const question = $('#question').val().trim();if (!question) {Toast.fire({icon: 'warning',title: 'Sujet Requis',text: 'Veuillez saisir un sujet avant d\'utiliser DeepThink.'});$('#question').addClass('animate-shake border-red-500').focus();setTimeout(() => $('#question').removeClass('animate-shake border-red-500'), 600);return;}// Use the same sophisticated loading animation, adjusted for DeepThinkSwal.fire({title: 'Génération DeepThink en cours',html: `<div class="space-y-4"><div class="flex justify-center"><div class="w-16 h-16 relative"><div class="absolute inset-0 rounded-full border-4 border-purple-200 animate-ping"></div><div class="absolute inset-0 rounded-full border-4 border-purple-500 animate-pulse"></div></div></div><div class="text-gray-600"><p class="animate-pulse">Analyse philosophique approfondie...</p><p class="text-sm mt-2 text-gray-500">Cela peut prendre un peu plus de temps</p></div></div>`,allowOutsideClick: false,showConfirmButton: false,customClass: {popup: 'rounded-2xl'}});const data = {question: question,type: $('#type-select').val(),courseId: $('#course-select').val() || null};$.ajax({url: '/submit_philo_deepthink', // Call the NEW endpointmethod: 'POST',contentType: 'application/json',data: JSON.stringify(data),success: function(data) {Swal.close();const htmlContent = marked.parse(data.response);// Display the dissertation (replaces previous content)$('#response > div').html(htmlContent);$('#response').removeClass('hidden').addClass('animate-fadeIn');$('#copy-btn').removeClass('hidden').addClass('animate-slideUp');// Save the dissertation locally (optional, but consistent)saveDissertation(question + " (DeepThink)", data.response);// RECORD the usage timestamplocalStorage.setItem(DEEPTHINK_STORAGE_KEY, Date.now().toString());// Update button state immediatelycheckDeepThinkCooldown();Toast.fire({icon: 'success',title: 'DeepThink terminé!',text: 'Dissertation générée et sauvegardée.',timer: 2500});},error: function(jqXHR) {Swal.close(); // Close loading indicator on error toolet errorMsg = 'Une erreur est survenue lors de la génération DeepThink.';if (jqXHR.responseJSON && jqXHR.responseJSON.error) {errorMsg = jqXHR.responseJSON.error;}Swal.fire({icon: 'error',title: 'Erreur DeepThink',text: errorMsg,customClass: {popup: 'rounded-2xl',confirmButton: 'bg-violet-600 hover:bg-violet-700 text-white font-medium py-2 px-4 rounded-lg transition-colors duration-200'}});// Do NOT update cooldown here, allow user to retry if it was a server error}});});// --- END: DeepThink Functionality ---function saveDissertation(title, content) {let savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];// Limit the number of saved dissertations to avoid excessive storage useconst MAX_SAVED = 20;if (savedDissertations.length >= MAX_SAVED) {savedDissertations.shift(); // Remove the oldest one}savedDissertations.push({ title, content, timestamp: Date.now() });localStorage.setItem('dissertations', JSON.stringify(savedDissertations));updateSavedDissertationsList();1 unmodified line}function deleteDissertation(index) {Swal.fire({title: 'Êtes-vous sûr?',text: "Cette action est irréversible!",icon: 'warning',showCancelButton: true,confirmButtonColor: '#d33',cancelButtonColor: '#3085d6',confirmButtonText: 'Oui, supprimer!',cancelButtonText: 'Annuler',customClass: {popup: 'rounded-2xl',}}).then((result) => {if (result.isConfirmed) {let savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];savedDissertations.splice(index, 1);localStorage.setItem('dissertations', JSON.stringify(savedDissertations));updateSavedDissertationsList();Toast.fire({icon: 'success',title: 'Dissertation supprimée'});}})}// Fonction pour afficher les dissertations sauvegardées (avec sections repliables et suppression)2 unmodified linesdissertationsList.empty(); // Vider la liste actuellelet savedDissertations = JSON.parse(localStorage.getItem('dissertations')) || [];// Sort by timestamp descending (newest first)savedDissertations.sort((a, b) => b.timestamp - a.timestamp);if (savedDissertations.length === 0) {dissertationsList.append('<p class="text-center text-gray-500 italic py-4">Aucune dissertation sauvegardée pour le moment.</p>');return;}savedDissertations.forEach((diss, index) => {const date = moment(diss.timestamp).format('LLL'); // Format: 5 juin 2024 15:53const uniqueId = `diss-${index}`; // Unique ID for content divconst $collapsible = $(`<div class="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden"><button class="collapsible bg-gray-50 hover:bg-gray-100 transition-colors duration-150 p-4 flex justify-between items-center w-full text-left focus:outline-none focus:ring-2 focus:ring-violet-300"><span class="font-medium text-gray-800 flex-1 mr-4 truncate" title="${diss.title}">${diss.title}</span><div class="flex items-center space-x-3 flex-shrink-0"><span class="text-gray-500 text-xs">${date}</span><button class="delete-dissertation text-red-500 hover:text-red-700 p-1 rounded hover:bg-red-100 transition-colors duration-150" data-index="${index}" title="Supprimer"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg></button><svg class="h-5 w-5 text-gray-400 transform transition-transform duration-200 chevron" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg></div></button></div>`);// Add content div separately to control its visibilityconst $content = $(`<div id="${uniqueId}" class="content prose prose-violet max-w-none p-6 border-t border-gray-200"></div>`).html(marked.parse(diss.content));// Append collapsible header first, then the initially hidden contentdissertationsList.append($collapsible.append($content));// Event handler for the collapsible button (excluding the delete button)$collapsible.find('.collapsible').click(function(event) {// Prevent toggling if the delete button was clickedif ($(event.target).closest('.delete-dissertation').length) {return;}const $thisContent = $(this).siblings('.content');const $chevron = $(this).find('.chevron');$thisContent.slideToggle("fast", function() {// Add/remove 'active' class and rotate chevron after animation completesif ($thisContent.is(':visible')) {$collapsible.addClass('active');$chevron.addClass('rotate-180');} else {$collapsible.removeClass('active');$chevron.removeClass('rotate-180');}});});// Event handler for the delete button$collapsible.find('.delete-dissertation').click(function() {const indexToDelete = $(this).data('index');deleteDissertation(indexToDelete);});});}10 unmodified linesconst temp = document.createElement('div');temp.innerHTML = responseDiv.innerHTML;// Fonction récursive améliorée pour extraire le texte avec un meilleur formatagefunction extractText(node) {let text = '';node.childNodes.forEach(child => {if (child.nodeType === Node.TEXT_NODE) { // Nœud textetext += child.textContent;} else if (child.nodeType === Node.ELEMENT_NODE) { // Élémentconst tagName = child.tagName.toLowerCase();// Ajouter des sauts de ligne avant/après les éléments de bloc, sauf s'il y en a déjàconst isBlock = window.getComputedStyle(child).display === 'block';if (isBlock && !text.endsWith('\n\n') && text.length > 0) {text += '\n'; // Un saut de ligne avant le bloc}if (tagName === 'br') {text += '\n';} else if (tagName === 'li') {text += '* '; // Marqueur pour les listestext += extractText(child);text += '\n';} else {text += extractText(child);}if (isBlock && !text.endsWith('\n') && tagName !== 'li') { // Ajouter un saut de ligne après le bloc si nécessairetext += '\n';}}});// Nettoyer les espaces multiples et les sauts de ligne excessifsreturn text.replace(/\n{3,}/g, '\n\n').trim();}textToCopy = extractText(temp);// Animation et copie$(this).addClass('scale-95 bg-violet-100');2 unmodified linesnavigator.clipboard.writeText(textToCopy).then(() => {$(this).removeClass('scale-95 bg-violet-100').addClass('bg-green-50 text-green-700 border-green-200');setTimeout(() => {$(this).removeClass('bg-green-50 text-green-700 border-green-200');}, 1200);Toast.fire({icon: 'success',title: 'Copié avec succès',//text: 'Le contenu a été copié dans votre presse-papiers',timer: 2000});}).catch((err) => {console.error("Clipboard API failed: ", err);// Fallback pour les appareils mobiles qui ne supportent pas l'API Clipboardtry {// Créer un élément textarea temporaire2 unmodified linestextarea.style.position = 'fixed'; // Évite le défilementtextarea.style.opacity = '0';document.body.appendChild(textarea);// Sélectionner et copier le textetextarea.select();// Pour iOSif (navigator.userAgent.match(/ipad|iphone/i)) {const range = document.createRange();range.selectNodeContents(textarea);const selection = window.getSelection();selection.removeAllRanges();selection.addRange(range);textarea.setSelectionRange(0, 999999);}document.execCommand('copy');// Nettoyerdocument.body.removeChild(textarea);// Feedback positif$(this).removeClass('scale-95 bg-violet-100').addClass('bg-green-50 text-green-700 border-green-200');setTimeout(() => {$(this).removeClass('bg-green-50 text-green-700 border-green-200');}, 1200);Toast.fire({icon: 'success',title: 'Copié avec succès (Fallback)',timer: 2000});} catch (fallbackErr) {console.error("Fallback copy failed: ", fallbackErr);// Si même le fallback échoue$(this).removeClass('scale-95 bg-violet-100').addClass('bg-red-50 text-red-700 border-red-200');setTimeout(() => {$(this).removeClass('bg-red-50 text-red-700 border-red-200');}, 1200);Toast.fire({icon: 'error',title: 'Erreur de copie',text: 'Impossible de copier le contenu automatiquement.',timer: 3000});}});});// Ajout des styles d'animation personnalisés (Déjà présents mais on s'assure qu'ils y sont)const styleCheck = document.getElementById('custom-animations-style');if (!styleCheck) {const style = document.createElement('style');style.id = 'custom-animations-style'; // Add an ID to prevent duplicationstyle.textContent = `@keyframes fadeIn {from { opacity: 0; transform: translateY(10px); }to { opacity: 1; transform: translateY(0); }}@keyframes fadeOut {from { opacity: 1; }to { opacity: 0; }}@keyframes slideUp {from { opacity: 0; transform: translateY(20px); }to { opacity: 1; transform: translateY(0); }}@keyframes shake {0%, 100% { transform: translateX(0); }10%, 30%, 50%, 70%, 90% { transform: translateX(-3px); }20%, 40%, 60%, 80% { transform: translateX(3px); }}.animate-fadeIn { animation: fadeIn 0.5s ease-out forwards; }.animate-fadeOut { animation: fadeOut 0.3s ease-out forwards; }.animate-slideUp { animation: slideUp 0.5s ease-out forwards; }.animate-shake { animation: shake 0.5s ease-in-out; }.rotate-180 { transform: rotate(180deg); }.chevron { transition: transform 0.2s ease-in-out; } /* Smooth chevron rotation */`;document.head.appendChild(style);}// Met à jour le label initial avec la valeur par défaut du selectconst initialSelectValue = $('#type-select').val();5 unmodified linesinitialLabelText = `Type ${initialSelectValue} - ${initialSelectedText}`;}$('#current-type-label').text(initialLabelText);}); // --- FIN de $(document).ready ---</script></body></html>
templates/philosophie.html+365-108