ServiceNow - WF - Context add info

Additional information in workflow context

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         ServiceNow - WF - Context add info
// @version      0.0.2
// @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';

    let navBarRight = document.querySelector('div.navbar-right');

    if(!navBarRight) {
        return;
    }

    let updateViewButton = document.createElement('button');
    updateViewButton.title = '[WK - SN] Update view';
    updateViewButton.classList.add('btn', 'btn-icon', 'navbar-btn', 'icon', 'icon-info');
    updateViewButton.onclick = addActionsInfo;

    navBarRight.append(updateViewButton);

    function addActionsInfo() {

        let timeSpans = document.querySelectorAll('span.wk-wf-time-span');
        if(timeSpans.length > 0) {
            timeSpans.forEach(timeSpan => {
                timeSpan.style.display = (timeSpan.style.display === 'block') ? 'none' : 'block';
            });
            return;
        }

        let selector = 'div.drag_section_part';
        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.wf_condition').getElementsByTagName('tbody')[0];

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

            rowStart.style.backgroundColor = '#e6e9eb';

            let timeSpan = document.createElement('span');
            timeSpan.title = '[WK - SN] Start/End date time';
            timeSpan.innerText = actionStart + '\n' + actionEnd;
            timeSpan.style.fontSize = '8pt';
            timeSpan.style.display = 'block';
            //timeSpan.style.padding = '3px';
            timeSpan.classList.add('wk-wf-time-span');

            cellStart.appendChild(timeSpan);
        });
    }

})();