Command Palette AutomationAnywhere

Enhance Automation Anywhere with a Command Palette

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

// ==UserScript==
// @name         Command Palette AutomationAnywhere
// @namespace    http://tampermonkey.net/
// @version      0.1
// @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';

    // main function
    document.addEventListener('keydown', function(e) {
        if (e.ctrlKey && e.code === 'KeyP') {
            (function() {
                var userInput = prompt("Enter a command (a, adv, v, duv) or 'help' for a list of commands:", "");
                switch (userInput) {
                    case "a":
                        addAction();
                        break;
                    case "adv":
                        addVariable();
                        break;
                    case "v":
                        showVariables();
                        break;
                    case "duv":
                        deleteUnusedVariables();
                        break;
                    default:
                        showHelp();
                        break;
                }
            })();
            e.preventDefault(); // This will prevent the default action for the Ctrl+P key combination
        }
    });

    // a
    function addAction() {
        document.querySelector("div.jsx-1665687331:nth-child(2) > div:nth-child(1) > header:nth-child(1) > div:nth-child(1) > button:nth-child(1)").click();
        document.querySelector(".rio-focus--border-radius_pill").click();
    }

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

        try {
            document.querySelector(".rio-focus--border-radius_pill").click();
        } catch (error) {}

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

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


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

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

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