I'm working on a userscript for a D2L/Brightspace page, and part of what it does is modify the list of courses that a user is enrolled in.
The problem is when you click on the icon to open the list of courses, it makes an XHR request to a different page to get the list, and then updates the element on the page, so I have to wait for it to load before modifying the list in any way.
What I'm doing currently is making a setTimeout(function() {}, 500);
function to wait half a second before making any modifications, but that doesn't work 100% of the time. Sometimes the internet is slower and it takes the XHR request more than half a second to load, so it gets modified before it exists, meaning my changes do not happen. Other times, the internet is fast, and the old list is shown for about half a second, and then it's changed, which doesn't look nice.
I would like to be able to, instead of using a setTimeeout()
function, use something that allows me to run a function immediately after the XHR request has successfully loaded.
The XHR request is sent to https://d2l.ca/d2l/lp/courseSelector/440/InitPartial?...
*. Is there any way that I could track that specific one and run something when it's completed?
I have tried .ajaxStop()
, but since this isn't an ajax request, something else is needed.
Thanks :)
*Link modified slightly for anonymity.