From 357574ba80371c81d33d647b060d73dbdcd9607b Mon Sep 17 00:00:00 2001 From: Yash-Singh1 <saiansh2525@gmail.com> Date: Mon, 24 Aug 2020 10:28:22 -0700 Subject: [PATCH 1/8] Added in copy button --- assets/master.js | 14 ++++++++++++++ index.html | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/master.js b/assets/master.js index bd672c3e..baeedcae 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,19 @@ byId('stats').innerHTML = '<span class="failure">' + escapeHTML(err) + '</span>'; byId('minify-btn').disabled = false; }); + byId('copy-btn').onclick = function() { + let bgColorButton = byId('copy-btn').style.backgroundColor; + let copyText = byId('output'); + copyText.select(); + copyText.setSelectionRange(0, 99999); + document.execCommand("copy"); + byId('copy-btn').innerHTML = 'Copied!' + byId('copy-btn').style.backgroundColor = 'green'; + setTimeout(function() { + byId('copy-btn').innerHTML = 'Copy Result'; + byId('copy-btn').style.backgroundColor = bgColorButton; + }, 5000) + } }; byId('select-all').onclick = function() { diff --git a/index.html b/index.html index f3478bb0..5245377c 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,9 @@ <h1>HTML Minifier <span>(v4.0.0)</span></h1> <button type="button" id="minify-btn">Minify</button> </div> <textarea rows="8" cols="40" id="output" readonly></textarea> - + <div class="minify-button"> + <button type="button" id="copy-btn" disabled>Copy Result</button> + </div> <p id="stats"></p> </div> <div id="options"> From b6249efc6e084ed7aa46ab511df9f811b36f4054 Mon Sep 17 00:00:00 2001 From: Yash-Singh1 <saiansh2525@gmail.com> Date: Wed, 26 Aug 2020 16:21:40 -0700 Subject: [PATCH 2/8] Changed to Clipboard API --- assets/master.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/assets/master.js b/assets/master.js index baeedcae..74be78c4 100644 --- a/assets/master.js +++ b/assets/master.js @@ -106,17 +106,21 @@ byId('minify-btn').disabled = false; }); byId('copy-btn').onclick = function() { - let bgColorButton = byId('copy-btn').style.backgroundColor; - let copyText = byId('output'); - copyText.select(); - copyText.setSelectionRange(0, 99999); - document.execCommand("copy"); - byId('copy-btn').innerHTML = 'Copied!' - byId('copy-btn').style.backgroundColor = 'green'; - setTimeout(function() { - byId('copy-btn').innerHTML = 'Copy Result'; - byId('copy-btn').style.backgroundColor = bgColorButton; - }, 5000) + navigator.permissions.query({name: "clipboard-write"}) + .then((permissionStatus) => { + if (permissionStatus.state == 'granted' || permissionStatus.state == 'prompt') { + navigator.clipboard.writeText(byId('output').value); + let bgColorButton = byId('copy-btn').style.backgroundColor; + byId('copy-btn').innerHTML = 'Copied!' + byId('copy-btn').style.backgroundColor = 'green'; + setTimeout(function() { + byId('copy-btn').innerHTML = 'Copy Result'; + byId('copy-btn').style.backgroundColor = bgColorButton; + }, 5000); + } else { + alert("Access was denied to clipboard-write, please give access to continue."); + } + }); } }; From c5d03e92d3d335a94ecd009df8ec657e666ea622 Mon Sep 17 00:00:00 2001 From: Yash-Singh1 <saiansh2525@gmail.com> Date: Sun, 30 Aug 2020 16:19:29 -0700 Subject: [PATCH 3/8] Used class instead of CSS --- assets/master.css | 2 ++ assets/master.js | 6 +++--- index.html | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) 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 74be78c4..988c6386 100644 --- a/assets/master.js +++ b/assets/master.js @@ -111,11 +111,11 @@ if (permissionStatus.state == 'granted' || permissionStatus.state == 'prompt') { navigator.clipboard.writeText(byId('output').value); let bgColorButton = byId('copy-btn').style.backgroundColor; - byId('copy-btn').innerHTML = 'Copied!' - byId('copy-btn').style.backgroundColor = 'green'; + byId('copy-btn').innerHTML = 'Copied!'; + byId('copy-btn').className = 'copied-button'; setTimeout(function() { byId('copy-btn').innerHTML = 'Copy Result'; - byId('copy-btn').style.backgroundColor = bgColorButton; + byId('copy-btn').className = 'copy-button'; }, 5000); } else { alert("Access was denied to clipboard-write, please give access to continue."); diff --git a/index.html b/index.html index 5245377c..15765286 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@ <h1>HTML Minifier <span>(v4.0.0)</span></h1> <button type="button" id="minify-btn">Minify</button> </div> <textarea rows="8" cols="40" id="output" readonly></textarea> - <div class="minify-button"> + <div class="copy-button"> <button type="button" id="copy-btn" disabled>Copy Result</button> </div> <p id="stats"></p> From 2c327a93bf6fc001410722d8bbdebc2169844955 Mon Sep 17 00:00:00 2001 From: Yash Singh <saiansh2525@gmail.com> Date: Sat, 18 Sep 2021 17:45:52 -0700 Subject: [PATCH 4/8] Remove unnecessary code --- assets/master.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/master.js b/assets/master.js index 988c6386..7e4a83d9 100644 --- a/assets/master.js +++ b/assets/master.js @@ -110,7 +110,6 @@ .then((permissionStatus) => { if (permissionStatus.state == 'granted' || permissionStatus.state == 'prompt') { navigator.clipboard.writeText(byId('output').value); - let bgColorButton = byId('copy-btn').style.backgroundColor; byId('copy-btn').innerHTML = 'Copied!'; byId('copy-btn').className = 'copied-button'; setTimeout(function() { From 321cb212179926f0da4de4792b041cee0896cc51 Mon Sep 17 00:00:00 2001 From: Yash Singh <saiansh2525@gmail.com> Date: Tue, 12 Oct 2021 19:21:46 -0700 Subject: [PATCH 5/8] Use `innerText` --- assets/master.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/master.js b/assets/master.js index 7e4a83d9..df9b082a 100644 --- a/assets/master.js +++ b/assets/master.js @@ -110,10 +110,10 @@ .then((permissionStatus) => { if (permissionStatus.state == 'granted' || permissionStatus.state == 'prompt') { navigator.clipboard.writeText(byId('output').value); - byId('copy-btn').innerHTML = 'Copied!'; + byId('copy-btn').innerText = 'Copied!'; byId('copy-btn').className = 'copied-button'; setTimeout(function() { - byId('copy-btn').innerHTML = 'Copy Result'; + byId('copy-btn').innerText = 'Copy Result'; byId('copy-btn').className = 'copy-button'; }, 5000); } else { From b0cb1440b818b0fc7d104c3843ca6b92285ed454 Mon Sep 17 00:00:00 2001 From: Yash Singh <saiansh2525@gmail.com> Date: Wed, 9 Feb 2022 17:25:59 -0800 Subject: [PATCH 6/8] fix: function instead of arrow for compat --- assets/master.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/master.js b/assets/master.js index df9b082a..3ba20694 100644 --- a/assets/master.js +++ b/assets/master.js @@ -107,7 +107,7 @@ }); byId('copy-btn').onclick = function() { navigator.permissions.query({name: "clipboard-write"}) - .then((permissionStatus) => { + .then(function(permissionStatus) { if (permissionStatus.state == 'granted' || permissionStatus.state == 'prompt') { navigator.clipboard.writeText(byId('output').value); byId('copy-btn').innerText = 'Copied!'; From de082d88bba11573abe96c4d32d1a32da87bddc2 Mon Sep 17 00:00:00 2001 From: Yash Singh <saiansh2525@gmail.com> Date: Wed, 9 Feb 2022 17:35:58 -0800 Subject: [PATCH 7/8] chore: lint warnings --- assets/master.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/assets/master.js b/assets/master.js index 3ba20694..2bee798d 100644 --- a/assets/master.js +++ b/assets/master.js @@ -106,21 +106,22 @@ 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."); - } + 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() { From 0d14de0da4047b7ae8d0464557ca2c07695c8efb Mon Sep 17 00:00:00 2001 From: Yash Singh <saiansh2525@gmail.com> Date: Wed, 9 Feb 2022 17:38:14 -0800 Subject: [PATCH 8/8] chore: an indentation missed --- assets/master.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/master.js b/assets/master.js index 2bee798d..2fe262e1 100644 --- a/assets/master.js +++ b/assets/master.js @@ -120,7 +120,7 @@ else { alert('Access was denied to clipboard-write, please give access to continue.'); } - }); + }); }; };