Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 20th, 2012  |  syntax: None  |  size: 2.27 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Git Time Tracker Greasemonkey Script
  2. // version 0.1 BETA!
  3. // 2005-04-22
  4. // Copyright (c) 2005, Robert McLeod
  5. // Released under the GPL license
  6. // http://www.gnu.org/copyleft/gpl.html
  7. //
  8. // --------------------------------------------------------------------
  9. //
  10. // This is a Greasemonkey user script to track time in git.
  11. //
  12. // Currently single user (no breakdown on time spent per user per issue)
  13. //
  14. // You will need to add the server side scripts somewhere and add your
  15. // URL and api key below.
  16. //
  17. // --------------------------------------------------------------------
  18. //
  19. // ==UserScript==
  20. // @name Git Time Tracker
  21. // @namespace https://gist.github.com/2273229
  22. // @description Script to track time on github
  23. // @include https://github.com/*/*/issues/*
  24. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  25. // ==/UserScript==
  26.  
  27. // api setting
  28. api_key = "X7v54j";
  29. api_url = "http://example.com/";
  30.  
  31. // Get the issue id
  32. url = window.location.href;
  33. issue_id = url.replace('https://github.com/','')
  34.                  .replace('issues/','')
  35.                  .replace(/\//g,'-');
  36.  
  37. // Add the time tracker stuff
  38. sidebar = $("div.discussion-sidebar");
  39. sidebar.append($('<hr>'));
  40. sidebar.append($('<p>').html( "<strong>Time Spent</strong>" ));
  41. sidebar.append($('<p>').attr('id', 'tracked-time').text("loading...").css('font-size','large'));
  42. sidebar.append($('<p>').html("<a href='javascript:void(0)' id='set-time-link'>Set Time</a>"));
  43.  
  44. // get the time from the storage
  45. get_time_url = api_url + "get_time.php?key=" + api_key +"&issue_id=" + issue_id;
  46.  
  47. GM_xmlhttpRequest({
  48.   method: "GET",
  49.   url: get_time_url,
  50.   onload:  function(r) {
  51.         $('#tracked-time').text( r.responseText );
  52.   }
  53. });
  54.  
  55. document.addEventListener('click', function(event) {
  56.         // event.target is the element that was clicked
  57.         if ( event.target.id == 'set-time-link' ) {
  58.                
  59.                
  60.                 time = prompt("Enter the time spent");
  61.                
  62.                 set_time_url = api_url + "set_time.php?key="
  63.                                          + api_key +"&issue_id=" + issue_id
  64.                                          + "&time="+time;
  65.                                          
  66.                 GM_xmlhttpRequest({
  67.                   method: "GET",
  68.                   url: set_time_url,
  69.                   onload:  function(r) {
  70.                         $('#tracked-time').text( r.responseText );
  71.                   }
  72.                 });
  73.                
  74.                 // if you want to prevent the default click action
  75.                 // (such as following a link), use these two commands:
  76.                 event.stopPropagation();
  77.                 event.preventDefault();
  78.         }
  79. }, true);