dheerajdlalwani / back-to-work

A simple browser extension, intended to get you "Back To Work" when you start slacking off to one of those really addictive sites.
MIT License
36 stars 1 forks source link

alt: clean JS, better implementation using classes #5

Closed tusharnankani closed 2 years ago

tusharnankani commented 2 years ago

Review: The code here can be shortened by creating classes and defining styles in the stylesheet.

https://github.com/dheerajdlalwani/back-to-work/blob/fc5c9820ee350dc1ab69f9c9aff77465bc33f979/src/popup/popup.js#L7-L18

It can be shortened more using a default, which I assume is Chill. Have the HTML, state & styles initially for that.

Have a class for Work, and toggle that whenever necessary.

 (mode === "Work") ? modeBtn.classList.add("work") : modeBtn.classList.remove("work");

Now CSS for work would be something like:

.work {
  content: "work";
  background-color: #f95050;
  color: #ffffff;
}

Reason to do that?

Keeps the JS clean and and implementation short. No need for item.style.backgroundColor etc.

dheerajdlalwani commented 2 years ago