Is it possible to hide a custom view if the query result is empty?

It seems that I got the concept of advanced queries pretty quickly and I have a bunch of them now, also with customized views. But some of them are empty, like queries for open tasks when I have done everything and then the header shows together with “No matched results”.
Is there a way to hide the whole block if the query has not returned any results?

Or maybe just modify the output message? Also looking for a similar solution.

A drastic way (use with caution) would be to add this code inside file custom.js:

function processNoResults(block) {
    const classList = block.classList;
    if (classList.contains("hidden")) return;

    function hideNoResults(div) {
        if (div.textContent === "No matched result") classList.add("hidden");
    }
    block.querySelectorAll(".custom-query-results .text-sm").forEach(hideNoResults);
}

const noResultsObserver = new MutationObserver(() => {
    document.querySelectorAll(".ls-block").forEach(processNoResults);
});

noResultsObserver.observe(document.getElementById("main-content-container"), {
    attributes: true,
    subtree: true,
    attributeFilter: ["class"],
});

Maybe a bit too drastic for my taste yet :smiley:

css: .custom-query-results .opacity-90 { display: none;}

A little less drastic, but not as targeted. Opacity-90 is applied to the message, so only shows up when empty.

Could use :has to target the parent element/block.

Oh, I’ll try that! Thanks!