https://i.stack.imgur.com/s0u6w.png
对于某些上下文,请查看所提供的图像,
有3种类型的框,出现在网站自动每几秒钟,“嗨”,“你好”和“嘿”。 您可以单击该框,它将被添加到右侧。
<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>
null
<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>
我如何制作一个内容脚本,自动点击任何带有“你好”的框。
你不能在背景脚本中这样做。 它必须在内容脚本中完成。
script.js
setInterval(() => {
document.querySelectorAll('div').forEach(div => {
div.getElementsByTagName('span')[0].innerHTML.includes('Hello') && div.click();
});
}, 1000);
MANIFEST.JSON
{
"manifest_version": 2,
"name": "Hello Box Clicker",
"permissions": [
"activeTab"
],
"version": "0.0.0.1",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"script.js"
]
}
]
}