e14matt / Replicon Time-Off UI Improvements

// ==UserScript==
// @name         Replicon Time-Off UI Improvements
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Show time off remaining balance. Move the 'Next Page' icon so that you can click in the same place multiple times to advance months
// @author       MattC
// @license      MIT
// @require      http://code.jquery.com/jquery-latest.js
// @match        https://*.replicon.com/*/TimeOff/calendar
// @match        https://*.replicon.com/*/TimeOff/Bookings
// @icon         https://www.google.com/s2/favicons?sz=64&domain=replicon.com
// @updateURL    https://openuserjs.org/meta/e14matt/Replicon_Time-Off_UI_Improvements.meta.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    if ($('.balance-summary .data').length>0) {
        uiChanges();
    } else {
        const targetNode = document.getElementById('balanceBar');
        const config = { attributes: true, childList: true, subtree: true };
        const callback = function(mutationsList, observer) {
            //console.log('herex'+ $('.balance-summary .data').length);
            if ($('.balance-summary .data').length>0) {
                observer.disconnect();
                uiChanges();
            }
        };

        const observer = new MutationObserver(callback);
        observer.observe(targetNode, config);
    }

    function uiChanges() {
        $('.fc-button-next').prependTo('.fc-header-left');
        $('.fc-button-prev').prependTo('.fc-header-left');

        var balances = $('#balanceBar .value');
        var takenSoFar = 0;
        var remaining = 0;
        $(balances).each(function( index ) {
            if(index==0) takenSoFar = $(this).html();
            if(index==1) remaining = $(this).html();
        });
        //console.log(takenSoFar + ' .. ' + remaining);
        var balance = remaining - takenSoFar;

        $('#balanceBar .last').before('<li><div class="data"><span class="value">'+balance+'</span><span class="label">Remaining</span></div></li>');
    }

})();