A script works on all pages with query strings but not on these without

I wrote the following script to hide some divs that appears in some Facebook pages. I run it with Tampermonkey on Google Chrome:

(function fbPurity() {
let fF = document.querySelector("._1uh-");
    fF.style.display = "none";
}());

// everythingGeneral:
document.querySelectorAll("#leftCol, .fbChatSidebar").forEach(function(element) {
    element.style.visibility = "hidden";
});

// myWall:
document.querySelectorAll("#stream_pagelet").forEach(function(element) {
    element.style.visibility = "hidden";

});

The script works fine on all pages which have query strings in their URL, but doesn’t work on all pages without.

This is extremely problematic as Facebook creates non-query-string-containing (NQSC) copies of almost each page; For example, if I click on my profile link with a left mouse click I get a NQSC version without the script’s effect and if I click it with a middle click (mosule wheel click) I get a query-string-containing version with the script’s effect.

I am very new to Javascript and can’t explain this behavior.

It’s just looking for a class and hiding it. For whatever reason that class is different for you.

The class is always there for me, though. I can’t find any screens where my name is there and that class isn’t on the wrapper.

I’m not sure I understood your reply but in any case I’ve updated the code with the longer, real code I used. Can you please try again both versions of pages with the updated code?

Still works for me, but I didn’t use Tampermonkey. It’s likely caused​ by Tampermonkey running a page load, but FB loads once and page transitions are likely handled by their JS, which means your script is never told to run again.

But I’m just totally taking a stab in the dark here.

This is extremely problematic as Facebook creates non-query-string-containing (NQSC) copies of almost each page

Anything in the DOM can be queried.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.