Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch head for changes instead of title #35

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Source/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ function isForbiddenNode(node) {
return node.isContentEditable || // DraftJS and many others
(node.parentNode && node.parentNode.isContentEditable) || // Special case for Gmail
(node.tagName && (node.tagName.toLowerCase() == "textarea" || // Some catch-alls
node.tagName.toLowerCase() == "input"));
node.tagName.toLowerCase() == "input" ||
node.tagName.toLowerCase() == "script" ||
node.tagName.toLowerCase() == "noscript" ||
node.tagName.toLowerCase() == "template" ||
node.tagName.toLowerCase() == "style"));
}

// The callback used for the document body and title observers
Expand All @@ -275,13 +279,13 @@ function observerCallback(mutations) {

// Walk the doc (document) body, replace the title, and observe the body and title
function walkAndObserve(doc) {
var docTitle = doc.getElementsByTagName('title')[0],
var docHead = doc.getElementsByTagName('head')[0],
observerConfig = {
characterData: true,
childList: true,
subtree: true
},
bodyObserver, titleObserver;
bodyObserver, headObserver;

// Do the initial text replacements in the document body and title
walk(doc.body);
Expand All @@ -292,9 +296,9 @@ function walkAndObserve(doc) {
bodyObserver.observe(doc.body, observerConfig);

// Observe the title so we can handle any modifications there
if (docTitle) {
titleObserver = new MutationObserver(observerCallback);
titleObserver.observe(docTitle, observerConfig);
if (docHead) {
headObserver = new MutationObserver(observerCallback);
headObserver.observe(docHead, observerConfig);
}
}
walkAndObserve(document);