Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. (function ($) {
  2.  
  3. /* Initialise Counters*/
  4. keywordSearchCounter(9292208, 'footballCounter');
  5. keywordSearchCounter(292410, 'tennisCounter');
  6. keywordSearchCounter(779180, 'chessCounter');
  7.  
  8. function keywordSearchCounter(searchesPerMonth, elementId) {
  9.  
  10. if($.type(searchesPerMonth) !== "number") return;
  11.  
  12. if(searchesPerMonth === 0) return;
  13.  
  14. console.log("function initialised for '" + elementId.toString() + "'");
  15.  
  16. /* Do some math on searches */
  17. var daysInMonth = 28,
  18. hoursInDay = 24,
  19. minutesInHour = 60,
  20. secondsInMinute = 60;
  21.  
  22. var searchesPerDay = searchesPerMonth / daysInMonth;
  23. var searches = searchesPerDay;
  24. console.log('per day: ' + searches);
  25.  
  26. var searchesPerHour = searchesPerDay / hoursInDay;
  27. searches = searchesPerHour;
  28. console.log('per hour: ' + searches);
  29.  
  30. var searchesPerMinute = searchesPerHour / minutesInHour;
  31. searches = searchesPerMinute;
  32. console.log('per minute: ' + searches);
  33.  
  34. var searchesPerSecond = searchesPerMinute / secondsInMinute;
  35. searches = searchesPerSecond;
  36. console.log('per second: ' + searches);
  37.  
  38. var interval = (1 / searches) * 1000;
  39. var counter = 0;
  40. console.log('interval set to: ' + interval);
  41.  
  42. /* Set the counter speed */
  43. setInterval(function () {
  44. counter += 1;
  45. document.getElementById(elementId).innerHTML = counter;
  46. }, interval);
  47. }
  48. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement