diff --git a/paste-html-subset.html b/paste-html-subset.html index b2207f5..b30f70e 100644 --- a/paste-html-subset.html +++ b/paste-html-subset.html @@ -72,6 +72,11 @@ margin-bottom: 20px; } + label { + margin-right: 10px; + margin-bottom: 20px; + } + .button:hover { background-color: #2a9038; } @@ -134,6 +139,10 @@

Supported HTML elements

Clean HTML code

+
@@ -279,6 +288,7 @@

Preview

const htmlOutput = document.getElementById('html-output'); const previewContent = document.getElementById('preview-content'); const copyButton = document.getElementById('copy-button'); + const includeRichHtmlCheckbox = document.getElementById('include-rich-html'); const clearButton = document.getElementById('clear-button'); // Handle paste event @@ -353,19 +363,26 @@

Preview

pasteArea.innerHTML = ''; } }); - - // Copy HTML to clipboard - copyButton.addEventListener('click', function() { - htmlOutput.select(); - document.execCommand('copy'); + // Copy HTML to clipboard + copyButton.addEventListener('click', async function() { + const content = htmlOutput.value; + const items = { + 'text/plain': new Blob([content], { type: 'text/plain' }), + }; + if (includeRichHtmlCheckbox.checked) { + items['text/html'] = new Blob([content], { type: 'text/html' }); + } + const cpItem = new ClipboardItem(items); + await navigator.clipboard.write([cpItem]); + const originalText = copyButton.textContent; copyButton.textContent = 'Copied!'; - setTimeout(function() { copyButton.textContent = originalText; }, 1500); }); + // Clear all content clearButton.addEventListener('click', function() {