使用跨度 ID 和文本的 Greasemonkey 关闭选项卡

问题描述

我有这个脚本,如果它在页面上找到某个元素,它会关闭一个选项卡:

// ==UserScript==
// @name        Name
// @namespace   bbb
// @match       https://example.com
// @include     about:config
// @version     1
// @grant       none
// ==/UserScript==



var intv = setInterval(function() {
 
if (/(container)|(mediumheight)/i.test (document.body.innerHTML) )

{
    window.close()
}
 
    },1000);

如果它发现这个,我如何让它关闭页面

<span id="some">0</span>

但它必须同时检查 id (some) 和数字 (0)。两者都必须在页面上才能触发脚本。

如果只是 id(一些)我可以做到,但我需要两者都为 true 才能触发脚本。

有人可以帮忙吗?谢谢

解决方法

<span id="some">0</span> 

但它必须同时检查 id(一些)和数字(0)。两者都必须在页面上才能触发脚本。

以下是如何检查它的示例:

const sp = document.querySelector('#some'); // find id (some)
if (sp && sp.textContent === '0') {
 // run the function
}