From fc1725c22a780304ec886dcad7ec7292f0581e44 Mon Sep 17 00:00:00 2001 From: arnoudkooi Date: Mon, 28 Oct 2024 23:41:05 +0100 Subject: [PATCH] Slash switches editor v8.2.3.0 --- CHANGELOG.md | 10 +++ inject.js | 2 +- js/monaco/settingeditor.js | 167 +++++++++++++++++++++++++++++++++++++ popup.html | 6 +- popup.js | 17 ++-- settingeditor.html | 43 ++++++++++ 6 files changed, 236 insertions(+), 9 deletions(-) create mode 100644 js/monaco/settingeditor.js create mode 100644 settingeditor.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 41780a1..4f15293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,14 @@ # CHANGELOG.md +## 8.2.3.0 (2024-10-28) +Features: + - Moving the advanced slashcommand and slasswitches editing to Monaco editor in a new browser tab + +Fixes / changes: + - Improve handling of "link" type switches autocomplete (Slack) + - Changing setting to default on: Prioritize CTRL-/ and CMD-/ above OOB shortcut. + + + ## 8.2.2.1 (2024-10-24) Fixes / changes: diff --git a/inject.js b/inject.js index f85881c..5d87d99 100644 --- a/inject.js +++ b/inject.js @@ -783,7 +783,7 @@ function snuSlashCommandAddListener() { switchValue = snuslashswitchesvalueoverwrites[`${prop}.${tableName}`]; } query = query.replace(val, ""); - if (snuslashswitches[prop].type == "link") { + if (snuslashswitches[prop].type == "link" && (snufilter + thisKeyWithSpace).includes("-" + prop + " ")) { targeturl = switchValue.replace(/\$0/g, tableName); targeturl = targeturl.replace(/\$sysid/, mySysId); targeturl = snuResolveVariables(targeturl).variableString; diff --git a/js/monaco/settingeditor.js b/js/monaco/settingeditor.js new file mode 100644 index 0000000..28ab909 --- /dev/null +++ b/js/monaco/settingeditor.js @@ -0,0 +1,167 @@ +let data; +let editor; +let versionid; +let language = 'json'; + +let monacoUrl = chrome.runtime.getURL('/') + 'js/monaco/vs'; +require.config({ + paths: { + 'vs': monacoUrl + } +}); + +const params = new URLSearchParams(window.location.search); +let setting = params.get('setting') || "slashsswitches"; +setting = ["slashsswitches","slashcommands","monacooptions"].includes(setting) ? setting : "slashsswitches"; + +let theme = "vs-dark"; +let title = "Settings Editor - " + setting; + +document.title = title; +document.getElementById('title').innerText = title; +require(['vs/editor/editor.main'], () => { + + editor = monaco.editor.create(document.getElementById('container'), { + automaticLayout: true, + language: language, + theme: theme, + wordWrap: "on", + colorDecorators: true, + "bracketPairColorization.enabled": true + }); + + addActions(editor); + + getFromSyncStorageGlobal("snusettings", function (data) { + let snusettings = data; + editor.setValue(snusettings[setting]); + setTimeout(() => { + editor.getAction('editor.action.formatDocument').run(); + editor.focus(); + }, 100); + versionid = getEditor().getModel().getAlternativeVersionId(); + }) + +}); + + +document.querySelector('button#save').addEventListener('click', e => { + saveSettings(); +}); + + + +function addActions(editor) { + + const blockContext = "editorTextFocus && !suggestWidgetVisible && !renameInputVisible && !inSnippetMode && !quickFixWidgetVisible"; + editor.addAction({ + id: "updateRecord", + label: "Save", + keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS], + contextMenuGroupId: "2_execution", + precondition: blockContext, + run: () => { + saveSettings(); + }, + }); + + editor.addAction({ + id: "google", + label: "Search Google", + contextMenuGroupId: "2_execution", + precondition: "editorHasSelection", + run: (editor) => { + let selection = getEditor().getModel().getValueInRange(editor.getSelection()); + window.open('https://www.google.com/search?q=' + selection); + } + }) + +} + + +function getEditor() { + return (typeof editor.getValue !== 'undefined') ? + editor : editor.getModifiedEditor(); +} + + + +window.onbeforeunload = function (e) { + if (versionid == getEditor().getModel().getAlternativeVersionId()) return null + e = e || window.event; + return 'Closing tab will loose unsaved work, continue?'; +}; + + + + +//get an instance independent sync parameter +function getFromSyncStorageGlobal(theName, callback) { + chrome.storage.sync.get(theName, function (resSync) { + var dataSync = resSync[theName]; + + if (typeof dataSync !== 'object'){ //only objects can become large and merged. + callback(dataSync); + return; + } + + getFromChromeStorageGlobal(theName,function (resLocal) { + var objLocal = resLocal || {}; + var objMerged = { ...dataSync, ...objLocal}; + callback(objMerged); + }); + }); +} + +//get an instance independent global parameter +function getFromChromeStorageGlobal(theName, callback) { + chrome.storage.local.get(theName, function (result) { + callback(result[theName]); + }); +} + +function saveSettings() { + + const jsonSetting = JSON.parse(editor.getValue()); + const minifiedSetting = JSON.stringify(jsonSetting); + + getFromSyncStorageGlobal("snusettings", function (data) { //get the current settings in case it was edited in the popup + snusettingsSync = data; + snusettingsSync[setting] = minifiedSetting; + + snusettings = {}; + + Object.keys(snusettingsSync).forEach(key => { + if (key.length >= 5000) { //overflow to local storage #204 + snusettings[key] = '' + snusettingsSync[key]; + delete snusettingsSync[key]; + } + }); + + setToChromeSyncStorageGlobal("snusettings", snusettingsSync); + setToChromeStorageGlobal("snusettings", snusettings); + + document.querySelector('#response').innerHTML = `Saved: ${new Date().toLocaleTimeString()}`; + versionid = getEditor().getModel().getAlternativeVersionId(); + + }) + +} + +//set an instance independent sync parameter +function setToChromeSyncStorageGlobal(theName, theValue) { + var myobj = {}; + myobj[theName] = theValue; + chrome.storage.sync.set(myobj, function () { + + }); +} + +//set an instance independent parameter +function setToChromeStorageGlobal(theName, theValue) { + //console.log(theName, theValue) + var myobj = {}; + myobj[theName] = theValue; + chrome.storage.local.set(myobj, function () { + }); +} diff --git a/popup.html b/popup.html index 0b2afae..2081b93 100644 --- a/popup.html +++ b/popup.html @@ -405,7 +405,7 @@
Settings (Reload browser after changing settings to take affect)
Slashcommands:
-

Slash Commands
- Advanced, please use the Slashcommands tab to manage custom commands, or doubleclick textarea to remove readonly. + Advanced, please use the Slashcommands tab to manage custom commands, or doubleclick textarea to open editor. - Advanced, custom switches . doubleclick textarea to remove readonly. + Advanced, custom switches . doubleclick textarea to open editor. diff --git a/popup.js b/popup.js index cc240b3..7f2fbff 100644 --- a/popup.js +++ b/popup.js @@ -397,7 +397,7 @@ function setBrowserVariables(obj) { }); $('.snu-setting').change(function () { - setSettings(); + saveSettings(); }); $('.snu-instance-setting').change(function () { @@ -441,7 +441,14 @@ function setBrowserVariables(obj) { }); $('#slashcommands, #slashsswitches').on('dblclick',function(){ - $(this).prop('readonly',''); + + var extensionUrl = chrome.runtime.getURL("settingeditor.html"); + var createObj = { + 'url': extensionUrl + "?setting=" + this.id, + 'active': true + } + chrome.tabs.create(createObj); + }) $('#iconallowbadge').on('change',function(){ @@ -608,7 +615,7 @@ function getSettings(callback) { }) } -function setSettings() { +function saveSettings() { var snusettingsSync = {}; var snusettings = {} $('.snu-setting').each(function (index, item) { @@ -1347,7 +1354,7 @@ function getSlashcommands() { if (!confirm("Delete command " + cmd + "?")) return; delete objCustomCommands[cmd]; $('#slashcommands').val(JSON.stringify(objCustomCommands)); - setSettings(); + saveSettings(); getSlashcommands(); }); @@ -1401,7 +1408,7 @@ function getSlashcommands() { response => { }); }); - setSettings(); + saveSettings(); getSlashcommands(); chrome.runtime.sendMessage({ "event" : "initializecontextmenus"}); diff --git a/settingeditor.html b/settingeditor.html new file mode 100644 index 0000000..2865c93 --- /dev/null +++ b/settingeditor.html @@ -0,0 +1,43 @@ + + + + + + + Code Editor + + + + + + + +
+ +
+
+
Do not modify settings in popup while editing here.
+ +
+
+ + + + + \ No newline at end of file