cyfung1031 / userscript-supports

This is for the userscripts created on GreasyFork.org.
https://cyfung1031.github.io/userscript-supports/
MIT License
48 stars 3 forks source link

Refractor youtube-cpu-tamper-by-animationframe.user.js #8

Closed SashaXser closed 1 year ago

cyfung1031 commented 1 year ago

thanks... but .. why?

Coding Improvement

I noted some good coding improvements that suggested from you. I am glad to incorporate them.

However, It is intended to use if case 2 3 4 5 and else case to do now + interval. Changing to o.nextAt += interval * Math.max(1, Math.floor((now - nextAt) / interval)); would have negative impact to the coding logic.

No resolve?

Did you tested the script ? You deleted the resolve inside Promise.

Regarding Comments

Some comments are used for JSDoc. I would not remove. Those comments I made in the script are to explain "why" to do or "what to be careful" when I (or other developers) try to update or improve the script. Therefore for some variables like toResetFuncHandlers, it is easily to understand what it is and how it works by its name and corresponding code.

Some codes are necessary to provide the text description to express the meaning of why to do. Otherwise I will forgot why I typed them after few years and the script will be no more maintainable.

  // Number.MAX_SAFE_INTEGER = 9007199254740991       // Define some constants for the initial value and the safe limits of the timer ID

  const INT_INITIAL_VALUE = 8192;
  const INT_INITIAL_VALUE = 8192; // 1 ~ {INT_INITIAL_VALUE} are reserved for native setTimeout/setInterval       const SAFE_INT_LIMIT = 2251799813685248;
  const SAFE_INT_LIMIT = 2251799813685248; // in case cid would be used for multiplying       const SAFE_INT_REDUCED = 67108864;
  const SAFE_INT_REDUCED = 67108864; // avoid persistent interval handlers with cids between {INT_INITIAL_VALUE + 1} and {SAFE_INT_REDUCED - 1}

Remarks

I created this script in a slow windows 7 PC and now I am using MacBook M1 Pro. Those fundamental programming logics that implemented in the script would remains unchanged as I am no longer capable to test it any more.