Skip to content

Commit

Permalink
Spike using DOM Mutation observer for Inbox support
Browse files Browse the repository at this point in the history
Instead of using Gmail.js, add a DOM Mutation observer on all
contenteditable DIVs.  Not sure how performance will be.

[#4]
  • Loading branch information
sbrudz authored and Steve Brudz committed Jun 24, 2016
1 parent cfcc49d commit a5dec2c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"128": "img/JustNotSorry-128.png" },
"content_scripts": [
{
"matches": ["https://mail.google.com/*"],
"matches": ["https://mail.google.com/*", "https://inbox.google.com/*"],
"css": ["just-not-sorry.css"],
"js": ["lib/head.load.min.js", "src/ScriptLoader.js"]
}
Expand Down
34 changes: 31 additions & 3 deletions src/JustNotSorry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ var JustNotSorry = function() {
var gmail;
var warningChecker;

function observeContentEditable() {
console.log('observeContentEditable');
var observer = new MutationObserver(function(mutations) {
console.log('in mutation observer');
mutations.forEach(function(mutation) {
//var changedNode = mutation.target;
var myNodeList = mutation.addedNodes;
for (var i = 0; i < myNodeList.length; ++i) {
var node = myNodeList[i];
if (node.querySelectorAll) {
var editableNodes = node.querySelectorAll('div[contentEditable=true]');
if (editableNodes.length > 0) {
console.log('mutation', mutation);
console.log('node ' + i, node);
console.log(editableNodes);
}
}
//if (node.getAttribute('contentEditable')) {
// console.log('node ' + i, myNodeList[i]);
//}
}
});
});
observer.observe(document, {childList: true, subtree: true});
}

function addWarningsOnFocusIn(compose) {
var $target = compose.$el;
$target.focusin(function(e) {
Expand Down Expand Up @@ -54,9 +80,11 @@ var JustNotSorry = function() {
updateWarningsOnMutation(compose);
}

gmail = new Gmail();
//gmail = new Gmail();
warningChecker = new WarningChecker(WARNINGS);
gmail.observe.on('compose', checkForWarnings);
//gmail.observe.on('compose', checkForWarnings);
observeContentEditable();
};

refresh(JustNotSorry);
JustNotSorry();
//refresh(JustNotSorry);

0 comments on commit a5dec2c

Please sign in to comment.