Skip to content

Commit

Permalink
Several updates / #484 #486
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoudkooi committed Mar 27, 2024
1 parent 73caf65 commit afc02fb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
39 changes: 29 additions & 10 deletions inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1555,7 +1555,7 @@ function snuResolveVariables(variableString){
variableString = variableString.replace(/\$sysid/g, sysId);
}
}
rtrn = {
let rtrn = {
"variableString" : variableString,
"tableName" : tableName,
"sysId" : sysId,
Expand Down Expand Up @@ -1661,8 +1661,11 @@ function snuSettingsAdded() {
snuEnterToFilterSlushBucket();
snuHyperlinkifyWorkNotes();
snuEasifyAdvancedFilter();
snuAddGckToken("stats.do");

}


if (snusettings.hasOwnProperty("slashcommands")) {
try {
var customCommands = JSON.parse(snusettings.slashcommands || "{}");
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -2279,15 +2299,15 @@ 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;
}
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;
Expand Down Expand Up @@ -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';


Expand All @@ -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 = {};
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit afc02fb

Please sign in to comment.