working state

This commit is contained in:
Max W. 2025-04-11 01:16:24 +02:00
parent d69b8aad67
commit 814adbd334
2 changed files with 20 additions and 16 deletions

View File

@ -74,7 +74,7 @@
<footer class="footer">
<div class="container">
<p>Pastes will be stored for 2 hours only.</p>
<p>Pastes are stored for 2 hours only. © 2025 Walzen665</p>
</div>
</footer>
</body>

View File

@ -20,7 +20,10 @@ $(document).ready(function() {
html: `
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 3H3C1.89 3 1 3.89 1 5V19C1 20.11 1.89 21 3 21H21C22.11 21 23 20.11 23 19V5C23 3.89 22.11 3 21 3Z"></path><path d="M7 8L12 13L17 8"></path></svg>
Format JSON
`
`,
css: {
display: $languageSelector.val() === 'json' ? 'inline-flex' : 'none'
}
});
$('.controls').prepend($formatJsonBtn);
@ -164,6 +167,7 @@ $(document).ready(function() {
const detectedLanguage = detectContentType($editor.val());
if (detectedLanguage === 'json') {
$languageSelector.val('json');
$formatJsonBtn.show();
}
}
@ -245,10 +249,14 @@ $(document).ready(function() {
window.history.pushState({}, '', '/'); // Reset URL to homepage
$editorContainer.removeClass('viewer-active');
$languageSelector.val('javascript');
$formatJsonBtn.hide(); // Hide JSON button when switching to new paste with JavaScript
});
// Language change
$languageSelector.on('change', () => {
// Toggle Format JSON button visibility based on language selection
$formatJsonBtn.toggle($languageSelector.val() === 'json');
if ($editorContainer.hasClass('viewer-active')) {
$viewer.attr('class', `language-${$languageSelector.val()}`);
hljs.highlightElement($viewer[0]);
@ -264,20 +272,16 @@ $(document).ready(function() {
// Format JSON handler
$formatJsonBtn.on('click', () => {
if ($languageSelector.val() === 'json') {
try {
const parsed = JSON.parse($editor.val());
const formatted = JSON.stringify(parsed, null, 2);
$editor.val(formatted);
$viewer.text(formatted);
hljs.highlightElement($viewer[0]);
updateLineNumbers();
showNotification('JSON formatted successfully!', 'success');
} catch (e) {
showNotification('Invalid JSON: ' + e.message, 'error');
}
} else {
showNotification('Select JSON language first', 'error');
try {
const parsed = JSON.parse($editor.val());
const formatted = JSON.stringify(parsed, null, 2);
$editor.val(formatted);
$viewer.text(formatted);
hljs.highlightElement($viewer[0]);
updateLineNumbers();
showNotification('JSON formatted successfully!', 'success');
} catch (e) {
showNotification('Invalid JSON: ' + e.message, 'error');
}
});