aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2014-12-14 14:24:30 -0500
committerTeddy Wing2014-12-14 14:24:30 -0500
commit6c34918ec98aedcbfd0778584ed25401435194bb (patch)
treeb5460e6ce7a893ccb527c181fbf8f1934033927c
parent8cdc79cd0409d1497174b768bc0b7c7bec9d4330 (diff)
downloadchrome-youtube-tooltipise-titles-6c34918ec98aedcbfd0778584ed25401435194bb.tar.bz2
tooltipise.js: Handle AJAX load of more videos
New videos loaded on a page over AJAX will not have title tooltips. Refresh tooltip titles when more videos are loaded. Just use a timeout to make things simple. The tooltipiser will wait 3 seconds between requesting more videos and refreshing titles. This will generally provide enough time to load the videos into the DOM unless the network connection is really slow.
-rw-r--r--tooltipise.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/tooltipise.js b/tooltipise.js
index 8d90aba..6331739 100644
--- a/tooltipise.js
+++ b/tooltipise.js
@@ -1,7 +1,17 @@
(function() {
- var title_elements = document.querySelectorAll('.yt-uix-sessionlink.yt-uix-tile-link');
-
- for (var i = 0; i < title_elements.length; i++) {
- title_elements[i].setAttribute('title', title_elements[i].innerText);
+ function tooltipise_titles () {
+ var title_elements = document.querySelectorAll('.yt-uix-sessionlink.yt-uix-tile-link');
+
+ for (var i = 0; i < title_elements.length; i++) {
+ title_elements[i].setAttribute('title', title_elements[i].innerText);
+ }
}
+
+ // Initial load
+ tooltipise_titles();
+
+ // Refresh titles when more videos are loaded
+ document.querySelector('.load-more-text').addEventListener('click', function() {
+ window.setTimeout(tooltipise_titles, 3000);
+ });
})()