Command Palette AutomationAnywhere

Enhance Automation Anywhere with a Command Palette

当前为 2023-10-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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");
    }
})();