Last active
July 30, 2018 04:25
-
-
Save adam-acosta/01e5e2c45766f45238bba1ceefa3580a to your computer and use it in GitHub Desktop.
fully automated script to load all coaches then add as recipient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var loadMoreCoachesAttempts = 0; | |
var loadMoreButtonSelector = '#main-app-content-container > div > ui-view > promote-container > div > div > div > div:nth-child(1) > promote-recipient-select > div > div.promote-recipient-select-pager.ng-scope > button'; | |
function waitForElementToDisplay(selector, time) { | |
if (document.querySelector(selector) != null) { | |
document.querySelector(selector).click(); | |
setTimeout(function() { | |
waitForElementToDisplay(selector, time); | |
}, 500); | |
} else { | |
if (loadMoreCoachesAttempts === 3) { | |
addCoaches(); | |
return console.log('loaded and selected all coaches or internet issue encountered'); | |
} | |
loadMoreCoachesAttempts++; | |
setTimeout(function() { | |
waitForElementToDisplay(selector, time); | |
}, time); | |
} | |
} | |
function getElementsByText(str, tag = 'a') { | |
return Array.prototype.slice.call(document.getElementsByTagName(tag)).filter(el => el.textContent.trim() === str.trim()); | |
} | |
function addCoaches() { | |
var addButtons = getElementsByText('Add', 'button'); | |
for (var i = 0; i <= addButtons.length - 1; i++) { | |
addButtons[i].click(); | |
} | |
} | |
waitForElementToDisplay(loadMoreButtonSelector, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment