Advertisement
ikai2

move afterpay to afterpay block

May 24th, 2023
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Function to move the Afterpay on-site message to the target div
  2. function moveAfterpayMessage() {
  3.   var afterpayMessage = document.querySelector('.afterpay-placement');
  4.   var targetDiv = document.querySelector('#afterpay');
  5.  
  6.   if (afterpayMessage && targetDiv) {
  7.     targetDiv.appendChild(afterpayMessage);
  8.   }
  9. }
  10.  
  11. // Create a MutationObserver to watch for changes in the DOM
  12. var observer = new MutationObserver(function(mutationsList) {
  13.   for (var mutation of mutationsList) {
  14.     if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  15.       // Check if the Afterpay on-site message is added to the DOM
  16.       var addedNodes = Array.from(mutation.addedNodes);
  17.       var afterpayMessageAdded = addedNodes.some(function(node) {
  18.         return node.classList && node.classList.contains('afterpay-placement');
  19.       });
  20.      
  21.       if (afterpayMessageAdded) {
  22.         moveAfterpayMessage();
  23.       }
  24.     }
  25.   }
  26. });
  27.  
  28. // Start observing changes in the DOM
  29. observer.observe(document.body, { childList: true, subtree: true });
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement