Generate ibis entry

enter something useful

  1. // ==UserScript==
  2. // @name Generate ibis entry
  3. // @namespace http://ibis.gen/
  4. // @version 0.1
  5. // @description enter something useful
  6. // @author You
  7. // @match https://ibis.infinity-software.com/timeentry/TimeEntryHome.aspx
  8. // @grant none
  9. // @require //cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js
  10. // ==/UserScript==
  11.  
  12.  
  13. $(function() {
  14. $('body').append("<input id='from' type='text' style='position: fixed; right: 125px; top: 100px; width: 80px' />");
  15. $('body').append("<span style='position: fixed; right: 110px; top: 100px; font-size: 10px'>to</span>")
  16. $('body').append("<input id='to' type='text' style='position: fixed; right: 25px; top: 100px; width: 80px' />");
  17. $('body').append("<textarea id='notes' style='position: fixed; right: 25px; top: 130px; width: 180px' />");
  18. $('body').append("<button id='run' style='position: fixed; right: 25px; top: 165px'>Generate</button>");
  19. $("#run").click(generate);
  20. function run(entry) {
  21. $("#txtDate").val(entry.date);
  22. $("#ddlStartTime").val('9:00 AM');
  23. $("#ddlEndTime").val('5:00 PM');
  24. $("#ddlProject").val(1515).change();
  25. $("#ddlRole").val(284).change();
  26. $("#ddlWorkType").val(100).change();
  27. $("#txtPublicNotes").val(entry.note);
  28. setTimeout(function() {
  29. $("#btnSaveEntry")[0].click();
  30. }, 1000);
  31. }
  32. function generate() {
  33. var entry = load();
  34. if(entry.from === '') { return; }
  35. // clear the last saved entry to start a new one
  36. if(!clearLastEntry()) { return; };
  37. var current = moment(entry.from).add(entry.current, 'days').format('MM/DD/YYYY');
  38. // save data
  39. entry.current += 1;
  40. save(entry);
  41. run({
  42. date: current,
  43. note: entry.note
  44. });
  45. }
  46. function save(data) {
  47. var diff = moment(data.from).add(data.current-1 ,'days').diff(moment(data.to), 'days');
  48. console.log(diff);
  49. if(diff === 0) {
  50. localStorage.removeItem('auto-ibis');
  51. }
  52. else{
  53. localStorage.setItem("auto-ibis", JSON.stringify(data));
  54. }
  55. }
  56. function load(){
  57. return JSON.parse(localStorage.getItem("auto-ibis")) || {
  58. from : $("#from").val(),
  59. to : $("#to").val(),
  60. note : $("#notes").val(),
  61. current : 0
  62. };
  63. }
  64. function clearLastEntry(){
  65. if($("#txtDate").val() !== '') {
  66. $("#txtDate").val('').change();
  67. $("#btnUndoAction")[0].click();
  68. return false;
  69. }
  70. return true;
  71. }
  72. generate();
  73. });