Skip to content

Commit

Permalink
Wait for feed to load on homepage before adding broadcasts
Browse files Browse the repository at this point in the history
Fixes broadcasts on Firefox
Previously it would hide the whole container if we had broadcasts
  • Loading branch information
glen3b committed Nov 21, 2018
1 parent 8c219c9 commit e449935
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions js/home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @typedef {{id:number,title:string,message:string,shortMessage:string,timestamp?:Date,icon?:string}} Broadcast */

let feed = document.querySelector(".feed .item-list .s-edge-feed");
let homeFeedContainer = document.getElementById("home-feed-container");
let feed = homeFeedContainer.querySelector(".feed .item-list .s-edge-feed");

/**
* Creates a post from a broadcast
Expand Down Expand Up @@ -76,7 +77,27 @@ function formatDateAsString(date) {
}

if (storage.broadcasts !== "disabled") {
for (let broadcast of storage.unreadBroadcasts || []) {
feed.insertAdjacentElement("afterbegin", postFromBroadcast(broadcast));
}
(function () {
let observer = new MutationObserver(function (mutations) {
if (mutations.length == 0) {
return;
}

// we Should only be observing changes to style on homeFeedContainer
// style is set on homeFeedContainer whenever Schoology decides to unhide it (static CSS sets display: none), i.e. when it's finished loading
// once this happens, we can do our thing

for (let broadcast of storage.unreadBroadcasts || []) {
feed.insertAdjacentElement("afterbegin", postFromBroadcast(broadcast));
}

// then disconnect
observer.disconnect();
});

observer.observe(homeFeedContainer, {
attributes: true,
attributeFilter: ["style"]
});
})();
}

0 comments on commit e449935

Please sign in to comment.