jeudi 15 août 2019

How to get post section and comments from body element of stackoverflow?

As I understand posts and comments on StackOverflow are loaded dynamically. What should I do to get a dom element of a post of a particular question(like the one I am currently typing in), or any comments to it. I want to make it not id or class specific, since I plan to use it on other sites that use same strategy as an extension too. I have tried to use observer to see if I can find how elements are added to body:

    var observer = new MutationObserver(function(mutationList) {
        for (var mutation of mutationList) {
            for (var child of mutation.addedNodes) {
                child.style.color = '#c00';
                console.log(child)
            }
        }
    });
    observer.observe(document, {childList: true, subtree: true});

I have tried event listeners:

    document.addEventListener("DOMNodeInserted", function(e) {
      var node = e.target;
      node.css({ color : '#c00' });
      console.log(node);
    }, false);

They do not pick up any actual content, lots of other tags, but not information typed by users.

Am I doing something wrong? Any other ways are possible?




Aucun commentaire:

Enregistrer un commentaire