Skip to content

Commit

Permalink
Mutiple updates, check CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoudkooi committed Feb 19, 2024
1 parent 38c024c commit 8c4d877
Show file tree
Hide file tree
Showing 7 changed files with 360 additions and 22 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# CHANGELOG.md
## 7.2.3.1 (2024-02-0)

## 7.3.0.0 (2024-02-19)
Features:
- Slash command now triggers a global search when now match is found, ie: /INC3940740 opens that incident. This is a shortcut for the /search command. If the command contains a _ it tries to open a table list like it used to.
- /copycells can now be triggered via the OS copy shortcut (ctrl-c or cmd-c), when no other selection is made
- The Modern Background scripts now get split and execute inline and other enhancements, like the classic background scripts.
- Pages on old background script get redirected to the modern background script page, when it detects the instance runs on washington release.
Fixes / changes:
- Mousevents now work on form labels with a hyperlink, after /tn moves the link to the ↗ symbol
- Added function snuCheckFamily to inject.js, this helps to determine the family release of the instance


## 7.2.3.1 (2024-02-07)
Fixes / changes:
- Fix for not applying switches with numbers (Issue #465)

Expand Down
5 changes: 5 additions & 0 deletions content_script_all_frames.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
addScript('js/monaco/bgscript.js', false);
}, 600)
}
else if (location.pathname == "/sys.scripts.modern.do") {
setTimeout(function () {
addScript('js/bgscriptmodern.js', false);
}, 400)
}
else if (location.pathname.startsWith("/merge_form_")) {
addScript('js/monaco/compare.js', false);
}
Expand Down
15 changes: 12 additions & 3 deletions css/background.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ body {
hr {
border: 0;
height: 1px;
background: #333;
background-image: linear-gradient(to right, #ccc, #333, #ccc);
background: #e5e5e5;
margin-block-start: 4px;
margin-block-end: 4px;
background-image: linear-gradient(to right, #e5e5e5, #ccc, #e5e5e5);
}

pre {
Expand All @@ -55,4 +57,11 @@ pre {

label{
font-size:9pt;
}
}

/* modern additions */
h4, .result_header{
height: 20px;
margin-block-start: 0;
margin-block-end: 0;
}
93 changes: 76 additions & 17 deletions inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ var snuslashcommands = {
"hint": "Background Script with var current"
},
"bgl": {
"url": "/sys.scripts.do?content=var%20list%20%3D%20new%20GlideRecord%28%22$table%22%29%3B%0Alist.addEncodedQuery%28%22$encodedquery%22%29%3B%0Alist.setLimit%2810%29%3B%0Alist.query%28%29%3B%0Awhile%20%28list.next%28%29%29%7B%0A%20%20%20%20gs.info%28list.getDisplayValue%28%29%29%3B%0A%7D%3B",
"url": "/sys.scripts.do?content=var%20list%20%3D%20new%20GlideRecord%28%22$table%22%29%3B%0Alist.addEncodedQuery%28%22$encodedquery%22%29%3B%0Alist.setLimit%2810%29%3B%0Alist.query%28%29%3B%0Awhile%20%28list.next%28%29%29%7B%0A%20%20%20%20gs.info%28list.getDisplayValue%28%29%29%3B%0A%7D",
"hint": "Background Script with list gr"
},
"bgm": {
"url": "sys.scripts.modern.do",
"hint": "Background Script Modern (Washington and up)"
},
"cls": {
"url": "*",
"hint": "Clear Local Storage"
Expand Down Expand Up @@ -463,7 +467,7 @@ function snuGetTables(shortcut) {
};
}
});
snuExpandHints(shortcut)
if (results?.length) snuExpandHints(shortcut)
} else {
snuSlashCommandInfoText(`<b>Log</b><br />- Tables can not be retrieved.<br />`, true);
}
Expand Down Expand Up @@ -655,6 +659,10 @@ function snuSlashCommandAddListener() {
e.currentTarget.value = (e.currentTarget.value + window.top.document.snuSelection).trim();
thisKey = "";
e.preventDefault();
setTimeout(()=> {
window.top.document.getElementById('snufilter').dispatchEvent(new KeyboardEvent('keydown', { 'key': 'Shift' }));
},150)

}
if (noSpace) idx = snufilter.length;
var originalShortcut = ((snufilter.slice(0, idx) + ((noSpace) ? thisKey : ""))).toLowerCase();
Expand Down Expand Up @@ -777,18 +785,18 @@ function snuSlashCommandAddListener() {
idx = (snufilter.indexOf(' ') == -1) ? snufilter.length : snufilter.indexOf(' ');
query = snufilter.slice(idx + 1);

if (['nav', 'fav', 'hist'].includes(shortcut)) {
e.preventDefault();
return;
}
// if (['nav', 'fav', 'hist'].includes(shortcut)) { //I think this can/should be removed.
// e.preventDefault();
// return;
// }
if (shortcut.replace(/['" ]+/g, '').match(/^[0-9a-f]{32}$/) != null || shortcut == "sysid") {//is a sys_id
var sysid = (shortcut.replace(/['" ]+/g, '').length == 32) ? shortcut.replace(/['" ]+/g, '') : query;
if (sysid.length != 32) return;
snuSearchSysIdTables(sysid);
//snuSlashCommandHide();
return;
}
if (/.*_([0-9a-fA-F]{32})$/.test(shortcut)) {//table_name_sysid pattern
else if (/.*_([0-9a-fA-F]{32})$/.test(shortcut)) {//table_name_sysid pattern
const result = shortcut.split(/_(?=[0-9a-fA-F]{32}$)/);
window.open(result[0] + ".do?sys_id=" + result[1], '_blank');
return;
Expand Down Expand Up @@ -894,6 +902,9 @@ function snuSlashCommandAddListener() {
else if (shortcut == "copycells" || shortcut == "copycolumn") {
snuCopySelectedCellValues(query, shortcut);
snuSlashCommandHide();
if (shortcut == "copycells" && !query) {
snuSlashCommandInfoText("You can now try CTRL-C / CMD-C instead of the slashcommand", false);
}
return;
}
else if (shortcut == "s2") {
Expand Down Expand Up @@ -1081,7 +1092,7 @@ function snuSlashCommandAddListener() {
}
else if (!snuslashcommands.hasOwnProperty(shortcut)) {

var inIFrame = (shortcut == snufilter.slice(0, idx) && sameWindow)
var inIFrame = (shortcut == snufilter.toLowerCase().slice(0, idx) && sameWindow)
if (e.target.className == "snutils") inIFrame = false;

if (shortcut.includes('.do')) {
Expand All @@ -1100,8 +1111,11 @@ function snuSlashCommandAddListener() {
snuSlashCommandHide();
return;
}
else if (shortcut.length > 4) { //try to open table list if shortcut nnot defined and 5+ charaters
var url = shortcut + "_list.do?sysparm_filter_pinned=true&sysparm_query=" + query;
else if (shortcut.length > 4 ) { //try to open table list if shortcut nnot defined and 5+ charaters

var url = 'text_search_exact_match.do?sysparm_search=' + snufilter;
if (shortcut.includes('_'))
url = shortcut + "_list.do?sysparm_filter_pinned=true&sysparm_query=" + query;

if (inIFrame) {
(document.querySelector("#gsft_main") || document.querySelector("[component-id]").shadowRoot.querySelector("#gsft_main")).src = url;
Expand Down Expand Up @@ -1238,6 +1252,11 @@ function snuSlashCommandShowHints(shortcut, selectFirst, snufilter, switchText,
if ((e.ctrlKey || e.metaKey) && e.key == 'v' && shortcut == 'v') {
//asume a sys_id when pasting for correct 'autocomplete'
shortcut = "00000000000000000000000000000000";

setTimeout(()=> { //this forces a refresh of the hints
window.top.document.getElementById('snufilter').dispatchEvent(new KeyboardEvent('keydown', { 'key': 'Shift' }));
},150)

}

var startswith = true;
Expand Down Expand Up @@ -1308,7 +1327,13 @@ function snuSlashCommandShowHints(shortcut, selectFirst, snufilter, switchText,
// html += "<li class='cmdfilter' ><span class='cmdkey'>/" + shortcut + "</span> " +
// "<span class='cmdlabel'>Table search &lt;encodedquery&gt; (hit ► to search tables)</span></li>"
}
if (snuPropertyNames.length == 0 && snufilter.length > 3) {
html += "<li class='cmdfilter' ><span class='cmdfilter cmdkey'>/search</span> " +
"<span class='cmdlabel'>Search for: " + snufilter + "</span></li>";
}
switchText = (switchText.length > 25) ? switchText : ''; //only if string > 25 chars;
if (!html)
console.log(html)
window.top.document.getElementById('snuhelper').innerHTML = DOMPurify.sanitize(html);
window.top.document.getElementById('snudirectlinks').innerHTML = DOMPurify.sanitize('');
window.top.document.getElementById('snuswitches').innerHTML = DOMPurify.sanitize(switchText);
Expand All @@ -1322,6 +1347,7 @@ function snuSlashCommandShowHints(shortcut, selectFirst, snufilter, switchText,

if (snusettings.slashnavigatorsearch && snuPropertyNames.length <= 3 && switchText.length <=25)
snuDoSlashNavigatorSearch(shortcut + ' ' + snufilter, arrDigits);

}

function setSnuFilter(ev) {
Expand Down Expand Up @@ -2612,10 +2638,13 @@ function snuAddTechnicalNames() {
}
jQuery(this).html('<span style="font-family:monospace; display:none" class="label-tech">' + elmDisp + '</span><span class="label-orig">' + this.innerHTML + '</span><span class="snuwrap"><span class="dict" title="Open dictionary entry">&nbsp;! </span><span class="pillar">&nbsp;| </span><span class="label-snu" style="font-family:monospace; ">' + (linkBtn || elm) + '</span><sup data-element="'+ elm +'"></sup></span>');
//jQuery(this).closest('a').replaceWith(function () { return jQuery(this).contents(); });
jQuery(this).closest('a').replaceWith(function () {
var cnt = this.innerHTML; var hl = this; hl.innerHTML = DOMPurify.sanitize("↗"); hl.title = "-SN Utils Original hyperlink-\n" + hl.title; hl.target = "_blank";
return DOMPurify.sanitize(hl.outerHTML + " " + cnt, { ADD_ATTR: ['target'] });
});
if (this.closest('a')){
elem.closest('label').style.pointerEvents = 'all';
jQuery(this).closest('a').replaceWith(function () {
var cnt = this.innerHTML; var hl = this; hl.innerHTML = DOMPurify.sanitize("↗"); hl.title = "-SN Utils Original hyperlink-\n" + hl.title; hl.target = "_blank";
return DOMPurify.sanitize(hl.outerHTML + " " + cnt, { ADD_ATTR: ['target'] });
});
}
});

} catch (error) {
Expand Down Expand Up @@ -3182,6 +3211,14 @@ function snuOpenWorkflowLink(){

function snuBindPaste(showIcon) {

//this is test to be able to use default copy event to copy cell values, without the need use /copycells
document.querySelector('body').addEventListener("copy", (event) => {
if (typeof g_list_edit_grid != 'undefined') { //list or form
if (!snuGetSelectionText())
snuCopySelectedCellValues();
}
});

if (typeof g_form != 'undefined') {

document.querySelector('body').addEventListener('paste', (e) => {
Expand Down Expand Up @@ -3708,8 +3745,8 @@ function snuCopySelectedCellValues(copySysIDs, shortcut = "copycells") {
hasCopied = true;
} else {
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");
if (!iframes.length && window.top.document.querySelector("[global-navigation-config]")) //try to find iframe in case of polaris
iframes = window.top.document.querySelector("[global-navigation-config]").shadowRoot.querySelectorAll("iframe");

Array.from(iframes).forEach(function (frm) {
selCells = frm.contentWindow.document.querySelectorAll('.list_edit_selected_cell, .list_edit_cursor_cell');
Expand Down Expand Up @@ -3756,7 +3793,12 @@ function snuCopySelectedCellValues(copySysIDs, shortcut = "copycells") {
});
if (str.endsWith(',')) str = str.substring(0, str.length - 1);

wdw.copyToClipboard(str);
setTimeout(() => {
if (typeof snuLastCopied == 'undefined' || new Date().getTime() - snuLastCopied > 500) {
snuLastCopied = new Date().getTime();
wdw.copyToClipboard(str);
}
},1);
return;
}
};
Expand Down Expand Up @@ -5097,5 +5139,22 @@ function snuTest(){
//Otherwise, execute the batch request
return snuBatchRequest(token, batchRequests);

}

async function snuCheckFamily(){
let family = '';
try{
let storedfamily = JSON.parse(localStorage.getItem('snufamily')) || {}; //once a day check version (use /cls to clear cache)
if (storedfamily?.checked == new Date().toISOString().substring(0,10))
return storedfamily?.family;

let fetchd = await snuFetchData(g_ck, '/api/now/table/sys_properties?sysparm_limit=1&sysparm_fields=value&sysparm_query=name=com.glide.embedded_help.version');
family = fetchd?.result[0]?.value;
storedfamily = { family: family, checked: new Date().toISOString().substring(0,10) };
localStorage.setItem('snufamily', JSON.stringify(storedfamily));
}
catch(e){
family = 'unknown';
}
return family;
}
Loading

0 comments on commit 8c4d877

Please sign in to comment.