我试图将带有angularjs的GMail DOM操作为chrome扩展名。
目前我有一个基本的应用程序:
(function() { "use strict";
var html = document.querySelector('html');
html.classList.add('gmail-detect-response');
angular.bootstrap(html, ['myGmailApp']);
html.classList.add('ng-app');
html.classList.add('ng-csp');
}());
指令:
(function(){ 'use strict';
angular.module('myGmailApp').directive('gmailDetectResponse', detectResponse);
function detectResponse(){
return {
restrict: 'A',
link: function(scope, element, attrs){
var target = document.body;
var config = {
attributes: true,
childList: true,
subtree: true
};
var observer = new MutationObserver(function(mutations){
mutations.forEach(function(mutation){
if(mutation.addedNodes.length > 0){
console.log('mutmut');
var responseDivs = document.getElementsByClassName("gH acX");
for(var i = 0; i < responseDivs.length; i++){
if(responseDivs[i].getAttribute('gTrelloSend') == null){
responseDivs[i].setAttribute('gTrelloSend', '');
var para = document.createElement('p');
var textNode = document.createTextNode('TEST');
para.appendChild(textNode);
responseDivs[i].insertBefore(para, responseDivs[i].firstElementChild);
}
}
}
});
});
observer.observe(target, config);
}
}
};
})();
如果我将它放在基本的js文件中,我的变异观察器工作正常。 为什么我的指令没有被执行?
我的目标是检测所有&#34;响应div&#34;进入Gmail以创建一个可以调用angularjs控制器的按钮。
非常感谢!