Command Palette AutomationAnywhere

Enhance Automation Anywhere with a Command Palette

目前為 2023-10-30 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Command Palette AutomationAnywhere
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Enhance Automation Anywhere with a Command Palette
// @author       jamir-boop
// @match        *://*.my.automationanywhere.digital/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=automationanywhere.digital
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const commands = {
        a: addAction,
        adv: addVariable,
        v: showVariables,
        duv: deleteUnusedVariables,
        hd: hideDialog
    };

    document.addEventListener('keydown', function(e) {
        if (e.ctrlKey && e.code === 'KeyP') {
            const userInput = prompt("Enter a command (a, adv, v, duv) or 'help' for a list of commands:", "");
            const command = commands[userInput];
            if (command) {
                command();
            } else {
                showHelp();
            }
            e.preventDefault(); // This will prevent the default action for the Ctrl+P key combination
        }
    });


    function addAction() {
        try {
            const addButton = document.querySelector("div.jsx-1665687331:nth-child(2) > div:nth-child(1) > header:nth-child(1) > div:nth-child(1) > button:nth-child(1)");
            addButton.click();
        } catch {}
        try {
            document.querySelector('.editor-palette-search__cancel button[type="button"][tabindex="-1"]').click();
        } catch {}
    }

    function addVariable() {
        try {
            const accordion = document.querySelector("div.editor-palette__accordion:nth-child(1)");
            const addButton = accordion.querySelector("header:nth-child(1) button:nth-child(1)");
            addButton.click();
        } catch (error) {}

        try {
            const cancelButton = document.querySelector('div.editor-palette-search__cancel button');
            cancelButton.click();
        } catch (error) {}

        try {
            const createButton = document.querySelector('button[name="create"]');
            createButton.click();
        } catch (error) {}

        try {
            const confirmButton = document.querySelector("div.action-bar--theme_default:nth-child(1) > button:nth-child(2)");
            confirmButton.click();
        } catch (error) {}
    }


    function showVariables() {
        const accordion = document.querySelector("div.editor-palette__accordion:nth-child(1)");
        const addButton = accordion.querySelector("header:nth-child(1) button:nth-child(1)");
        addButton.click();
        const variablesButton = document.querySelector(".rio-focus--border-radius_pill");
        variablesButton.click();
    }

    function deleteUnusedVariables() {
        const accordion = document.querySelector("div.editor-palette__accordion:nth-child(1)");
        const addButton = accordion.querySelector("header:nth-child(1) button:nth-child(1)");
        addButton.click();
        const menuButton = document.querySelector("button.action-bar__item--is_menu:nth-child(5)");
        menuButton.click();
        const deleteButton = document.querySelector("button.rio-focus--inset_4px:nth-child(2)");
        deleteButton.click();
    }

    function hideDialog() {
        var dialogElement = document.querySelector('[role="dialog"]');
        if (dialogElement) {
            dialogElement.style.display = 'none';
        } else {
            console.error('No element found with role="dialog"');
        }

        var backdropElement = document.querySelector(".jsx-3772251890.modal__backdrop");
        if (backdropElement) {
            backdropElement.style.display = 'none';
        } else {
            console.error('No element backdrop found');
        }
    }

    function showHelp() {
        alert("List of commands:\n" +
            "a: Add Action\n" +
            "adv: Add Variable\n" +
            "v: Show Variables\n" +
            "duv: Delete Unused Variables\n" +
            "hd: Hide dialog when running bot");
    }
})();