Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MutationObserver to detect changes within the answer #6

Open
corelgott opened this issue Jan 2, 2023 · 1 comment
Open

Use MutationObserver to detect changes within the answer #6

corelgott opened this issue Jan 2, 2023 · 1 comment

Comments

@corelgott
Copy link

corelgott commented Jan 2, 2023

Currently a loop is used to detect changes within the response of chat gpt. It would be more efficient to register a mutation-observer to track changes. The code is courtesy of Chat-GPT ;-)

// Select target element
var target = document.getElementById('my-element');

// Set MutationObserver options
var options = {
  characterData: true,
  childList: true,
  subtree: true
};

// Create MutationObserver instance
var observer = new MutationObserver(function(mutations) {
  mutations.forEach(function(mutation) {
    // Was the element's content changed?
    if (mutation.type == 'characterData') {
      console.log('Element content changed!');
    }
  });
});

// Register observer
observer.observe(target, options);
@RetricSu
Copy link
Owner

RetricSu commented Jan 5, 2023

however, this does not work I don't know why. I have tried impl observer in the first place but switched to the simple loop method... if you are interested, can you explore such an idea and submit a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants