小编kkm*_*our的帖子

使用executeScript()将弹出窗口中弹出的数据与popup注入的内容脚本进行通信

我的Chrome扩展程序弹出窗口中有一个文本区域和一个按钮.我希望用户在文本区域中输入所需的文本.然后,一旦他们点击该按钮,它将注入一个内容脚本,以更改当前页面上的字段<textarea class="comments">文本,该文本必须是用户<textarea>在Chrome扩展程序弹出窗口中输入的文本.

我的问题是,我怎样才能从文本<textarea>中我popup.html,并从它传递popup.js的内容脚本?

这就是我目前所拥有的:

popup.html:

<!doctype html>  
<html>  
    <head><title>activity</title></head>  
<body>  
    <button id="clickactivity3">N/A</button> 
    <textarea rows="4" cols="10" id="comments" placeholder="N/A Reason..."></textarea>
    <script src="popup.js"></script> 
</body>
</html>  
Run Code Online (Sandbox Code Playgroud)

popup.js:

function injectTheScript3() {
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        // query the active tab, which will be only one tab
        //and inject the script in it
        chrome.tabs.executeScript(tabs[0].id, {file: "content_script3.js"});
    });
}

document.getElementById('clickactivity3').addEventListener('click', injectTheScript3);
Run Code Online (Sandbox Code Playgroud)

content_script3:

//returns a node list which is good
var objSelectComments = …
Run Code Online (Sandbox Code Playgroud)

html javascript google-chrome-extension firefox-addon-webextensions

7
推荐指数
1
解决办法
3256
查看次数

可以为不同的功能提供多个内容脚本吗?

我是新手,但我正在尝试创建一个chrome扩展来操作网页上的DOM.目前,我有两个按钮,每个按钮将执行不同的任务.以下是否有意义?此外,如果我有多个内容脚本,我如何将它们都添加到manifest.json中

popup.js:

function injectTheScript() {
        chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        // query the active tab, which will be only one tab
        //and inject the script in it
        chrome.tabs.executeScript(tabs[0].id, {file: "content_script.js"});
    });
}
function injectTheScript1() {
        chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        // query the active tab, which will be only one tab
        //and inject the script in it
        chrome.tabs.executeScript(tabs[0].id, {file: "content_script1.js"});
    });
}

document.getElementById('clickactivity').addEventListener('click', injectTheScript);
document.getElementById('clickactivity1').addEventListener('click', injectTheScript1);
Run Code Online (Sandbox Code Playgroud)

html javascript google-chrome-extension

3
推荐指数
1
解决办法
2947
查看次数

When I submit form, I am getting Uncaught RangeError: Maximum call stack size exceeded

I am trying to POST a form to my testexe.php using an Ajax request, however, whenever I add the data type gateway in my Ajax request I get the Uncaught RangeError: Maximum call stack size exceeded error message. Is there something I am doing wrong here? I am able to get the button value successfully but not sure why gateway is giving me problems.

<!DOCTYPE html>
<html>
<head>
<style>
    .box1 {
        width: 450px;
        border: 2px solid black;
        margin: 0;
        display: …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax jquery

2
推荐指数
1
解决办法
2473
查看次数

docker-py 在生成器挂起时读取容器日志

我正在使用docker-py将容器日志作为流读取。通过将stream标志设置为True文档中所示。基本上,我正在迭代所有容器并作为生成器读取它们的容器日志并将其写入文件,如下所示:

for service in service_names:
    dkg = self.container.logs(service, stream=True)
    with open(path, 'wb') as output_file:
        try:
            while True:
                line = next(dkg).decode("utf-8")
                print('line is: ' + str(line))
                if not line or "\n" not in line:  # none of these work
                    print('Breaking...')
                    break
                output_file.write(str(line.strip()))

        except Exception as exc:                  # nor this
            print('an exception occurred: ' + str(exc))
Run Code Online (Sandbox Code Playgroud)

但是,它只读取第一个服务并挂在文件末尾。它不会跳出循环,也不会引发异常(例如 StopIteration 异常)。根据文档,如果stream=True它应该返回一个生成器,我打印出了生成器类型,它显示为 a,docker.types.daemon.CancellableStream所以如果我们到达容器日志生成器的末尾并调用,它不会遵循传统的 python 生成器和异常。下一个()。

正如你所看到的,我尝试检查 eol 是否为假或包含换行符,甚至看看它是否会捕获任何类型的异常,但没有运气。我还有别的办法吗。确定它是否到达服务流的末尾并跳出循环while并继续编写下一个服务?我想使用流的原因是因为大量数据导致我的系统内存不足,所以我更喜欢使用生成器。

generator python-3.x docker dockerpy

2
推荐指数
1
解决办法
3319
查看次数

期望脚本来处理 RSA 指纹密钥

我试图让我的期望脚本更加健壮,并能够处理更多情况以更加自动化。目前我的脚本工作正常,但是,有时我会被要求将 RSA 密钥添加到 known_hosts,我希望它一直默认为 yes。我的服务器并不总是要求提供密钥,一旦添加,一段时间后它不会询问,直到您删除密钥或切换网关。在线查看后,我尝试在我的工作代码中添加此(注释代码),并在添加后说,如果已经添加了 RSA 密钥,它会在密码输入屏幕上停止。

所以我的问题是,有没有办法处理这种情况,假设已经添加了 RSA,它只会跳到密码行?

[user@gateway my_direcotry]$ cat loadItTest
#!/usr/bin/expect -f

set timeout 600
set user root
set host 1.1.1.1
set pass pass


spawn ssh $user@$host

#expect {
#    -re "RSA key fingerprint" {send "yes\r"}
#}

expect "assword:"
send "$pass\r"
expect "#"
Run Code Online (Sandbox Code Playgroud)

示例输出:

[root@gateway my_direcotry]# loadItTest
spawn ssh root@1.1.1.1
root@1.1.1.1's password:
Run Code Online (Sandbox Code Playgroud)

linux rsa expect

1
推荐指数
1
解决办法
3090
查看次数