Index: gc_lang/fr/webext/content_scripts/init.js ================================================================== --- gc_lang/fr/webext/content_scripts/init.js +++ gc_lang/fr/webext/content_scripts/init.js @@ -49,10 +49,12 @@ oGCPanel: null, oMessageBox: null, xRightClickedNode: null, + + xObserver: null, listenRightClick: function () { // Node where a right click is done // Bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1325814 document.addEventListener('contextmenu', function (xEvent) { @@ -89,10 +91,37 @@ this.nMenu += 1; } } } }, + + observePage: function () { + /* + When a textarea is added via jascript we add the menu :) + */ + let this.xObserver = new MutationObserver(function (mutations) { + mutations.forEach(function (mutation) { + for (let i = 0; i < mutation.addedNodes.length; i++){ + if (mutation.addedNodes[i].getElementsByTagName) { + if (mutation.addedNodes[i].tagName == "TEXTAREA") { + oGrammalecte.lMenu.push(new GrammalecteMenu(oGrammalecte.nMenu, mutation.addedNodes[i])); + oGrammalecte.nMenu += 1; + } else { + for (let xNode of mutation.addedNodes[i].getElementsByTagName("textarea")) { + oGrammalecte.lMenu.push(new GrammalecteMenu(oGrammalecte.nMenu, xNode)); + oGrammalecte.nMenu += 1; + } + } + } + } + }); + }); + this.xObserver.observe(document.body, { + childList: true, + subtree: true + }); + }, rescanPage: function () { if (this.oTFPanel !== null) { this.oTFPanel.hide(); } if (this.oLxgPanel !== null) { this.oLxgPanel.hide(); } if (this.oGCPanel !== null) { this.oGCPanel.hide(); } @@ -296,30 +325,6 @@ /* Start */ oGrammalecte.listenRightClick(); oGrammalecte.createMenus(); - -/* - When a textarea is added via jascript we add the menu :) -*/ -let observer = new MutationObserver(function(mutations) { - mutations.forEach(function(mutation) { - for(let i = 0; i < mutation.addedNodes.length; i++){ - if ( mutation.addedNodes[i].getElementsByTagName ){ - if ( mutation.addedNodes[i].tagName == "TEXTAREA" ) { - oGrammalecte.lMenu.push(new GrammalecteMenu(oGrammalecte.nMenu, mutation.addedNodes[i])); - oGrammalecte.nMenu += 1; - } else { - for (let xNode of mutation.addedNodes[i].getElementsByTagName("textarea")) { - oGrammalecte.lMenu.push(new GrammalecteMenu(oGrammalecte.nMenu, xNode)); - oGrammalecte.nMenu += 1; - } - } - } - } - }); -}); -observer.observe(document.body, { - childList: true, - subtree: true -}); +oGrammalecte.observePage();