ServiceNow - WF - Context add info

Additional information in workflow context

От 10.03.2024. Виж последната версия.

// ==UserScript==
// @name         ServiceNow - WF - Context add info
// @version      0.0.1
// @description  Additional information in workflow context
// @author       Matteo Lecca
// @match        *.service-now.com/context_workflow.do*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=service-now.com
// @grant        none
// @license MIT
// @namespace    https://greasyfork.org/users/1246673
// ==/UserScript==

(function () {
    'use strict';

    function waitForEl(selector) {
        if (document.querySelectorAll(selector).length > 0) {
            addActionsInfo(selector);
        } else {
            setTimeout(function () {
                waitForEl(selector);
            }, 3000);
        }
    };

    waitForEl('div.drag_section_part');

    function addActionsInfo(selector) {

        let wfDragAreas = document.querySelectorAll(selector);

        wfDragAreas.forEach(wfDragArea => {
            let hoverArea = wfDragArea.getElementsByClassName('hidden-but-read')[0];
            let actionStart = hoverArea.innerHTML.match(/<br>(Started.*?)<br>/).pop();
            let actionEnd = hoverArea.innerHTML.match(/<br>(Ended.*?)<br>/).pop();

            let tableRef = wfDragArea.querySelector('table[role="presentation"]').getElementsByTagName('tbody')[0];

            // Start label
            let rowStart = tableRef.insertRow(1);
            let cellStart = rowStart.insertCell(0);

            rowStart.style.backgroundColor = '#e6e9eb';

            let startSpan = document.createElement('span');
            startSpan.title = '[WK - SN] Action Start Date';
            startSpan.innerText = actionStart;
            startSpan.style.fontSize = '8pt';
            startSpan.style.padding = '3px';

            cellStart.appendChild(startSpan);

            // End label
            let rowEnd = tableRef.insertRow(2);
            let cellEnd = rowEnd.insertCell(0);

            rowEnd.style.backgroundColor = '#e6e9eb';

            let endSpan = document.createElement('span');
            endSpan.title = '[WK - SN] Action End Date';
            endSpan.innerText = actionEnd;
            endSpan.style.fontSize = '8pt';
            endSpan.style.padding = '3px';

            cellEnd.appendChild(endSpan);
        });
    }

})();