Skip to content

Instantly share code, notes, and snippets.

@argf013
Last active February 28, 2025 08:53
Show Gist options
  • Save argf013/588e0fb22aacf2898a8855996f05b00a to your computer and use it in GitHub Desktop.
Save argf013/588e0fb22aacf2898a8855996f05b00a to your computer and use it in GitHub Desktop.
Script Shortcut Aris
let isListenerActive = true;
// Helper function to find and click an anchor element
function clickAnchorElements(elements) {
elements.forEach((element) => element.click());
}
// Helper function to find and click elements by class name
function clickElementsByClass(elements, className) {
elements.forEach((element) => {
if (element.querySelectorAll) {
element.querySelectorAll(`.${className}`).forEach((el) => el.click());
}
});
}
// Function to click the first matching link with specific text content
function clickLinkByText(links, text) {
let clicked = false;
links.forEach((link) => {
if (!clicked && link.textContent.trim() === text) {
link.click();
clicked = true;
}
});
}
// Function to handle element click by id and aria-label
function handleElementByIdOrAttribute(id, ariaLabel) {
const element = document.querySelector(`#${id}[aria-label="${ariaLabel}"]`);
if (element) {
element.click();
} else {
console.error(
`Element with id="${id}" and aria-label="${ariaLabel}" not found.`
);
}
}
// Main keydown listener function
function mainKeydownListener(event) {
if (!isListenerActive) return; // Ignore if listener is inactive
const links = document.querySelectorAll('a.link');
switch (event.key.toLowerCase()) {
case 'e':
// First show all inline edit actions
document
.querySelectorAll('.inlineEdit-actions')
.forEach((el) => (el.style.display = 'block'));
// Click the inline edit action button
document.getElementById('gwt-debug-inlineEdit-action-btn').click();
// Find and click element with aria-label="Place attribute"
document.querySelector('[aria-label="Place attribute"]').click();
break;
case 'q':
if (event.altKey) clickLinkByText(links, 'Organizational unit lane');
break;
case 'c':
handleKeyPress('Control', 'symbolsPanel-symbolsRow-icon-name-wrapper');
break;
case 'x':
handleKeyPress('Risk', 'symbolsPanel-symbolsRow-icon-name-wrapper');
break;
case 'r':
if (event.altKey) clickLinkByText(links, 'Role lane');
else clickLinkByText(links, 'Lane to the right');
break;
case 'l':
if (event.altKey) handleButtonPress('Layout');
else clickLinkByText(links, 'Lane to the left');
break;
case 'd':
handleKeyPress('Document', 'symbolsPanel-symbolsRow-icon-name-wrapper');
break;
case 'i':
handleButtonPress('Create connection');
break;
case 'h':
handleButtonPress('Horizontal space');
break;
case 'v':
handleButtonPress('Vertical space');
break;
case 'a':
if (event.altKey) clickLinkByText(links, 'Application system type lane');
// Open attribute placement toolbar
else if (event.shiftKey) {
const element = document.getElementById(
'gwt-debug-attributeplacement-toolbar'
);
if (element) {
let startElement = document.querySelector(
'a.link[data-target="#gwt-uid-251"]'
);
if (startElement) {
startElement.click();
}
element.className = 'btn-group open active';
element.setAttribute('aria-expanded', 'true');
element.setAttribute('expanded', 'true');
}
} else
handleKeyPress(
'Application system type',
'symbolsPanel-symbolsRow-icon-name-wrapper'
);
break;
case 't':
handleKeyPress('Task', 'symbolsPanel-symbolsRow-icon-name-wrapper');
break;
case 'g':
handleKeyPress('Gateway', 'symbolsPanel-symbolsRow-icon-name-wrapper');
break;
case '|':
case '\\':
clickLinkByText(links, 'Attribute placement');
break;
}
}
// Activate or deactivate the event listener
document.addEventListener('keydown', (event) => {
if (event.ctrlKey && event.key === ']') {
isListenerActive = false;
console.log('Event listener deactivated.');
} else if (event.ctrlKey && event.key === '[') {
isListenerActive = true;
console.log('Event listener activated.');
}
});
// Main event listener for keydown
document.addEventListener('keydown', mainKeydownListener);
// Handle element click by title and class name
function handleKeyPress(title, className, isAnchor = false) {
const elements = document.querySelectorAll(`[title="${title}"]`);
if (!elements.length) {
console.error(`Element with title="${title}" not found.`);
return;
}
isAnchor
? clickAnchorElements(elements)
: clickElementsByClass(elements, className);
}
// Handle button click by aria-label
function handleButtonPress(ariaLabel) {
const button = document.querySelector(`[aria-label="${ariaLabel}"]`);
if (button) {
button.click();
} else {
console.error(`Button with aria-label="${ariaLabel}" not found.`);
}
}
@argf013
Copy link
Author

argf013 commented Dec 17, 2024

How to Use This Script for Shortcuts

  1. Open ARIS:

    • Launch the ARIS application installed on your device.
  2. Open Developer Tools (F12):

    • Press F12 on your keyboard to open the Developer Tools in your browser.
    • Alternatively, right-click on the ARIS page and select "Inspect" or "Inspect Element".
  3. Go to the Console Tab:

    • In Developer Tools, select the "Console" tab. Here, you will see logs and can enter code.
  4. Copy and Paste the Code:

    • Copy the provided script (or the relevant section) and paste it into the console.
    • In some browsers, when pasting code for the first time, you may need to allow pasting.
    • If prompted, type allow pasting and press Enter before proceeding.
  5. Press Enter:

    • After pasting the code, press Enter to execute the script.
  6. Use the Keyboard Shortcuts:

    • Once activated, you can use the following keyboard shortcuts to perform actions in ARIS:

Keyboard Shortcuts Documentation

Basic Controls

  • Ctrl + [ - Activate event listener
  • Ctrl + ] - Deactivate event listener

Lane Operations

  • Alt + Q - Add Organizational unit lane
  • Alt + R - Add Role lane
  • Alt + A - Add Application system type lane
  • R - Add Lane to the right
  • L - Add Lane to the left

Element Creation

  • C - Add Control element
  • X - Add Risk element
  • D - Add Document element
  • A - Add Application system type (Hold Shift for Attribute Placement Toolbar)
  • T - Add Task element
  • G - Add Gateway element
  • E - Open Inline Edit Actions and Place Attribute

Layout & Connections

  • I - Create connection
  • H - Add Horizontal space
  • V - Add Vertical space
  • | or \ - Open Attribute placement toolbar
  • Alt + L - Open Layout menu

Notes

  • All shortcuts are case-insensitive.
  • Shortcuts only work when the event listener is active.
  • Use Ctrl + [ to activate and Ctrl + ] to deactivate the shortcuts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment