spectabular/title_listener.js
2015-03-16 11:13:37 -04:00

13 lines
542 B
JavaScript

var title = document.querySelector("title");
if (title!=null){
var observer = new MutationObserver(function(mutations){
mutations.forEach(function(mutation){
if (mutation.addedNodes.length===1 && mutation.removedNodes.length===1){
var newTitle = mutation.addedNodes[0].nodeValue;
var oldTitle = mutation.removedNodes[0].nodeValue;
chrome.runtime.sendMessage({"titleChange":{"newTitle":newTitle,"oldTitle":oldTitle}});
}
});
});
observer.observe(title,{childList:true,characterData:true,characterDataOldValue:true});
}