bassie111 / Teamleader Timesheets Default Open

// ==UserScript==
// @name         Teamleader Timesheets Default Open
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Opens teamleader timesheets
// @author       Bas Everaarts
// @match        https://app.teamleader.eu/*
// @grant        none
// ==/UserScript==



function openTimesheets()
{
    setTimeout(function(){
        var timesheets = document.getElementsByClassName("timesheet_day");
        for (i = 0; i < timesheets.length; i++) {
            timesheets[i].getElementsByTagName('h2')[0].click();
        }
        addEventListeners();
    }, 750);
}

function addEventListeners()
{
    var button_left = document.getElementsByClassName("left");
    var button_right = document.getElementsByClassName("right");
    if(button_left.length > 0) {
        button_right[0].addEventListener("click", openTimesheets);
        button_left[0].addEventListener("click", openTimesheets);
    }

    var timesheets_button = document.getElementsByClassName("TIMESHEETS");
    timesheets_button[0].addEventListener("click", openTimesheets);
}

openTimesheets();