Chrome扩展程序javascript [英] Chrome extension javascript
本文介绍了Chrome扩展程序javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
https://i.stack.imgur.com/S0u6W.png
对于某些情况,请查看提供的图像,
For some context look at the image provided,
网站每隔几秒钟会自动显示三种类型的框:嗨",你好"和嘿". 您可以单击该框,它将被添加到右侧.
There are 3 type of box that appears in the site automatically every few seconds, "Hi", "Hello" and "Hey". You can click the box and it will be added to the right side.
<div class="h-240 rounded relative bg-gray-400 cursor-pointer hover:bg-gray-300 transition duration-75 ease-in-out">
<span class="inline-block ml-10 text-gray-200"> (Hello)</span>
</div>
<div class="h-240 rounded relative bg-gray-400 cursor-pointer hover:bg-gray-300 transition duration-75 ease-in-out">
<span class="inline-block ml-10 text-gray-200"> (Hi)</span>
<div class="h-240 rounded relative bg-gray-400 cursor-pointer hover:bg-gray-300 transition duration-75 ease-in-out">
<span class="inline-block ml-10 text-gray-200"> (Hey)</span>
</div>
<div class="h-240 rounded relative bg-gray-400 cursor-pointer hover:bg-gray-300 transition duration-75 ease-in-out">
<span class="inline-block ml-10 text-gray-200"> (Hey)</span>
</div>
<div class="h-240 rounded relative bg-gray-400 cursor-pointer hover:bg-gray-300 transition duration-75 ease-in-out">
<span class="inline-block ml-10 text-gray-200"> (Hello)</span>
</div>
如何制作内容脚本以自动单击带有"Hello"的任何框.
How do I make a content script to automatically click any box with "Hello".
推荐答案
您不能在后台脚本中执行此操作.它必须在内容脚本中完成.
You can't do this in a background script. It has to be done in a content script.
script.js
script.js
setInterval(() => {
document.querySelectorAll('div').forEach(div => {
div.getElementsByTagName('span')[0].innerHTML.includes('Hello') && div.click();
});
}, 1000);
manifest.json
manifest.json
{
"manifest_version": 2,
"name": "Hello Box Clicker",
"permissions": [
"activeTab"
],
"version": "0.0.0.1",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"script.js"
]
}
]
}
这篇关于Chrome扩展程序javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文