Last active
November 20, 2024 13:00
-
-
Save imkevinxu/4393523 to your computer and use it in GitHub Desktop.
Revisions
-
imkevinxu revised this gist
Dec 28, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,9 +21,9 @@ <h1>Time Spent on Page</h1> <small>Change tabs, switch windows, or leave the page and the active amount of time on this page is logged</small> <a href="https://gist.github.com/4393523" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a> <script src="timeSpentOnPage.js"></script> </body> </html> -
imkevinxu revised this gist
Dec 28, 2012 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,11 +9,11 @@ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; width: 400px; margin: 50px auto; color: #444; } h1 { font-weight: 400; } li { margin: 1em 0; font-weight:300; } </style> </head> @@ -24,5 +24,6 @@ <h1>Time Spent on Page</h1> <a href="https://gist.github.com/4393523"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a> <script src="timeSpentOnPage.js"></script> </body> </html> -
imkevinxu revised this gist
Dec 28, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
imkevinxu revised this gist
Dec 28, 2012 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ Javascript code that calculates how much active time is spent on a tab and takes into account changing tabs, switching windows, or leaving the page. Demo here [http://bl.ocks.org/d/4393523/](http://bl.ocks.org/d/4393523/) -
imkevinxu revised this gist
Dec 28, 2012 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,6 +21,7 @@ <h1>Time Spent on Page</h1> <small>Change tabs, switch windows, or leave the page and the active amount of time on this page is logged</small> <a href="https://gist.github.com/4393523"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a> <script src="timeSpentOnPage.js"></script> </body> -
imkevinxu revised this gist
Dec 28, 2012 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ <html lang="en"> <head> <meta charset="UTF-8" /> <title>Time Spent on Page</title> <style type="text/css"> body { @@ -11,13 +11,16 @@ margin: 50px auto; } h1 { margin-bottom: 0.2em; } li { margin: 1em 0; } small { color: #666; } </style> </head> <body> <h1>Time Spent on Page</h1> <small>Change tabs, switch windows, or leave the page and the active amount of time on this page is logged</small> <script src="timeSpentOnPage.js"></script> </body> -
imkevinxu revised this gist
Dec 28, 2012 . 2 changed files with 43 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title></title> <style type="text/css"> body { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; width: 400px; margin: 50px auto; } li { line-height: 2em; } </style> </head> <body> <h1 id="title">Change Tabs</h1> <script src="timeSpentOnPage.js"></script> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,40 +25,43 @@ this.new_d = new Date(); // Calculates Time Spent on page upon switching windows setInterval((function() { if (document.hasFocus() === false) { _this.new_d = new Date(); var time_spent = Math.round((_this.new_d - _this.d) / 1000); doSomething("Switched Window", time_spent); _this.d = new Date(); } }), 200); // Calculates Time Spent on page upon leaving/closing page window.onunload = function() { _this.new_d = new Date(); var time_spent = Math.round((_this.new_d - _this.d) / 1000); doSomething("Left Page", time_spent); }; // Calculates Time Spent on page upon unfocusing tab // http://davidwalsh.name/page-visibility document.addEventListener(visibilityChange, (function(e) { if (document[state] === 'visible') { _this.d = new Date(); } else if (document[hidden]) { _this.new_d = new Date(); var time_spent = Math.round((_this.new_d - _this.d) / 1000); doSomething("Changed Tab", time_spent); } }), false); // Function that does something var doSomething = function(message, time_spent) { if (time_spent >= 1) { var text = "["+message+"] "+time_spent+" seconds" var item = document.createElement("li"); item.innerHTML = text; document.body.appendChild(item); console.log(text); } } -
imkevinxu created this gist
Dec 28, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ var hidden, state, visibilityChange, _this = this; if (document.hidden != null) { hidden = "hidden"; visibilityChange = "visibilitychange"; state = "visibilityState"; } else if (document.mozHidden != null) { hidden = "mozHidden"; visibilityChange = "mozvisibilitychange"; state = "mozVisibilityState"; } else if (document.msHidden != null) { hidden = "msHidden"; visibilityChange = "msvisibilitychange"; state = "msVisibilityState"; } else if (document.webkitHidden != null) { hidden = "webkitHidden"; visibilityChange = "webkitvisibilitychange"; state = "webkitVisibilityState"; } this.d = new Date(); this.new_d = new Date(); // Calculates Time Spent on page upon switching windows setInterval((function() { var time_spent; if (document.hasFocus() === false) { _this.new_d = new Date(); time_spent = Math.round((_this.new_d - _this.d) / 1000); if (time_spent > 1) { console.log("[Switched Window] " + time_spent + " seconds"); } _this.d = new Date(); } }), 200); // Calculates Time Spent on page upon leaving/closing page window.onunload = function() { var time_spent; _this.new_d = new Date(); time_spent = Math.round((_this.new_d - _this.d) / 1000); if (time_spent > 1) { console.log("[Left Page] " + time_spent + " seconds"); } }; // Calculates Time Spent on page upon unfocusing tab // http://davidwalsh.name/page-visibility document.addEventListener(visibilityChange, (function(e) { var time_spent; if (document[state] === 'visible') { return _this.d = new Date(); } else if (document[hidden]) { _this.new_d = new Date(); time_spent = Math.round((_this.new_d - _this.d) / 1000); if (time_spent > 1) { console.log("[Changed Tab] " + time_spent + " seconds"); } } }), false);