Javascript 以聚焦文本输入字段为目标

Javascript 以聚焦文本输入字段为目标,javascript,html,object,Javascript,Html,Object,因此,我一直在做一个个人项目,创建一个文本扩展器扩展,这样我就可以在工作中添加我最常用的电子邮件,并且,在人们在这个论坛和其他论坛上发布的帮助下,我能够使它工作。我按Id定位一个元素,代码运行得很好 现在我需要将它应用到我在工作中用来回答这些问题的软件中,但是,我无法确定并选择正确的文本字段,因此我的快捷方式脚本也可以在其中工作。我从他们的页面中提取了代码,并将在下面发布 如果重要的话,我需要在整个过程中单击createanewmessage,并动态加载一个富文本编辑器部分。我尝试了很多可能性,

因此,我一直在做一个个人项目,创建一个文本扩展器扩展,这样我就可以在工作中添加我最常用的电子邮件,并且,在人们在这个论坛和其他论坛上发布的帮助下,我能够使它工作。我按Id定位一个元素,代码运行得很好

现在我需要将它应用到我在工作中用来回答这些问题的软件中,但是,我无法确定并选择正确的文本字段,因此我的快捷方式脚本也可以在其中工作。我从他们的页面中提取了代码,并将在下面发布

如果重要的话,我需要在整个过程中单击createanewmessage,并动态加载一个富文本编辑器部分。我尝试了很多可能性,但我无法针对所需的元素,因此我的快捷方式可以工作。你们能不能看一下,看看能不能找到我在这里遗漏的东西

这是我的工作小提琴:

这是他们的代码截图和我看到新消息框的方式:

从页面/字段提取的HTML,如果有帮助,我需要使用我的快捷方式:


function addToObject(obj, key, value, index) {

    // Create a temp object and index variable

    var i = 0;

    // Loop through the original object
    for (var prop in obj) {
        if (obj.hasOwnProperty(prop)) {

            // If the indexes match, add the new item
            if (i === index && key && value) {
                temp[key] = value;
            }

            // Add the current item in the loop to the temp obj
            temp[prop] = obj[prop];

            // Increase the count
            i++;

        }
    }

    // If no index, add to the end
    if (!index && key && value) {
        temp[key] = value;
    }

    return temp;

};


// Original object
var myShortcuts = {
    "test" : "test2 by 2",
    "rsvp" : "I am confirming it!",
    "bye1" : "good bye, you all"    
    
    
};
        
// Create new shortcuts 

function addItem() {



var shortcut = document.getElementById('addShortcut').value; 
var newString = document.getElementById('addString').value;

// Add the new shortcut to the end of the myShortcuts object
    
var addnewShortcut = addToObject(myShortcuts, shortcut, newString);





console.log(addnewShortcut);

// replace shortcut by full string in the input text field  

    var textArea = document.getElementById("newMessage");
    var timer = 0;
    var fullString = new RegExp("\\b(" + Object.keys(addnewShortcut).join("|") + ")\\b", "g");
    
     replaceShortcut = function() {
        textArea.value = textArea.value.replace(fullString, function($0, $1) {
            return addnewShortcut[$1.toLowerCase()];
        });
    }
    
    textArea.onkeydown = function() {
        clearTimeout(timer);
        timer = setTimeout(replaceShortcut, 200);

    }
    

    
}