我有一个使用chrome控制台运行的js代码,但现在我想扩展使用这个代码,我用2个按钮制作了一个简单的html表单,我想要的 当我点击按钮时,js代码将像我在chrome console中一样运行。
我使用此代码调用了按钮
$(function(){
$('#rjct').click(function(){
var buttons = document.getElementsByClassName('_42ft _4jy0 _4jy3 _517h _51sy');
for(var i = 0; i <= buttons.length; i++)
buttons[i].click();
})
});
其中rjct是按钮的id名称。
这是扩展的形象 enter image description here
我像这样编辑了manifest.json enter image description here
答案 0 :(得分:0)
简而言之,您需要做的是设置import subprocess
import sys
# Execute another Python scipt as a separate process and echo its output.
kwargs = dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True)
args = [sys.executable, 'second_script.py']
with subprocess.Popen(args, **kwargs).stdout as output:
for line in output:
print(line, end='') # Process the output...
文件以使content_scripts指向您的文件,并标记您希望扩展程序在哪些网站上运行。例如,如果您希望您的扩展程序在stackoverflow.com上运行,您可以执行以下操作:
manifest.json
然后你会把你的代码放在 "content_scripts": [
{
"matches": [
"*://stackoverflow.com/*",
"*://*.stackoverflow.com/*"
],
"js": ["my_bundle.js"],
"run_at": "document_idle"
}
],
。