From a4c9ee0372c699111d41818d7bfc86e3b7bcd311 Mon Sep 17 00:00:00 2001 From: arnoudkooi Date: Sat, 9 Dec 2023 00:51:10 +0100 Subject: [PATCH] Add /copycolumn command and fix manifest file for Edge --- CHANGELOG.md | 8 ++++++++ inject.js | 34 ++++++++++++++++++++++++++++------ manifest.json | 2 +- publish/manifest-edge.json | 3 ++- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c007c9e..d0ee59a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG.md +## 7.1.9.0 (2023-12-08) +Features: + - Added /copycolumn command, in addition to /copycells It will copy all non empty values of the column where a cell is selected. +Fixes / changes: + - Adjust manifest file for Edge to allow servicenowservices.com domain + - Expand the doubleclick area in the headerbar to trigger page reload + - Fix to support the /um unmnadatory command inside Next Experience + ## 7.1.8.0 (2023-12-04) Fixes / changes: - Show the quick add button on related lists (Discussion #451) diff --git a/inject.js b/inject.js index 10527c2..074b00e 100644 --- a/inject.js +++ b/inject.js @@ -51,6 +51,10 @@ var snuslashcommands = { "url": "*", "hint": "Copy Selected Cell Values from List [-s for SysIDs]" }, + "copycolumn": { + "url": "*", + "hint": "Copy All Values from Selected Column [-s for SysIDs]" + }, "debug": { "url": "*", "hint": "Open Script Debugger" @@ -883,8 +887,8 @@ function snuSlashCommandAddListener() { } return; } - else if (shortcut == "copycells") { - snuCopySelectedCellValues(query); + else if (shortcut == "copycells" || shortcut == "copycolumn") { + snuCopySelectedCellValues(query, shortcut); snuSlashCommandHide(); return; } @@ -1802,7 +1806,7 @@ function snuDoubleClickToShowFieldOrReload() { } else { alert('[SN Utils]\nField Type: ' + glideUIElement.type + '\nField: ' + elm + '\nValue:' + val); } - } else if (event.target.classList.contains('container-fluid')) { + } else if (event.target.classList.contains('container-fluid') || event.target.classList.contains('navbar_ui_actions')) { location.reload(); } else if (event.target.classList.contains('breadcrumb_container')) { //placeholder maybe move breadcrumb doubleclick here @@ -3666,9 +3670,9 @@ function snuFillFields(query) { } }; -function snuCopySelectedCellValues(copySysIDs) { +function snuCopySelectedCellValues(copySysIDs, shortcut = "copycells") { var hasCopied = false; - var selCells = window.top.document.querySelectorAll('.list_edit_selected_cell'); + var selCells = window.top.document.querySelectorAll('.list_edit_selected_cell, .list_edit_cursor_cell'); if (selCells.length > 0) { doCopy(selCells); hasCopied = true; @@ -3678,7 +3682,7 @@ function snuCopySelectedCellValues(copySysIDs) { iframes = document.querySelector("[global-navigation-config]").shadowRoot.querySelectorAll("iframe"); Array.from(iframes).forEach(function (frm) { - selCells = frm.contentWindow.document.querySelectorAll('.list_edit_selected_cell'); + selCells = frm.contentWindow.document.querySelectorAll('.list_edit_selected_cell, .list_edit_cursor_cell'); if (selCells.length > 0) { doCopy(selCells, frm); hasCopied = true; @@ -3689,6 +3693,14 @@ function snuCopySelectedCellValues(copySysIDs) { function doCopy(selCells, frm) { var str = ''; var wdw = (frm) ? frm.contentWindow : window; + + if (shortcut == "copycolumn") { + let firstCell = selCells[0]; + let columnIndex = Array.from(firstCell.parentElement.children).indexOf(firstCell); + let rows = firstCell.closest('table').querySelectorAll('tr'); + selCells = Array.from(rows).map(row => row.cells[columnIndex]).filter(td => td !== undefined && td.classList.contains('vt') && td.innerText); + } + selCells.forEach(function (cElem) { if (copySysIDs) { if (cElem.querySelector('a')) { @@ -3941,6 +3953,16 @@ function snuAddBGScriptButton() { } function snuSetAllMandatoryFieldsToFalse() { + + var iframes = window.top.document.querySelectorAll("iframe"); + if (!iframes.length && document.querySelector("[global-navigation-config]")) //try to find iframe in case of polaris + iframes = document.querySelector("[global-navigation-config]").shadowRoot.querySelectorAll("iframe"); + + iframes.forEach((iframe) => { + if (typeof iframe.contentWindow.unhideFields != 'undefined') + iframe.contentWindow.snuSetAllMandatoryFieldsToFalse(); + }); + if (typeof g_form != 'undefined' && typeof g_user != 'undefined') { if (g_user.hasRole('admin')) { var fields = g_form.getEditableFields(); diff --git a/manifest.json b/manifest.json index 549d6b5..886a5fc 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "short_name": "SN Utils", "description": "Productivity tools for ServiceNow. (Personal work, not affiliated to ServiceNow)", "author": "Arnoud Kooi / arnoudkooi.com", - "version": "7.1.8.0", + "version": "7.1.9.0", "manifest_version": 3, "permissions": [ "activeTab", diff --git a/publish/manifest-edge.json b/publish/manifest-edge.json index 7b59a76..fc2eb09 100644 --- a/publish/manifest-edge.json +++ b/publish/manifest-edge.json @@ -102,7 +102,8 @@ "js/*" ], "matches": [ - "https://*.service-now.com/*" + "https://*.service-now.com/*", + "https://*.servicenowservices.com/*" ] } ],