Skip to content

New version - #26

Open
0vulns wants to merge 1 commit into
jasonzissman:masterfrom
0vulns:patch-1
Open

New version#26
0vulns wants to merge 1 commit into
jasonzissman:masterfrom
0vulns:patch-1

Conversation

@0vulns

@0vulns 0vulns commented Jul 3, 2016

Copy link
Copy Markdown

TimeMe.js

I noticed the version of TimeMe.js for Jasonzissman is impractical due it support one timer on page,So you cannot use for multipurpose.

The version of I Support multipurpose using and unlimited Timers on one page.

How do I use TimeMe.js?

First, obtain a copy of timeme.js and ifvisible.js. You can get both by installing TimeMe.js via Bower:

bower install timeme.js


Then, simply include the following lines of code in your page's head element:


<script src="ifvisible.js"></script>
<script src="timeme.js">
<script type="text/javascript">
 TimeMe.setIdleDurationInSeconds(30);
 TimeMe.initialize();        
</script>

This code both imports the TimeMe.js library and initializes it. Notice that this code sets the idle duration to 30 seconds, which means 30 seconds of user inactivity (no mouse or keyboard usage on the page) will stop the timer. Also, we used default timer ID (default).


Once imported and initialized, we can call the various methods made available
by TimeMe.js. See the API documentation below for
a complete breakdown of all of the available functionality. The most basic
feature is to retrieve the time spent by the user on the default timer:


 var timeSpentOnPage = TimeMe.getDefaultTimer();


In most cases you will want to store the time spent on a page for analytic purposes. You will therefore need to send the time spent on a page to the server at some point! When is the best time to do this? You can hook into the window.onbeforeunload event to do so. In most browsers this method is fired during a page's shut-down routine. Notice below that we use a synchronous request (not the usual asynchronous request) to guarantee the request to our server arrives before the page closes:

window.onbeforeunload = function (event) {
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open("POST","ENTER_URL_HERE",false);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    var timeSpentOnPage = TimeMe.getDefaultTimer();
    xmlhttp.send(timeSpentOnPage);
};

Using 'onbeforeunload' is by no means a requirement. You can hook into any other event or logical point in your application to send the time spent information to the server.
In a traditional if you want another timer on same page without stop or rest the default timer:

var TimerID = "xC0d3rZ"
TimeMe.initialize(TimerID);
var timeSpend = TimeMe.getTimer(TimerID);

Such easy !

All page times are tracked in TimeMe.js, so you can review total aggregate timers on each page for a particular user's session:


var timersReport = TimeMe.getAll();

API


TimeMe.setDefaultID(newDefaultID);

Sets the Default Timer ID.



TimeMe.setIdleDurationInSeconds(durationInSeconds);
Sets the time (in seconds) that a user is idle before the timer is turned off. Set this value to -1 to disable idle time outs.


TimeMe.initialize(TimerID);
Initializes the timer. Should only be called when first importing the library and beginning to time page usage. If you set TimerID will start new Timer with The stetted vaule as ID,unless will start the Default timer (Time Spent on Page)


var timeInSeconds = TimeMe.getDefaultTimer();
Retrieves the time spent (in seconds) for Default ID.


var timeInSeconds = TimeMe.getTimer(TimerID);
Retrieves the time spent (in seconds) for the indicated Timer ID.


var timeSpentInfo = TimeMe.getAll();
Retrieves the time spent on all timers that have been recorded using TimeMe.js. Notice this only works for Single Page Applications (SPAs) where TimeMe.js is only initialized once.


TimeMe.startTimer(TimerID);
Manually starts the timer for the indicated Timer ID.. Notice this only works if the timer is currently stopped.


TimeMe.stopTimer(TimerID);
Manually stops the timer for the indicated Timer ID. Notice this only works if the timer is currently running.


TimeMe.resetRecordedTimer(TimerID);
Clears the recorded time for the indicated TimerID.


TimeMe.TimeMe.resetAllRecordedTimers();
Clears all recorded timers.


Add multi timers in one page
@0vulns 0vulns changed the title add support multi use for TimeMe New version Jul 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant