0

I am building a tiny Chrome extension which purpose is to hide Twitter-users I am already following from user's follower/following pages. The really simple code I wrote works perfectly with the initial DOM, but when Twitter/browser loads more users to the end of the list, I am not able to reach these added users with jQuery. So it seems that jQuery is only able to reach the original DOM, not the updated one.

So, the question is, how do I reach the updated DOM with jQuery? Currently I fetch the user elements with simple

var cells = $(".Grid-cell");

EDIT:

Here's the whole code I have in content.js:

var cells = $(".Grid-cell");

_.each(cells, function (cell) {
    var theCell = $(cell);
    var avatarLink = theCell.find("a.ProfileCard-avatarLink");
    var title = $(avatarLink).attr("title");

    if (title !== undefined) {
        var userActions = theCell.find("div.user-actions");

        if ($(userActions).hasClass("following") && $(userActions).hasClass("including") && $(userActions).hasClass("btn-group") && $(userActions).hasClass("not-muting")) {
            if (!$(userActions).hasClass("not-following")) {
                theCell.hide();
            }
        }
    }
});

I also use underscore.js...

jubakala
  • 13
  • 5
  • Check this answer https://stackoverflow.com/questions/2844565/is-there-a-javascript-jquery-dom-change-listener – rafaelcpalmeida Jun 07 '16 at 16:26
  • Please show the code which "*works perfectly*," it's likely to be simpler, easier and clearer, to add to that existing code rather than trying to create a whole new function that replicates existing functionality. – David Thomas Jun 07 '16 at 16:31
  • You need to run the script again when twitter loads new users. Your script can't access DOM elements that don't exist yet and it's not listening for an event like `DOMSubtreeModified` – bcr Jun 07 '16 at 16:50

0 Answers0