diff --git a/assets/master.css b/assets/master.css index faa209d1..0720d8d7 100644 --- a/assets/master.css +++ b/assets/master.css @@ -5,6 +5,8 @@ h1 span { font-size: 0.6em; } button { font-weight: bold; width: 100px; } .minify-button { margin: 16px 0; } +.copy-button { margin: 16px 0; } +.copied-button { margin: 16px 0; background-color: green; } #outer-wrapper { overflow: hidden; } #wrapper { width: 65%; float: left; } #input { width: 99%; height: 18em; } diff --git a/assets/master.js b/assets/master.js index bd672c3e..2fe262e1 100644 --- a/assets/master.js +++ b/assets/master.js @@ -84,6 +84,7 @@ } byId('minify-btn').onclick = function() { + byId('copy-btn').disabled = false; byId('minify-btn').disabled = true; var originalValue = byId('input').value; minify(originalValue, getOptions(), function(minifiedValue) { @@ -104,6 +105,23 @@ byId('stats').innerHTML = '' + escapeHTML(err) + ''; byId('minify-btn').disabled = false; }); + byId('copy-btn').onclick = function() { + navigator.permissions.query({ name: 'clipboard-write' }) + .then(function(permissionStatus) { + if (permissionStatus.state === 'granted' || permissionStatus.state === 'prompt') { + navigator.clipboard.writeText(byId('output').value); + byId('copy-btn').innerText = 'Copied!'; + byId('copy-btn').className = 'copied-button'; + setTimeout(function() { + byId('copy-btn').innerText = 'Copy Result'; + byId('copy-btn').className = 'copy-button'; + }, 5000); + } + else { + alert('Access was denied to clipboard-write, please give access to continue.'); + } + }); + }; }; byId('select-all').onclick = function() { diff --git a/index.html b/index.html index f3478bb0..15765286 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,9 @@

HTML Minifier (v4.0.0)

- +
+ +