lefnire/habitrpg-chrome — pull request #10 by SlappyBag (2013-01-23 11:24:19+00:00)
Title: Rewrite of site checking code

I re-wrote most the code for efficiency and ease of use. It now checks the current tabs open before scoring to your character. I had to remove the initial score on arrival to a site, it now requires at least 5mins on the website before scoring. (This is due to cookie expiration every 5mins)

This works by:
1. Checking if a cookie is present when the browser loads a page.
1a.If there isn't a cookie the browser sends background.js to start a timer & makes a cookie which lasts 5 mins.
1b.If there is a cookie, the browser remakes the cookie & does nothing.

2. background.js starts a timer of 5mins, after 5mins it requests information from the tabCheck function
2a. Tabcheck returns how many tabs for the original URL are open & if any are active.
2b. If a tab is active, a score is sent via the API. If tabs are present but not active, nothing happens and the timer restarts. If no tabs are present, the timer ends.

Possible Issues:
A. I think its possible that if the user stays on one page of the site, the cookie will expire and upon opening a new tab there will be 2 timers running for the site. I can most likely re-write it without cookies at all in the future.

B. It may be possible that the user closes all tabs on the 5min mark, and then revisits the site, restarting the timer. The tabs being open before won't affect the new timer. This is less of a problem than #A

Fortunately both issues are fairly unlikely and both are likely to be solved in the future.

Cheers,
Stan