  window.addEventListener(
    "message",
    (event) => {
      if(event.origin.indexOf('qualtrics.com') > -1){
        let footer = document.querySelector('footer');

        if(footer !== null){
          footer.querySelector('.deLeqc').children[0].replaceWith(preservedContinueButton);
        }
      }
    },
    false,
  );

  window.onload = () => {
    hideNextCourseButtonLp();
    autoFSMutationObserver();
    eoqMutationObserver();
    mockMilestoneMutationObserver();
  };

  let autoFSMutationObserver = () => {
    let observer;

    let config = {
        attributes: true,
        childList: true,
        subtree: true
    };

    observer = new MutationObserver(() => {
      let fullscreenButton = document.querySelector('button[data-test="with-fullscreen-button"]');

      if(fullscreenButton){
        if(!document.querySelector('.iSRNPB')){
          setTimeout(() => {
            fullscreenButton.click();
            observer.disconnect();
            observer.observe(document, config);
          }, 500);
        }

      }
    })

    observer.observe(document, config);
  }

  function hideNextCourseButtonLp() {
      let observer = new MutationObserver(callback);
      let config = { attributes: true, childList: true, subtree: true };
      observer.observe(document.body, config);
  }
    function callback(mutationsList, observer) {
      for(let mutation of mutationsList) {
          if (mutation.type === 'childList') {
              let button = document.querySelector('[data-test="primary-button"]');
              if (button) {
                  if (window.location.pathname.includes('learning_paths')) {
                      button.style.display = 'none';
                  }
              }
          }
      }
  }

  let eoqMutationObserver = () => {
      let observer;

      let config = {
          attributes: true,
          childList: true,
          subtree: true
      };

      let observeStarter = () => {
          observer.observe(document,config);
      }

      let callback1 = () => {
        if(document.querySelector('[data-test="activity-title"]').innerHTML == 'Personal Lines Checkpoint 1') {
          document.querySelector('[data-test="continue-button"]').style.color = "grey";
          document.querySelector('[data-test="continue-button"]').style.background = "orange";
      	}
        observer.disconnect();
        observeStarter();
      };
      let callback2 = () => {
        if(document.querySelector('[data-test="activity-title"]').innerHTML == 'Personal Lines Checkpoint 1') {
          document.querySelector('[data-test="continue-button"]').style.color = "purple";
          document.querySelector('[data-test="continue-button"]').style.background = "white";
        }
        observer.disconnect();
        observeStarter();
      };


      observer = new MutationObserver(() => {
        if(document.querySelector('[data-test="activity-body"]')){
          callback1();
        };

        if(document.querySelector('#EndOfSurvey')) {
          callback2();
        };

      })

      observer.observe(document, config);
  }
  /*
  let preservedContinueButton;
  let mockMilestoneMutationObserver = () => {
    let config = {
        attributes: true,
        childList: true,
        subtree: true
    };

    let mockMilestoneObserver = new MutationObserver(() => {
      let activityTitle = document.querySelector('[data-test="activity-title"]');
      let footer = document.querySelector('footer');

      if(activityTitle &&
      (activityTitle.textContent.toLowerCase().indexOf('feedback') > -1) &&
      footer){
        let navButtons = footer.querySelector('.deLeqc').children;
        preservedContinueButton = navButtons[0];

        if(navButtons != null){
          let mockMilestoneWrapper = document.createElement('div');
          mockMilestoneWrapper.setAttribute('title', 'Please make sure to complete the survey to continue');
          mockMilestoneWrapper.setAttribute('aria-describedby', ':r0:');

          let mockMilestoneButton = document.createElement('button');
          mockMilestoneButton.classList.add('ButtonContainer-sc-1lz9u5r-2');
          mockMilestoneButton.classList.add('dxvqSB');
          mockMilestoneButton.setAttribute('type', 'button');
          mockMilestoneButton.setAttribute('data-test', 'disabled-continue-button');
          mockMilestoneButton.setAttribute('disabled', true);

          let mockMilestoneText = document.createElement('span');
          mockMilestoneText.classList.add('Label-sc-1lz9u5r-0');
          mockMilestoneText.classList.add('hlPxhH');
          mockMilestoneText.textContent = 'Continue';

          let mockMilestoneChevron = document.createElement('i');
          mockMilestoneChevron.classList.add('chevron');
          mockMilestoneChevron.classList.add('chevron--right');
          mockMilestoneChevron.classList.add('far');
          mockMilestoneChevron.classList.add('fa-chevron-right');
          mockMilestoneChevron.setAttribute('data-test','chevron');

          mockMilestoneWrapper.appendChild(mockMilestoneButton);
          mockMilestoneButton.appendChild(mockMilestoneText);
          mockMilestoneButton.appendChild(mockMilestoneChevron);

          navButtons[0].replaceWith(mockMilestoneWrapper);
        }
        mockMilestoneObserver.disconnect();
      }
    })

    mockMilestoneObserver.observe(document, config);
    */
  }
