使用JavaScript删除两个注释标记之间的所有内容

使用JavaScript删除两个注释标记之间的所有内容,javascript,jquery,ads,removechild,adblock,Javascript,Jquery,Ads,Removechild,Adblock,如何删除两个标记之间的所有内容,而这些内容不在标准标记中 <!--googleoff: index--> some codes and content here... <!--googleon: index--> 这里有一些代码和内容。。。 这是一个显示在一个站点上的广告,我想通过用户JS阻止并删除浏览器中的主题。这些是评论节点,而不是标签。最好的办法可能是识别父母,然后在孩子之间循环;见评论: // Assuming a single parent let

如何删除两个标记之间的所有内容,而这些内容不在标准标记中

<!--googleoff: index-->
    some codes and content here...
<!--googleon: index-->

这里有一些代码和内容。。。

这是一个显示在一个站点上的广告,我想通过用户JS阻止并删除浏览器中的主题。这些是评论节点,而不是标签。最好的办法可能是识别父母,然后在孩子之间循环;见评论:

// Assuming a single parent
let parent = document.querySelector(".stuff");
if (parent) {
    // Uncomment if you want to see nodes before the change
    // showNodes("before", parent);
    let removing = false;
    let child = parent.firstChild;
    let next = null;
    // While we still have child elements to process...
    while (child) {
        // If we're already removing, remember that
        let removeThis = removing;
        // Before we remove anything, identify the next child to visit
        next = child.nextSibling;
        // Is this a comment node?
        if (child.nodeType === Node.COMMENT_NODE) {
            if (child.nodeValue.includes("googleoff: index")) {
                // It's the node that tells us to start removing:
                // Turn on our flag and also remove this node
                removing = true;
                removeThis = true;
            } else if (child.nodeValue.includes("googleon: index")) {
                // It's the node that tells us to stop removing:
                // Turn off our flag, but do remove this node
                removing = false;
                removeThis = true;
            }
        }
        if (removeThis) {
            // This is either stuff in-between the two comment nodes
            // or one of the comment nodes; either way, remove it
            parent.removeChild(child);
        }

        // Move on to next child
        child = next;
    }
    // Uncomment if you want to see nodes before the change
    // showNodes("after", parent);
}
实例:

//短暂的延迟,以便您可以看到它的发生
设置超时(()=>{
//假设单亲
让parent=document.querySelector(“.stuff”);
如果(家长){
//如果要在更改之前查看节点,请取消注释
//showNodes(“之前”,父节点);
让删除=假;
让child=parent.firstChild;
设next=null;
//虽然我们还有子元素要处理。。。
while(儿童){
//如果我们已经移除了,记住这一点
让我们移除它=移除;
//在我们删除任何内容之前,请确定要访问的下一个孩子
下一步=child.nextSibling;
//这是评论节点吗?
if(child.nodeType==Node.COMMENT\u Node){
if(child.nodeValue.includes(“googleoff:index”)){
//该节点告诉我们开始删除:
//打开我们的标志并删除此节点
删除=真;
removeThis=正确;
}else if(child.nodeValue.includes(“googleon:index”)){
//该节点告诉我们停止删除:
//关闭我们的标志,但一定要删除此节点
删除=假;
removeThis=正确;
}
}
如果(移除此项){
//这是两个注释节点之间的内容
//或其中一个注释节点;无论哪种方式,都将其删除
父母。removeChild(子女);
}
//转到下一个孩子
孩子=下一个;
}
//如果要在更改之前查看节点,请取消注释
//showNodes(“之后”,父节点);
}
}, 800);
函数showNodes(标签、父节点){
控制台日志(标签);
for(让child=parent.firstChild;child;child=child.nextSibling){
log(child.nodeType,child.nodeValue);
}
}

只是一些不相关的内容
这是父元素
这里有一些代码和内容。。。

该代码的容器是什么?
,还是什么?