From 5677284c5cdb6840ea424bb002a6d603649cefce Mon Sep 17 00:00:00 2001 From: "D.Marius" <77802969+DMariuss@users.noreply.github.com> Date: Wed, 5 May 2021 15:21:32 +0300 Subject: [PATCH] Adding functionality to the button Replacing functionality of existing button to stop the HALLO attacks! --- index.html | 2 +- main.js | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 741cb4f..2d0ffa4 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,7 @@

diff --git a/main.js b/main.js index 7c7f7c4..dbd39d1 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,3 @@ - let h, s, l; const helloInDifLanguage = [ @@ -31,14 +30,16 @@ function randomHSLValues() { s = Math.floor(Math.random() * 21 + 80); l = Math.floor(Math.random() * 11 + 55); } +// const timerID = []; +let timeID; function executeHello() { - setTimeout(function () { - + timeID = setTimeout(function () { changeColor(); displayHello(); console.log(sayHello); executeHello(); }, 3000); + // timerID.push(timeID); } executeHello(); let selectBody = document.querySelector("body"); @@ -46,15 +47,19 @@ function changeColor() { randomHSLValues(); helloStyle.style.background = `hsl(${h}, ${s}%, ${l}%)`; - helloStyle.style.borderColor = `hsl(${h}, ${s-10}%, ${l-20}%)`; + helloStyle.style.borderColor = `hsl(${h}, ${s - 10}%, ${l - 20}%)`; } function handleClick() { - console.log('first button was clicked 🚀') + if (timeID) { + clearTimeout(timeID); + timeID = 0; + } else console.log(`Stop: timeout id is ${timeID}`); } -var btn = document.querySelector('first-btn') -// btn.addEventListener('click', handleClick) +var btn = document.querySelector("#first-btn"); +btn.addEventListener("click", handleClick); + function conflictsAreUgly() { - console.log('🙏') + console.log("🙏"); }