Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chrome扩展(内容脚本)-在字符串中的特定位置添加按钮_Javascript_Jquery_Google Chrome - Fatal编程技术网

Javascript Chrome扩展(内容脚本)-在字符串中的特定位置添加按钮

Javascript Chrome扩展(内容脚本)-在字符串中的特定位置添加按钮,javascript,jquery,google-chrome,Javascript,Jquery,Google Chrome,因此,我正在创建一个Chrome扩展,它可以扫描当前页面中的电话号码,在找到每个电话号码后,必须创建一个点击呼叫按钮 当前代码: var number = foobar, queue = [document.body], curr; while (curr = queue.pop()) { if (!curr.textContent.match(number)) continue; for (var i = 0; i < curr.childNodes.l

因此,我正在创建一个Chrome扩展,它可以扫描当前页面中的电话号码,在找到每个电话号码后,必须创建一个点击呼叫按钮

当前代码:

var number = foobar,
    queue = [document.body],
    curr;

while (curr = queue.pop()) {
    if (!curr.textContent.match(number)) continue;
    for (var i = 0; i < curr.childNodes.length; ++i) {
        switch (curr.childNodes[i].nodeType) {
            case Node.TEXT_NODE :
                var match = curr.childNodes[i].textContent.match(number);
                if (match) {
                    if(!curr.innerHTML.includes("fa-phone-square")) {
                        var $call_button = $('<i style="margin-left: 5px;" class="fa fa-phone-square" aria-hidden="true" id="'+ match +'"></i>').click(call);
                        $(curr).append($call_button);
                    }
                    break;
                }
                break;
            case Node.ELEMENT_NODE :
                queue.push(curr.childNodes[i]);
                break;
        }
    }
}
我正在努力实现的目标:

Name: John Doe
Phone: 1234567890 [button]
Mail: example@example.com
感谢您的帮助

试试换衣服

$(curr).append($call_button);

$(curr).append($call_button);
$(curr.childNodes[i]).after($call_button);