From afc02fb5a329ade3b4f23bf7fbab5f47b711bd88 Mon Sep 17 00:00:00 2001 From: arnoudkooi Date: Thu, 28 Mar 2024 00:27:34 +0100 Subject: [PATCH] Several updates / #484 #486 --- CHANGELOG.md | 8 ++++++++ inject.js | 39 +++++++++++++++++++++++++++++---------- manifest.json | 2 +- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0a5791..7a14a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ # CHANGELOG.md +## 7.4.2.0 (2024-03-27) +Fixes / changes: + - Minor updates for /vd not always working in Firefox (Issue #484) + - Prevent global g_list object on forms (may interfeer with OOB scripts) + - Added snuAddGckToken function to inject.js run when on stats.do page. This adds the g_ck token so that Node switching and othe popup functions works when on that page. + - Fix for scriptsync button not working on classic BG script page (Issue #486) + - Note: 7.4.1.7 and 7.4.1.9 only published for troubleshooting purposes + ## 7.4.1.5 (2024-03-25) Fixes / changes: diff --git a/inject.js b/inject.js index 6dbebdf..d71da0e 100644 --- a/inject.js +++ b/inject.js @@ -883,7 +883,7 @@ function snuSlashCommandAddListener() { var data = {}; data.instance = window.location.host.split('.')[0]; data.url = window.location.origin; - data.g_ck = g_ck; + data.g_ck = g_ck || window.top.g_ck; data.query = query; var event = new CustomEvent( "snutils-event", @@ -907,7 +907,7 @@ function snuSlashCommandAddListener() { data.sysId = vars.sysId; data.instance = window.location.host.split('.')[0]; data.url = window.location.origin; - data.g_ck = g_ck; + data.g_ck = g_ck || window.top.g_ck; let event = new CustomEvent( "snutils-event", { @@ -1480,7 +1480,7 @@ function snuResolveVariables(variableString){ let tableName = ''; let sysId = ''; let encodedQuery = ''; - let doc = gsft ? gsft.contentWindow : window; + let doc = gsft ? gsft.contentWindow : window.top; if (typeof doc.g_form !== 'undefined') { //get sysid and tablename from classic form tableName = doc.g_form.getTableName(); sysId = doc.g_form.getUniqueValue(); @@ -1555,7 +1555,7 @@ function snuResolveVariables(variableString){ variableString = variableString.replace(/\$sysid/g, sysId); } } - rtrn = { + let rtrn = { "variableString" : variableString, "tableName" : tableName, "sysId" : sysId, @@ -1661,8 +1661,11 @@ function snuSettingsAdded() { snuEnterToFilterSlushBucket(); snuHyperlinkifyWorkNotes(); snuEasifyAdvancedFilter(); + snuAddGckToken("stats.do"); + } + if (snusettings.hasOwnProperty("slashcommands")) { try { var customCommands = JSON.parse(snusettings.slashcommands || "{}"); @@ -2064,6 +2067,23 @@ function snuS2Ify() { } +async function snuAddGckToken(pathName = ""){ + if (!(location.pathname.includes(pathName) && !g_ck)) return; + + const response = await fetch(`/sn_devstudio_/v1/get_publish_info.do`, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': 'BasicCustom' + } + }); + if (response.ok) { + const resp = await response.json(); + g_ck = resp?.ck; //set the global g_ck + } +} + function snuAddFormDesignScopeChange() { if (location.pathname == "/$ng_fd.do") { @@ -2279,7 +2299,7 @@ function snuCaptureFormClick() { } } - if (event.target.className.includes('scriptSync icon-save')) { + if (event.target.className.length && event.target.className.includes('scriptSync icon-save')) { //for svg className is an object if (g_form.isNewRecord()) { snuSlashCommandInfoText('This is a new record, try again after saving',false); return true; @@ -2287,7 +2307,7 @@ function snuCaptureFormClick() { snuPostToScriptSync(event.target.dataset.field, event.target.dataset.fieldtype); event.target.style.opacity = 0.3; } - if (event.target.className.includes('scriptSync icon-code')) { + else if (event.target.className.length && event.target.className.includes('scriptSync icon-code')) { if (g_form.isNewRecord()) { snuSlashCommandInfoText('This is a new record, try again after saving',false); return true; @@ -3970,7 +3990,7 @@ function snuPostToScriptSync(field, fieldType) { } else { //bgscript - let scriptVal = document.querySelector('#runscript')?.value || snuEditor?.getValue(); + let scriptVal = (typeof snuEditor !== 'undefined') ? snuEditor.getValue() : document.querySelector('#runscript')?.value; //modern or classic... let scope = document.querySelector('select[name=sys_scope]')?.value || 'global'; @@ -3996,7 +4016,7 @@ function snuPostLinkRequestToScriptSync(field) { var instance = {}; instance.name = window.location.host.split('.')[0]; instance.url = window.location.origin; - instance.g_ck = g_ck; + instance.g_ck = g_ck || window.top.g_ck; var ngScope = angular.element(document.getElementById('explorer-editor-wrapper')).scope() var data = {}; @@ -4874,8 +4894,7 @@ function snuAddPersonaliseListHandler() { function snuListFilterHelper() { - if (typeof GlideList2 == 'undefined') return; - + if (typeof GlideList2 == 'undefined' || typeof g_form !== 'undefined') return true; //prevent global g_list on forms let relatedListsButtons = document.querySelectorAll('[data-type="list_mechanic2_open"]:not(.snuified)'); if (!relatedListsButtons) return; diff --git a/manifest.json b/manifest.json index 632baad..19e3d3b 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.4.1.5", + "version": "7.4.1.9", "manifest_version": 3, "permissions": [ "activeTab",