amnrst / youtube-like-to-view-ratio

11 stars 1 forks source link

Bug when dealing with very large view counts returning negative percentages #6

Closed bourkemcrobbo closed 2 years ago

bourkemcrobbo commented 2 years ago

I was just looking at videos with very high view counts to see how the ratio for videos with multiple rewatches changes, and noticed values that are clearly incorrect. Looking at source I can't see anything immediately that would cause this. However, I have very little experience.

Gangnam Style shows -245% - https://www.youtube.com/watch?v=9bZkp7q19f0 Despacito is -5% - https://www.youtube.com/watch?v=kJQP7kiw5Fk

Thank you for creating this extension

aminroosta commented 2 years ago

Thanks @bourkemcrobbo for reporting the issue.

I had a silly bug converting strings to numbers. Apparently in javascript bit or casts a number to 32 bits, so a large number like "98765432100" | 0 becomes a negative number -18815708!

The fix is to use "98765432100" * 1 instead - I've submitted v0.0.6 and it should be public in a few hours.