rfmacedo.marlo / Time Sheet - Auto Fulfill

// ==UserScript==
// @name         Time Sheet - Auto Fulfill
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  auto fulfill the time sheet
// @author       Rafael Macedo
// @match        http://ts.marlo.com.au/time.php*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  'use strict';

  // Your code here...
  window.Rafael = [];
  window.Rafael.TimeSheet = function () {

    var data;
    var search;

    data = new Date().getFullYear();
    data += "-";
    data += (new Date().getMonth() + 1).toString().length == 2 ? new Date().getMonth() + 1 : "0" + (new Date().getMonth() + 1);
    data += "-";
    data += new Date().getDate().toString().length == 2 ? new Date().getDate() : "0" + new Date().getDate();

    search = '?date=' + data;

    if (window.location.search != search) {
      var origin = window.location.origin;
      var pathname = window.location.pathname;
      var url = origin + pathname;

      window.location.href = url + search;
    }

    var dia = document.querySelector('a[href="' + search + '"]');
    if (dia.className == 'CalendarLinkRecordsExist') return;

    var form = document.getElementsByName('timeRecordForm')[0];
    var client = 3;
    var project = 18;

    if (form === undefined) {
      setTimeout(Rafael.TimeSheet, 300);
      return;
    }

    fillProjectDropdown(client);
    fillTaskDropdown(project);

    document.getElementById("client").value = client;
    document.getElementById("project").value = project;
    document.getElementById("task").value = 64;
    document.getElementById("duration").value = '6.0h';

  }

  Rafael.TimeSheet();

})();