torntools_extension icon indicating copy to clipboard operation
torntools_extension copied to clipboard

Faction and Company ID fixes

Open Kwack-Kwack opened this issue 2 years ago • 5 comments

  • Remove random event listener that didn't make any sense to be there (... I think)
  • Remove debugging console statements
  • Code style changes for readability

Kwack-Kwack avatar Apr 24 '24 01:04 Kwack-Kwack

We should keep the listener as changing between companies on joblist.php will trigger the custom event and have the ID updated.

Sashank999 avatar Apr 28 '24 03:04 Sashank999

You should also add caching to the company ID call as it will mostly not change.

Sashank999 avatar Apr 28 '24 03:04 Sashank999

hashes.get returns null when the key/value pair isn't found, and isIntNumber(null) returns true, causing the final two case checks to always return true. Perhaps the built-in isIntNumber should also do a null check first? Would love to check this before making any changes

function isIntNumber(number) {
        if (number == null) return false; // number == null is true for null and undefined, but false for 0 and NaN.
        // could also do a strict check as undefined is caught by the function below, it doesn't really matter
	return !isNaN(number) && isFinite(number) && number % 1 === 0; // already existing logic
}

You're right about the company pages, I knew there must have been a reason for having it in the first place. The only issue is this event listener also fires on opening the employees tab on your own company page, so I'll likely just add a pathname check in the callback.

Good call with the caching, I'll get that done as well, thanks!

Kwack-Kwack avatar Apr 28 '24 11:04 Kwack-Kwack

Yes, a check so that the custom event listener is applied only for job listings should work.

I suggest isIntNumber as:

function isIntNumber(number) {
	return number !== null && !isNaN(number) && isFinite(number) && number % 1 === 0;
}

undefined already returns false so no == needed.

Sashank999 avatar Apr 28 '24 14:04 Sashank999

Updated, and the faction ID feature has also been updated to match.

  • Add a new element rather than modifying element text directly
  • Double check the element doesn't already exist before inserting
  • Cache the data for half a week (3.5 days, yes this is a weird value but I had no idea what else would be better... edits are open if you've got a better idea)

Both features are much more readable now in my opinion.

Kwack-Kwack avatar Apr 28 '24 16:04 Kwack-Kwack