Skip to content

Commit

Permalink
Fix for Unresponsive Main Page due to Twitter Widget (tardis-sn#1743)
Browse files Browse the repository at this point in the history
* customize tweets after change is detected

* [build docs]
  • Loading branch information
atharva-2001 authored and DhruvSondhi committed Aug 1, 2021
1 parent 960a5f9 commit 055cf0d
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,35 @@


<script>
// observe the DOM for changes
const config = { childList: true };
// callback function to be called on change
const callback = function (mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === "childList") {
// customize tweet media if change is detected
customizeTweetMedia();
}
}
};
// create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
document.getElementsByClassName("twitter-block")[0].addEventListener(
"DOMSubtreeModified",
function (e) {
for (var target = e.target; target && target != this; target = target.parentNode) {
// loop parent nodes from the target to the delegation node
// if target matches the twitter widget
if (target.matches("#twitter-widget-0")) {
customizeTweetMedia();
var iframe = document.getElementById("twitter-widget-0");
const targetNode = iframe.contentWindow.document.getElementsByClassName("timeline-TweetList")[0];
// observe tweet list
observer.observe(targetNode, config);
}
}
},
Expand Down Expand Up @@ -50,14 +72,7 @@
tweetTextList[index].style.lineHeight = "1.1";
}
tweetList = iframe.contentWindow.document.getElementsByClassName("timeline-TweetList")[0];
tweetList.addEventListener(
"DOMSubtreeModified",
function () {
customizeTweetMedia();
},
false
);
};
// checks if the widget hasn't loaded and prints a message after 4 seconds
Expand Down

0 comments on commit 055cf0d

Please sign in to comment.