salience / Time Sheet Portal

// ==UserScript==
// @name         Time Sheet Portal
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  Small fixes to Time Sheet Portal
// @author       salience
// @copyright    2022, salience (https://openuserjs.org/users/salience)
// @license      MIT
// @match        https://servicepoint.mtrltech.com/tcp?id=worker_portal_x0410*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=service-now.com
// @grant        none
// ==/UserScript==

const css = `<style type="text/css">
@media (min-width: 1200px) {
    #tc-grid-table.container {
        width: 1200px !important;
    }
}
#cal-container-1 * {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}
#cal-container-1 .cal-container-4 {
    min-height: 5rem;
}
.time-breakdown + .flex-grow {
    display: flex;
    align-items: center;
}
#chart-area {
    display: none;
}
#tc-grid-table .project_time_category {
    display: none;
}
#tc-grid-table .table-headers > *:first-child,
#tc-grid-table .tc-row > *:first-child {
    min-width: 300px !important;
}
#tc-grid-table .tc-row > .flex-item {
    padding-top: 0;
    padding-bottom: 0;
}
.cards-panel-container .cards-panel-header {
    display: none;
}
.cards-panel-container .cards-panel-body {
    padding-top: .5rem !important;
}
.card {
    margin-bottom: .5rem !important;
}
.card > div:first-child {
    padding: .5rem 1rem !important;
}
.card > div:last-child,
.card > div:last-child * {
    padding: 0 !important;
}
.card > div:last-child * {
    padding-right: .5rem !important;
    opacity: 1 !important;
}
.card .secondary-fields {
    display: flex;
    flex-direction: column;
}
.card .parent-container {
    display: none;
}
</style>`;

(function() {

    // Favicon
    var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
    link.type = 'image/png';
    link.rel = 'shortcut icon';
    link.href = 'https://i.imgur.com/tEGie2N.png';
    document.getElementsByTagName('head')[0].appendChild(link);

    // CSS
    document.body.insertAdjacentHTML('afterend', css);

    /*
    // Always use comma as a decimal separator
    document.body.addEventListener("keydown", (e) => {
        if (e.target.className.includes('tc-row-input') && e.key === '.') {

            // get old value
            var start = e.target.selectionStart;
            var end = e.target.selectionEnd;
            var oldValue = e.target.value;

            // replace point and change input value
            var newValue = oldValue.slice(0, start) + ',' + oldValue.slice(end)
            e.target.value = newValue;

            // replace cursor
            e.target.selectionStart = e.target.selectionEnd = start + 1;
            e.preventDefault();
        }
    });
    */

})();