Update scripts.js

This commit is contained in:
2024-09-22 12:20:00 +02:00
committed by GitHub
parent c522d5267c
commit eba0f59d9a
+18
View File
@@ -9,6 +9,24 @@ document.addEventListener('DOMContentLoaded', function() {
},
});
// New function to load file content into the editor
function loadFileContent(filename) {
const timestamp = new Date().getTime();
fetch(`files/${encodeURIComponent(filename)}?t=${timestamp}`)
.then(response => response.text())
.then(content => {
easyMDE.value(content);
document.getElementById('filename').value = filename.replace(/^\d{8}-/, '').replace(/\.md$/, '');
});
}
// Check for 'edit' parameter in URL and load file content if present
const urlParams = new URLSearchParams(window.location.search);
const editFile = urlParams.get('edit');
if (editFile) {
loadFileContent(editFile);
}
document.querySelectorAll('.copy-url').forEach(button => {
button.addEventListener('click', function(e) {
e.stopPropagation();