From 42fd05b79ec31cf9174f8ab76108e075164a6e63 Mon Sep 17 00:00:00 2001 From: arnoudkooi Date: Wed, 23 Oct 2024 23:45:38 +0200 Subject: [PATCH] Slash command improvements v8.2.2.0 --- CHANGELOG.md | 5 +++++ inject.js | 13 +++++++++---- manifest.json | 2 +- popup.js | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 428032d..28db519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG.md +## 8.2.2.0 (2024-10-23) +Fixes / changes: + - Autocomplete for slash command switches, i.e. -u (Slack) + - Allow - and _ character in slash commands and switches (Slack) + ## 8.2.1.4 (2024-10-21) Fixes / changes: - Fix Doubleclick refrence icon on catalog item variables in the formatter (LinkedIn post comment) diff --git a/inject.js b/inject.js index 66ffc62..3fd0c82 100644 --- a/inject.js +++ b/inject.js @@ -762,11 +762,12 @@ function snuSlashCommandAddListener() { if (originalShortcut.startsWith("-")) query = shortcut; var extraParams = ""; var unusedSwitches = Object.assign({}, snuslashswitches); - var switches = (query + thisKey).match(/\-([a-z0-9]*)(\s|$)/g); + var switches = (query + thisKey).match(/\-([a-z0-9_-]*)(\s|$)/g); var linkSwitch = false; //determine if this is a switch that converts the entire hyperlink + let autoCompleteSwitch = ""; if (switches) { Object.entries(switches).forEach(([key, val]) => { - var prop = val.replace(/\s|\-/g, ''); + var prop = val.replace(/\s/g, '').replace('-', ''); if (snuslashswitches.hasOwnProperty(prop) && !linkSwitch) { var switchValue = snuslashswitches[prop].value; var tableName = targeturl.split("_list.do")[0] || ''; @@ -802,12 +803,16 @@ function snuSlashCommandAddListener() { switchText += "
-" + prop + ": " + snuslashswitches[prop].description + '
'; delete unusedSwitches[prop]; } + else { + autoCompleteSwitch = prop; + } }); targeturl += extraParams; } Object.entries(unusedSwitches).forEach(([key, val]) => { - switchText += "
-" + key + ": " + val.description + '
'; + if (key.startsWith(autoCompleteSwitch)) + switchText += "
-" + key + ": " + val.description + '
'; }); } @@ -1338,7 +1343,7 @@ function snuSlashCommandShowHints(shortcut, selectFirst, snufilter, switchText, // snuPropertyNames = [shortcut]; // } - if (snuPropertyNames.length > 0 && selectFirst && !snuPropertyNames.includes(shortcut)) { //select first hit when tap or space pressed + if (snuPropertyNames.length > 0 && selectFirst && (!snuPropertyNames.includes(shortcut) || snuIndex > 0)) { //select first hit when tap or space pressed if (e) e.preventDefault(); shortcut = snuPropertyNames[snuIndex]; snuPropertyNames = [snuPropertyNames[snuIndex]]; diff --git a/manifest.json b/manifest.json index 2a40628..8e04c75 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": "8.2.1.4", + "version": "8.2.2.0", "manifest_version": 3, "permissions": [ "activeTab", diff --git a/popup.js b/popup.js index a1fff87..cc240b3 100644 --- a/popup.js +++ b/popup.js @@ -1372,7 +1372,7 @@ function getSlashcommands() { try { cmds = JSON.parse($('#slashcommands').val()); } catch (e) { }; - var cmdname = $('#tbxslashcmd').val().replace(/[^a-zA-Z0-9]/gi, '').toLowerCase(); + var cmdname = $('#tbxslashcmd').val().replace(/[^a-zA-Z0-9_-]/gi, '').toLowerCase(); if (!cmdname){ $('#divslashmsg').text('No command name defined'); return;