|
72 | 72 | margin-bottom: 20px; |
73 | 73 | } |
74 | 74 |
|
| 75 | + label { |
| 76 | + margin-right: 10px; |
| 77 | + margin-bottom: 20px; |
| 78 | + } |
| 79 | + |
75 | 80 | .button:hover { |
76 | 81 | background-color: #2a9038; |
77 | 82 | } |
@@ -134,6 +139,10 @@ <h3>Supported HTML elements</h3> |
134 | 139 | <h2>Clean HTML code</h2> |
135 | 140 | <textarea id="html-output" readonly></textarea> |
136 | 141 | <button id="copy-button" class="button">Copy HTML</button> |
| 142 | + <label title="Useful if pasting into rich text editor, as also writes the cleaned text/html payload to the clipboard. Doesn't make a difference if pasting into a plain text editor."> |
| 143 | + <input type="checkbox" id="include-rich-html" checked > |
| 144 | + Include Cleaned Rich HTML |
| 145 | + </label> |
137 | 146 | <button id="clear-button" class="button">Clear all</button> |
138 | 147 |
|
139 | 148 | <div id="preview-container"> |
@@ -279,6 +288,7 @@ <h2>Preview</h2> |
279 | 288 | const htmlOutput = document.getElementById('html-output'); |
280 | 289 | const previewContent = document.getElementById('preview-content'); |
281 | 290 | const copyButton = document.getElementById('copy-button'); |
| 291 | + const includeRichHtmlCheckbox = document.getElementById('include-rich-html'); |
282 | 292 | const clearButton = document.getElementById('clear-button'); |
283 | 293 |
|
284 | 294 | // Handle paste event |
@@ -353,19 +363,26 @@ <h2>Preview</h2> |
353 | 363 | pasteArea.innerHTML = ''; |
354 | 364 | } |
355 | 365 | }); |
356 | | - |
357 | | - // Copy HTML to clipboard |
358 | | - copyButton.addEventListener('click', function() { |
359 | | - htmlOutput.select(); |
360 | | - document.execCommand('copy'); |
361 | 366 |
|
| 367 | + // Copy HTML to clipboard |
| 368 | + copyButton.addEventListener('click', async function() { |
| 369 | + const content = htmlOutput.value; |
| 370 | + const items = { |
| 371 | + 'text/plain': new Blob([content], { type: 'text/plain' }), |
| 372 | + }; |
| 373 | + if (includeRichHtmlCheckbox.checked) { |
| 374 | + items['text/html'] = new Blob([content], { type: 'text/html' }); |
| 375 | + } |
| 376 | + const cpItem = new ClipboardItem(items); |
| 377 | + await navigator.clipboard.write([cpItem]); |
| 378 | + |
362 | 379 | const originalText = copyButton.textContent; |
363 | 380 | copyButton.textContent = 'Copied!'; |
364 | | - |
365 | 381 | setTimeout(function() { |
366 | 382 | copyButton.textContent = originalText; |
367 | 383 | }, 1500); |
368 | 384 | }); |
| 385 | + |
369 | 386 |
|
370 | 387 | // Clear all content |
371 | 388 | clearButton.addEventListener('click', function() { |
|
0 commit comments