Now this is not my idea... I found a git on gitHub that did exactly what I needed it to do the problem was that it was beefy(12k lines)(GitHub - sdjrice/msgobs: A JavaScript modification for the Canvas learning management system which adds the ability to m… ). So I forked it and was going to go to work on it, convert to plain JS modify, when I realized I had no idea WTH is going on. Seriously though, @sdjrice was on another level. So I scraped the project and decided to go in from scratch. I created a baby version of that. So it has a ton of stipulations.
One stipulation that will not disappear is that a course must be selected in order to use.
- can only be used once per session--- this is a stipulation that I imposed because we have very click happy people. You can remove by switching the bool from {once: true} to false
- This does not work on the grade book.-I am no longer concerned w/this deemed not that important by staff
- If you were to decide to remove one of the students from the email there is no direct line to retract the parents from the email. I am no longer working on this as well.


I tried to embed the proof of concept no luck so here is the link:
https://www.iorad.com/player/1618642/Add-observers-to-email
Now anywhere you might see a set of // // those belong to a custom CSS animation I can share it if anyone is interested its the pacMan that you see nest to the button. Or you can use the integrated loading animation in Canvas.
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">addObserverEmailButton</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">const</SPAN> checkIfNull <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">async</SPAN> selector <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">while</SPAN> <SPAN class="punctuation token">(</SPAN>document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">querySelector</SPAN><SPAN class="punctuation token">(</SPAN>selector<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">===</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">await</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Promise</SPAN><SPAN class="punctuation token">(</SPAN>resolve <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">requestAnimationFrame</SPAN><SPAN class="punctuation token">(</SPAN>resolve<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="keyword token">return</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">querySelector</SPAN><SPAN class="punctuation token">(</SPAN>selector<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="token function">checkIfNull</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"#compose-btn"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><BR /> ENV<SPAN class="punctuation token">.</SPAN>current_user_roles<SPAN class="punctuation token">.</SPAN><SPAN class="token function">includes</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"teacher"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">||</SPAN><BR /> ENV<SPAN class="punctuation token">.</SPAN>current_user_roles<SPAN class="punctuation token">.</SPAN><SPAN class="token function">includes</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"admin"</SPAN><SPAN class="punctuation token">)</SPAN><BR /> <SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">const</SPAN> delay <SPAN class="operator token">=</SPAN> ms <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Promise</SPAN><SPAN class="punctuation token">(</SPAN>res <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">setTimeout</SPAN><SPAN class="punctuation token">(</SPAN>res<SPAN class="punctuation token">,</SPAN> ms<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> conversationsNav <SPAN class="operator token">=</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">querySelector</SPAN><SPAN class="punctuation token">(</SPAN><BR /> <SPAN class="string token">"div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix"</SPAN><BR /> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> parentButton <SPAN class="operator token">=</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">createElement</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"div"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> classesToAdd <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><BR /> <SPAN class="string token">"ui-button"</SPAN><SPAN class="punctuation token">,</SPAN><BR /> <SPAN class="string token">"ui-widget"</SPAN><SPAN class="punctuation token">,</SPAN><BR /> <SPAN class="string token">"ui-state-default"</SPAN><SPAN class="punctuation token">,</SPAN><BR /> <SPAN class="string token">"ui-corner-all"</SPAN><SPAN class="punctuation token">,</SPAN><BR /> <SPAN class="string token">"ui-button-text-only"</SPAN><SPAN class="punctuation token">,</SPAN><BR /> <SPAN class="string token">"includeObserver"</SPAN><BR /> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN><BR /> parentButton<SPAN class="punctuation token">.</SPAN>classList<SPAN class="punctuation token">.</SPAN><SPAN class="token function">add</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>classesToAdd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> parentButton<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setAttribute</SPAN><SPAN class="punctuation token">(</SPAN><BR /> <SPAN class="string token">"style"</SPAN><SPAN class="punctuation token">,</SPAN><BR /> <SPAN class="string token">"margin:0 2px; min-width: 110px; background-color:wheat;"</SPAN><BR /> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> parentButton<SPAN class="punctuation token">.</SPAN>innerHTML <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Include Observers"</SPAN><SPAN class="punctuation token">;</SPAN><BR /> conversationsNav<SPAN class="punctuation token">.</SPAN><SPAN class="token function">insertBefore</SPAN><SPAN class="punctuation token">(</SPAN><BR /> parentButton<SPAN class="punctuation token">,</SPAN><BR /> conversationsNav<SPAN class="punctuation token">.</SPAN>childNodes<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><BR /> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /><BR /> <SPAN class="comment token">// //let pmLoader = document.createElement("div");</SPAN><BR /> <SPAN class="comment token">// //let classesToAddPM = ["gameLoader", "pacMan"];</SPAN><BR /> <SPAN class="comment token">// //pmLoader.classList.add(...classesToAddPM);</SPAN><BR /> <SPAN class="comment token">// //conversationsNav.insertBefore(pmLoader, conversationsNav.childNodes[2]);</SPAN><BR /><BR /> conversationsNav<SPAN class="punctuation token">.</SPAN><SPAN class="token function">querySelector</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">".includeObserver"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">addEventListener</SPAN><SPAN class="punctuation token">(</SPAN><BR /> <SPAN class="string token">"click"</SPAN><SPAN class="punctuation token">,</SPAN><BR /> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">let</SPAN> course <SPAN class="operator token">=</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">querySelector</SPAN><SPAN class="punctuation token">(</SPAN><BR /> <SPAN class="string token">'.message-header-input > input[type="hidden"]'</SPAN><BR /> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> courseNum <SPAN class="operator token">=</SPAN> course<SPAN class="punctuation token">.</SPAN>value<SPAN class="punctuation token">.</SPAN><SPAN class="token function">split</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"_"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> parentCollection <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN> data<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> kiddosArr <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> emailParents <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN><BR /><BR /> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>course<SPAN class="punctuation token">.</SPAN>value<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="comment token">//loading animation</SPAN><BR /> <SPAN class="comment token">// //document.querySelector(".gameLoader.pacMan").style.setProperty("--playState", "play");</SPAN><BR /> <SPAN class="comment token">//loading animation</SPAN><BR /> <SPAN class="keyword token">const</SPAN> fetchObservees <SPAN class="operator token">=</SPAN> <SPAN class="template-string token"><SPAN class="string token">`/api/v1/courses/</SPAN><SPAN class="interpolation token"><SPAN class="interpolation-punctuation punctuation token">${</SPAN>courseNum<SPAN class="interpolation-punctuation punctuation token">}</SPAN></SPAN><SPAN class="string token">/enrollments?type[]=ObserverEnrollment&per_page=100`</SPAN></SPAN><SPAN class="punctuation token">;</SPAN><BR /><BR /> <SPAN class="keyword token">function</SPAN> <SPAN class="token function">nextURL</SPAN><SPAN class="punctuation token">(</SPAN>linkTxt<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>linkTxt<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">let</SPAN> links <SPAN class="operator token">=</SPAN> linkTxt<SPAN class="punctuation token">.</SPAN><SPAN class="token function">split</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">","</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> nextRegEx <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">RegExp</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'^<(.*)>; rel="next"$'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /><BR /> <SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">let</SPAN> i <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> i <SPAN class="operator token"><</SPAN> links<SPAN class="punctuation token">.</SPAN>length<SPAN class="punctuation token">;</SPAN> i<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">let</SPAN> matches <SPAN class="operator token">=</SPAN> nextRegEx<SPAN class="punctuation token">.</SPAN><SPAN class="token function">exec</SPAN><SPAN class="punctuation token">(</SPAN>links<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>matches <SPAN class="operator token">&&</SPAN> matches<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="comment token">//return right away</SPAN><BR /> <SPAN class="comment token">//console.log(matches[1]);</SPAN><BR /> <SPAN class="keyword token">return</SPAN> matches<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="comment token">//Next define your main call:</SPAN><BR /><BR /> <SPAN class="keyword token">const</SPAN> OPTIONS <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> credentials<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"same-origin"</SPAN><SPAN class="punctuation token">,</SPAN><BR /> headers<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> accept<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"application/json"</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><BR /> timeout<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">5000</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="token function">main</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">const</SPAN> response <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">fetch</SPAN><SPAN class="punctuation token">(</SPAN>fetchObservees<SPAN class="punctuation token">,</SPAN> OPTIONS<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> data <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> response<SPAN class="punctuation token">.</SPAN><SPAN class="token function">json</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> res <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> data<SPAN class="punctuation token">:</SPAN> data<SPAN class="punctuation token">,</SPAN><BR /> ok<SPAN class="punctuation token">:</SPAN> response<SPAN class="punctuation token">.</SPAN>ok<SPAN class="punctuation token">,</SPAN><BR /> headers<SPAN class="punctuation token">:</SPAN> response<SPAN class="punctuation token">.</SPAN>headers<BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><BR /> parentCollection<SPAN class="punctuation token">.</SPAN>data <SPAN class="operator token">=</SPAN> res<SPAN class="punctuation token">.</SPAN>data<SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">loop</SPAN><SPAN class="punctuation token">(</SPAN>res<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="comment token">//And then your loop</SPAN><BR /><BR /> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="token function">loop</SPAN><SPAN class="punctuation token">(</SPAN>parents<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token function">nextURL</SPAN><SPAN class="punctuation token">(</SPAN>parents<SPAN class="punctuation token">.</SPAN>headers<SPAN class="punctuation token">.</SPAN><SPAN class="keyword token">get</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Link"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">===</SPAN> undefined<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="comment token">//otherwise keep going.</SPAN><BR /> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">const</SPAN> RESPONSE <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">fetch</SPAN><SPAN class="punctuation token">(</SPAN><BR /> <SPAN class="token function">nextURL</SPAN><SPAN class="punctuation token">(</SPAN>parents<SPAN class="punctuation token">.</SPAN>headers<SPAN class="punctuation token">.</SPAN><SPAN class="keyword token">get</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Link"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><BR /> OPTIONS<BR /> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> data <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> RESPONSE<SPAN class="punctuation token">.</SPAN><SPAN class="token function">json</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">let</SPAN> res <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> data<SPAN class="punctuation token">:</SPAN> data<SPAN class="punctuation token">,</SPAN><BR /> ok<SPAN class="punctuation token">:</SPAN> RESPONSE<SPAN class="punctuation token">.</SPAN>ok<SPAN class="punctuation token">,</SPAN><BR /> headers<SPAN class="punctuation token">:</SPAN> RESPONSE<SPAN class="punctuation token">.</SPAN>headers<BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>res<SPAN class="punctuation token">.</SPAN>ok<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="comment token">//console.log(res.data);</SPAN><BR /> parentCollection<SPAN class="punctuation token">.</SPAN>data <SPAN class="operator token">=</SPAN> parentCollection<SPAN class="punctuation token">.</SPAN>data<SPAN class="punctuation token">.</SPAN><SPAN class="token function">concat</SPAN><SPAN class="punctuation token">(</SPAN><BR /> res<SPAN class="punctuation token">.</SPAN>data<BR /> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="comment token">//console.log(res.data);</SPAN><BR /> <SPAN class="comment token">//console.info(Object.keys(parents.data).length);</SPAN><BR /> <SPAN class="comment token">//console.info(Object.keys(parentCollection.data).length);</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">loop</SPAN><SPAN class="punctuation token">(</SPAN>res<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="comment token">//await loop(res);</SPAN><BR /> <SPAN class="comment token">//if you want to wait for it.</SPAN><BR /><BR /> <SPAN class="comment token">//You need to call it from within an async function.</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="comment token">//Now all you need to do is call the main function:</SPAN><BR /> <SPAN class="keyword token">const</SPAN> waitForMom <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">main</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="comment token">//or:</SPAN><BR /> <SPAN class="comment token">//await main();</SPAN><BR /> <SPAN class="comment token">//if you want to wait for it.</SPAN><BR /> <SPAN class="comment token">//You need to call it from within an async function !impotanto.</SPAN><BR /> <SPAN class="token function">waitForMom</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><BR /> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">async</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="comment token">//console.log(parentCollection.data);</SPAN><BR /> document<BR /> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">querySelectorAll</SPAN><SPAN class="punctuation token">(</SPAN><BR /> <SPAN class="string token">'div.message-header-input input[name="recipients[]"]'</SPAN><BR /> <SPAN class="punctuation token">)</SPAN><BR /> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">forEach</SPAN><SPAN class="punctuation token">(</SPAN>kiddo <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> kiddosArr<SPAN class="punctuation token">.</SPAN><SPAN class="token function">push</SPAN><SPAN class="punctuation token">(</SPAN>kiddo<SPAN class="punctuation token">.</SPAN>value<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="comment token">//console.log(kiddosArr);</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><BR /> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">async</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> kiddosArr <SPAN class="operator token">=</SPAN> kiddosArr<SPAN class="punctuation token">.</SPAN><SPAN class="token function">map</SPAN><SPAN class="punctuation token">(</SPAN>x <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">return</SPAN> <SPAN class="token function">parseInt</SPAN><SPAN class="punctuation token">(</SPAN>x<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><BR /> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">async</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> parentCollection<SPAN class="punctuation token">.</SPAN>data<SPAN class="punctuation token">.</SPAN><SPAN class="token function">forEach</SPAN><SPAN class="punctuation token">(</SPAN>element <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="comment token">//console.log(element.associated_user_id);</SPAN><BR /> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>kiddosArr<SPAN class="punctuation token">.</SPAN><SPAN class="token function">includes</SPAN><SPAN class="punctuation token">(</SPAN>element<SPAN class="punctuation token">.</SPAN>associated_user_id<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> emailParents<SPAN class="punctuation token">.</SPAN><SPAN class="token function">push</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>element<SPAN class="punctuation token">.</SPAN>user_id<SPAN class="punctuation token">,</SPAN> element<SPAN class="punctuation token">.</SPAN>user<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="comment token">//}</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><BR /> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">then</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">async</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">delay</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">1000</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>emailParents<SPAN class="punctuation token">.</SPAN>length <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="comment token">//loading animation</SPAN><BR /> <SPAN class="comment token">// //document.querySelector(".gameLoader.pacMan").style.setProperty("--playState", "paused");</SPAN><BR /> <SPAN class="comment token">//loading animation</SPAN><BR /> emailParents<SPAN class="punctuation token">.</SPAN><SPAN class="token function">forEach</SPAN><SPAN class="punctuation token">(</SPAN>parent <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">table</SPAN><SPAN class="punctuation token">(</SPAN>parent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">querySelectorAll</SPAN><SPAN class="punctuation token">(</SPAN><BR /> <SPAN class="string token">".ac-token-list"</SPAN><BR /> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>innerHTML <SPAN class="operator token">+</SPAN><SPAN class="operator token">=</SPAN> `<SPAN class="operator token"><</SPAN>li <SPAN class="keyword token">class</SPAN><SPAN class="operator token">=</SPAN><SPAN class="string token">"ac-token"</SPAN> style<SPAN class="operator token">=</SPAN><SPAN class="string token">"background-color:wheat;"</SPAN><SPAN class="operator token">></SPAN><BR /> $<SPAN class="punctuation token">{</SPAN>parent<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="operator token"><</SPAN>a href<SPAN class="operator token">=</SPAN><SPAN class="string token">"#"</SPAN> <SPAN class="keyword token">class</SPAN><SPAN class="operator token">=</SPAN><SPAN class="string token">"ac-token-remove-btn"</SPAN><SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN>i <SPAN class="keyword token">class</SPAN><SPAN class="operator token">=</SPAN><SPAN class="string token">"icon-x icon-messageRecipient--cancel"</SPAN><SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>i<SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN>span <SPAN class="keyword token">class</SPAN><SPAN class="operator token">=</SPAN><SPAN class="string token">"screenreader-only"</SPAN><SPAN class="operator token">></SPAN><BR /> Remove recipient $<SPAN class="punctuation token">{</SPAN>parent<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>span<SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>a<SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN>input type<SPAN class="operator token">=</SPAN><SPAN class="string token">"hidden"</SPAN> name<SPAN class="operator token">=</SPAN><SPAN class="string token">"recipients[]"</SPAN> value<SPAN class="operator token">=</SPAN><SPAN class="string token">"${parent[0]}"</SPAN><SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>li<SPAN class="operator token">></SPAN><SPAN class="template-string token"><SPAN class="string token">`;<BR /> });<BR /> } else {<BR /> popUpError(<BR /> `</SPAN></SPAN><SPAN class="punctuation token">(</SPAN> ⊙0⊙<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN> I am not seeing an observers associated<SPAN class="punctuation token">.</SPAN> Sorry<SPAN class="punctuation token">.</SPAN> <SPAN class="operator token">-</SPAN> <SPAN class="punctuation token">(</SPAN>⊙▂⊙ <SPAN class="punctuation token">)</SPAN><SPAN class="template-string token"><SPAN class="string token">`<BR /> );<BR /> }<BR /> });<BR /> } else {<BR /> popUpError(<BR /> `</SPAN></SPAN><SPAN class="punctuation token">(</SPAN>×_×<SPAN class="punctuation token">;</SPAN>)<SPAN class="operator token">-</SPAN>In order to add parents you must select a course first<SPAN class="punctuation token">.</SPAN> Re<SPAN class="operator token">-</SPAN>fresh to <SPAN class="keyword token">try</SPAN> again<SPAN class="punctuation token">.</SPAN> <SPAN class="operator token">-</SPAN>(o。o;)`<BR /> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><BR /> <SPAN class="punctuation token">{</SPAN> once<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">true</SPAN> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="comment token">//---------------------------------------------------------------------------</SPAN><BR /> <SPAN class="keyword token">const</SPAN> popUpError <SPAN class="operator token">=</SPAN> msgTxt <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">const</SPAN> msgHolder <SPAN class="operator token">=</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">querySelector</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"#flash_message_holder"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">const</SPAN> timeout <SPAN class="operator token">=</SPAN> <SPAN class="number token">9000</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="keyword token">const</SPAN> daMsg <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>msgHolder<SPAN class="punctuation token">.</SPAN>innerHTML <SPAN class="operator token">=</SPAN> `<SPAN class="operator token"><</SPAN>div role<SPAN class="operator token">=</SPAN><SPAN class="string token">"alert"</SPAN> <SPAN class="keyword token">class</SPAN><SPAN class="operator token">=</SPAN><SPAN class="string token">"ic-flash-static ic-flash-error popUp"</SPAN><SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN>div <SPAN class="keyword token">class</SPAN><SPAN class="operator token">=</SPAN><SPAN class="string token">"ic-flash__icon"</SPAN> aria<SPAN class="operator token">-</SPAN>hidden<SPAN class="operator token">=</SPAN><SPAN class="string token">"true"</SPAN><SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN>i <SPAN class="keyword token">class</SPAN><SPAN class="operator token">=</SPAN><SPAN class="string token">"icon-warning"</SPAN><SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>i<SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>div<SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN>h1<SPAN class="operator token">></SPAN>$<SPAN class="punctuation token">{</SPAN>msgTxt<SPAN class="punctuation token">}</SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>h1<SPAN class="operator token">></SPAN><BR /> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>div<SPAN class="operator token">></SPAN>`<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> daMsg<SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="token function">setTimeout</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><BR /> <SPAN class="keyword token">let</SPAN> popUp <SPAN class="operator token">=</SPAN> document<SPAN class="punctuation token">.</SPAN><SPAN class="token function">querySelector</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">".popUp"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> popUp<SPAN class="punctuation token">.</SPAN>parentNode<SPAN class="punctuation token">.</SPAN><SPAN class="token function">removeChild</SPAN><SPAN class="punctuation token">(</SPAN>popUp<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> timeout<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN><BR /> <SPAN class="comment token">//---------------------------------------------------------------------------</SPAN><BR /><SPAN class="punctuation token">}</SPAN><BR /><SPAN class="token function">addObserverEmailButton</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><BR /><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Edit: 17-12-19: modified script to pull in a 100 parents if there, as well as made a few more async calls for better error handling and lengthy forEach if >50 parents(merged classes & lectures)
Edit: 10-02-20: modified script to pull in all paginated pages if there is pagination now working in large courses like grade counselors w/400+ students and 1000+ parents