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>
<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“。
发布于 2020-06-12 19:20:20
你不能在后台脚本中这样做。它必须在一个内容脚本中完成。
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"
]
}
]
}https://stackoverflow.com/questions/62348183
复制相似问题