Mind & Body Update All Customers

by brombomb

JavaScript

function remove() {
  var frame = document.getElementById('loader');
  frame.parentNode.removeChild(frame);
}

function mkIframe(src) {
  var iframe = document.createElement('iframe');
  iframe.id = 'loader';
  iframe.src = src;
  document.body.appendChild(iframe);
  $('#loader').css({
    position: 'fixed',
    top: 0,
    left: 0,
    width: '50%',
    height: '400px'
  });
  iframe.onload = work;
}

function work() {
  window.frames[1].document.getElementById('optAccountEmail').checked = true;
  window.frames[1].document.getElementById('optAccountText').checked = true;
  window.frames[1].document.getElementById('optScheduleEmail').checked = true;
  window.frames[1].document.getElementById('optScheduleText').checked = true;
  window.frames[1].document.getElementById('optPromoEmail').checked = true;
  window.frames[1].document.getElementsByClassName('doSave')[0].click();
  console.log(links.length);
  if (links.length) {
    window.setTimeout(() => {
      remove();
      mkIframe(links.shift())
    }, 5000);
  }
}

var urls = $('.clientLink');
var links = [];
urls.each((e, t) => {
  links.push(t.href);
})

// In case we have to reload, continue where we left off
// links = links.slice(1001 - 1);

mkIframe(links.shift());