Skip to content

Instantly share code, notes, and snippets.

@emlyn
Last active April 18, 2023 17:03
Show Gist options
  • Save emlyn/0dccc7f1093e1c64758745e73c4befa4 to your computer and use it in GitHub Desktop.
Save emlyn/0dccc7f1093e1c64758745e73c4befa4 to your computer and use it in GitHub Desktop.
Synapse control
// ==UserScript==
// @name Notebook Control-Run
// @description Make Ctrl+Enter run the current notebook cell (without jumping to the next one) in Synapse and Azure ML
// @downloadURL https://gist.github.com/emlyn/0dccc7f1093e1c64758745e73c4befa4/raw/notebook_control.js
// @updateURL https://gist.github.com/emlyn/0dccc7f1093e1c64758745e73c4befa4/raw/notebook_control.js
// @namespace https://gist.github.com/emlyn
// @version 0.4
// @author Emlyn Corrin
// @match https://web.azuresynapse.net/*
// @match https://ml.azure.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const KEY_ENTER = 13;
const onCtrlEnter = function() {
console.log("#NCR Ctrl+Enter pressed!");
var el = document.activeElement;
console.log(el);
if (el.tagName != 'TEXTAREA') {
console.log('#NCR Not a text area');
return;
}
while (el && !el.querySelector('button.cell-execute-button.ms-Button--command')) {
el = el.parentElement;
}
const buttons = el && el.querySelectorAll('button.cell-execute-button.ms-Button--command');
if (!buttons || buttons.length < 1) {
console.error("#NCR Couldn't find the button.");
} else if (buttons.length > 1) {
console.error("#NCR Too many buttons:", buttons);
} else {
console.log("#NCR Found a button, let's click it!", buttons[0]);
buttons[0].click();
}
}
const onKeydown = function(evt) {
// Use https://keycode.info/ to get keys
if (evt.keyCode == KEY_ENTER && evt.ctrlKey && !evt.shiftKey && !evt.altKey && !evt.metaKey && !evt.repeat) {
onCtrlEnter();
}
}
const installIt = function() {
if (document.querySelector('.cell-container')) {
console.log('#NCR Installing listener');
document.addEventListener('keydown', onKeydown, true);
} else {
console.log('#NCR No cell container, waiting');
setTimeout(installIt, 1000);
}
}
console.log('#NCR Starting');
setTimeout(installIt, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment