Highlight Assigned to Me

Highlight my incidents/changes

当前为 2020-04-02 提交的版本,查看 最新版本

// ==UserScript==
// @name         Highlight Assigned to Me
// @version      0.1

// @description  Highlight my incidents/changes
// @author       Ricardo Constantino
// @match        https://frusupport.service-now.com/*_list.do?*
// @grant        none
// @namespace https://greasyfork.org/users/129739
// ==/UserScript==

(function() {
    'use strict';

    const TABLES = ['change_request', 'incident'];
    const BG_COLOR = '#bcefff';
    const EVEN_STYLE = `
background-color: ${BG_COLOR} !important;
`;
    const ODD_STYLE = `
/* background-color: ${BG_COLOR}87 !important; */
${EVEN_STYLE}
`;

    let assignedToColumn = document.querySelector('th[name="assigned_to"]');
    if (!assignedToColumn) return;

    let assignedToColumnIdx = [...assignedToColumn.parentElement.children].indexOf(assignedToColumn);

    let tableElem = assignedToColumn.parentElement.parentElement.parentElement;
    if (TABLES.indexOf(assignedToColumn.parentElement.parentElement.parentElement.getAttribute('list_name')) === -1) return;

    let rowsAssignedToMe = [...tableElem.querySelectorAll('td:nth-child('+(assignedToColumnIdx+1)+')')]
        .filter(e => e.children.length > 0)
        .map(e => e.children[0])
        .filter(e => e.getAttribute('sys_id') === g_user.getUserID())
        .map(e => e.parentElement.parentElement);

    rowsAssignedToMe.forEach(r => r.addClassName('assignedToMe'));

    let d = document.createElement('style');
    d.textContent = `tr.assignedToMe.list_even td { ${EVEN_STYLE} }\ntr.assignedToMe.list_odd td { ${ODD_STYLE} }`;
    document.querySelector("style").append(d);
})();