theforumhelpers.github.io icon indicating copy to clipboard operation
theforumhelpers.github.io copied to clipboard

Simplify FHP.js and use code supporting modern browsers

Open Weredime opened this issue 2 years ago • 5 comments

We currently implement the fetch standard, which is present starting Chromium 42 and Firefox 39. In FHP.js, we can really simplify it a LOT, and use better code practices supported in these versions, such as:

  • document.createElement instead of Element.innerHTML - XSS could be a thing, but moderation is implemented in the main website. Really, you should just use .innerText, It's supported in most browsers.
  • Use const or let instead of var. The declaration var isn't really good (search it up on google, there are loads of things).
  • Use for .... of .... iterators instead of for (j = 0; j < .... iterators. It's supported in most browsers, and we really don't need the index of the member in the array.
  • We shouldn't keep calling document.getElementById(string) every single time we need to update it in the same section of the code. We should just declare a variable!

I hope you take this into consideration, as this would introduce new JavaScript programmers to better solutions for code, instead of old ones.

Weredime avatar Jul 27 '22 20:07 Weredime

document.createElement in FHP.js would make it a lot more verbose, and I don't think XSS is as much of a risk for such a simple, relatively low-traffic site like this

gosoccerboy5 avatar Jul 27 '22 21:07 gosoccerboy5

Yeah, I’ve heard that let is sometimes better than var

penguinmoose avatar Jul 27 '22 23:07 penguinmoose

And I always use const for things that don’t change - it’s just better (it doesn’t let you change it I think) in my opinion.

penguinmoose avatar Jul 27 '22 23:07 penguinmoose

does it really matter in the case of this repo tho?

gosoccerboy5 avatar Jul 28 '22 01:07 gosoccerboy5

@gosoccerboy5 It probably won't impact the actual site. I guess it's just a code improvement.

penguinmoose avatar Aug 01 '22 19:08 penguinmoose