Skip to content

Instantly share code, notes, and snippets.

@m0wn1ka
Last active May 27, 2024 10:42
Show Gist options
  • Save m0wn1ka/a64ba52204b846bd87b24d3586420f7c to your computer and use it in GitHub Desktop.
Save m0wn1ka/a64ba52204b846bd87b24d3586420f7c to your computer and use it in GitHub Desktop.
this code is useful to close the popups while reading content in scalar acdemay ,this uses mutation observer to observe changes in dom

code

var targetNode = document.body
const config = { childList: true ,characterData: true, subtree: true, attributes: true,};// callback function
const callback = function (mutationsList, observer) { 
let node1 = document.getElementsByClassName("Tappable-module_root__N7ll5 absolute crt-popup_close_button__ZhQDT");
node1[0].click()
let node2=document.getElementsByClassName("exit-intent_close_icon__lxzbB")
node2[0].click()
console.log('Changes Detected');
};// Create observer instance
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);

reference links

need of this code

  • when opening sites of this type a pop up appers periodically blocking reading content
  • without we manually closing these windows each time and without periodically checking them manually mutation observer is used

overview

  • we observe the documents body
  • we write a call back function in which we extract the needed nodes and click the necessary buttons to close them
  • we make a mutation observer object-observer
  • and we observe the target node with configuration

how to use

  • just paste this code in console when openign the sites of scalar academy

output

  • there wont be any periodic popups blocking the content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment