david-sabata/Chrome-Last.fm-Scrobbler — pull request #380 by remoteviewer (2014-05-19 00:53:52+00:00)
Title: Pausing and unpausing in the second half of the track

Hello.

I began using this last.fm-scrobbler recently and have instantly encountered a problem – if I start listening to a song, it will irresistibly be scrobbled unless I switch to another song or turn off and then on the whole app. I made a little fix for my favourite connector. Now it roughly calculates how many real time music was playing (constantly updating local var currentTime in `vk.js`) and allows to stop scrobbling countdown.

After that I have got a little bit funny behaviour – after the half-time of the song have elapsed, every time I paused-unpaused song it was submitted to my last.fm profile. This problem was in `scrobbler.js`, and my idea to fix it was to set up a timer after every successive scrobble, which will reject this track to be submitted again for a little while (half-length of this track). Function `protectedSubmit()` does it.
Now every connector that is able to save song.currentTime can send clean `{type: 'nowPlaying'}` to prevent scrobbling and then informative `{type: 'nowPlaying', ..}` to continue where it's stopped.
Weakness of this method is that `reset()` won't destroy that additional new timer, but pauses are relying on resetting timer. Maybe there should be two variants of `reset()`: the weak one, which will act just as actual function; and a strong one, that will clear the whole memory when it's needed.

I'm quite new to github and completely new to javascript, however I hope this will be useful.