Skip to content

Instantly share code, notes, and snippets.

@adam-acosta
Last active July 30, 2018 04:25
Show Gist options
  • Select an option

  • Save adam-acosta/01e5e2c45766f45238bba1ceefa3580a to your computer and use it in GitHub Desktop.

Select an option

Save adam-acosta/01e5e2c45766f45238bba1ceefa3580a to your computer and use it in GitHub Desktop.

Revisions

  1. adam-acosta renamed this gist Jul 30, 2018. 1 changed file with 0 additions and 0 deletions.
  2. adam-acosta revised this gist Jul 30, 2018. 1 changed file with 7 additions and 17 deletions.
    24 changes: 7 additions & 17 deletions fieldlevelAddRecipients.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    var loadMoreCoachesAttempts = 0;
    var loadMorebutton = '#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';
    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) {

    @@ -9,31 +9,28 @@ function waitForElementToDisplay(selector, time) {

    setTimeout(function() {
    waitForElementToDisplay(selector, time);
    }, time);
    }, 500);

    } else {

    if (loadMoreCoachesAttempts === 6) {
    console.log('loaded all coaches or internet issue encountered');
    return;
    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');

    @@ -42,11 +39,4 @@ function addCoaches() {
    }
    }


    function main() {
    waitForElementToDisplay(loadMorebutton, 1000);
    addCoaches();
    }


    main();
    waitForElementToDisplay(loadMoreButtonSelector, 1000);
  3. adam-acosta revised this gist Jul 30, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions fieldlevelAddRecipients.js
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,7 @@ function waitForElementToDisplay(selector, time) {

    }


    function getElementsByText(str, tag = 'a') {
    return Array.prototype.slice.call(document.getElementsByTagName(tag)).filter(el => el.textContent.trim() === str.trim());
    }
    @@ -47,4 +48,5 @@ function main() {
    addCoaches();
    }


    main();
  4. adam-acosta revised this gist Jul 30, 2018. 1 changed file with 47 additions and 18 deletions.
    65 changes: 47 additions & 18 deletions fieldlevelAddRecipients.js
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,50 @@
    var i = 0;
    var loadMoreCoachesAttempts = 0;
    var loadMorebutton = '#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) {
    if (i === 6) {
    console.log('loaded all coaches or internet issue encountered');
    return;
    }
    document.querySelector(selector).click();
    i++;
    setTimeout(function() {
    waitForElementToDisplay(selector, time);
    }, time);
    }
    else {
    setTimeout(function() {
    waitForElementToDisplay(selector, time);
    }, time);
    }

    if (document.querySelector(selector) != null) {

    document.querySelector(selector).click();

    setTimeout(function() {
    waitForElementToDisplay(selector, time);
    }, time);

    } else {

    if (loadMoreCoachesAttempts === 6) {
    console.log('loaded all coaches or internet issue encountered');
    return;
    }

    waitForElementToDisplay('#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', 1000);
    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();
    }
    }


    function main() {
    waitForElementToDisplay(loadMorebutton, 1000);
    addCoaches();
    }

    main();
  5. adam-acosta revised this gist Jul 30, 2018. No changes.
  6. adam-acosta created this gist Jul 30, 2018.
    21 changes: 21 additions & 0 deletions fieldlevelAddRecipients.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    var i = 0;
    function waitForElementToDisplay(selector, time) {
    if(document.querySelector(selector)!=null) {
    if (i === 6) {
    console.log('loaded all coaches or internet issue encountered');
    return;
    }
    document.querySelector(selector).click();
    i++;
    setTimeout(function() {
    waitForElementToDisplay(selector, time);
    }, time);
    }
    else {
    setTimeout(function() {
    waitForElementToDisplay(selector, time);
    }, time);
    }
    }

    waitForElementToDisplay('#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', 1000);