1
2
3
4
5
6
7
8
9
10
11
12
|
// Modify page
/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* global GrammalectePanel, GrammalecteMenu, GrammalecteTextFormatter, GrammalecteLexicographer, GrammalecteGrammarChecker, GrammalecteMessageBox, showError, MutationObserver, chrome, document, console */
/*
JS sucks (again, and again, and again, and again…)
Not possible to load content from within the extension:
https://bugzilla.mozilla.org/show_bug.cgi?id=1267027
No SharedWorker, no images allowed for now…
*/
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
|
// Modify page
/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* global GrammalectePanel, GrammalecteButton, GrammalecteTextFormatter, GrammalecteLexicographer, GrammalecteGrammarChecker, GrammalecteMessageBox, showError, MutationObserver, chrome, document, console */
/*
JS sucks (again, and again, and again, and again…)
Not possible to load content from within the extension:
https://bugzilla.mozilla.org/show_bug.cgi?id=1267027
No SharedWorker, no images allowed for now…
*/
|
︙ | | | ︙ | |
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
}, true);
},
clearRightClickedNode: function () {
this.xRightClickedNode = null;
},
createMenus: function () {
if (bChrome) {
browser.storage.local.get("ui_options", this._createMenus.bind(this));
return;
}
browser.storage.local.get("ui_options").then(this._createMenus.bind(this), showError);
},
_createMenus: function (oOptions) {
if (oOptions.hasOwnProperty("ui_options")) {
this.oOptions = oOptions.ui_options;
if (this.oOptions.textarea) {
for (let xNode of document.getElementsByTagName("textarea")) {
if (xNode.style.display !== "none" && xNode.style.visibility !== "hidden" && xNode.getAttribute("spellcheck") !== "false") {
this.lMenu.push(new GrammalecteMenu(this.nMenu, xNode));
this.nMenu += 1;
}
}
}
if (this.oOptions.editablenode) {
for (let xNode of document.querySelectorAll("[contenteditable]")) {
this.lMenu.push(new GrammalecteMenu(this.nMenu, xNode));
this.nMenu += 1;
}
}
}
},
observePage: function () {
// When a textarea is added via jascript we add the menu
let that = this;
this.xObserver = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
for (let i = 0; i < mutation.addedNodes.length; i++){
if (mutation.addedNodes[i].tagName == "TEXTAREA") {
if (that.oOptions === null || that.oOptions.textarea) {
oGrammalecte.lMenu.push(new GrammalecteMenu(oGrammalecte.nMenu, mutation.addedNodes[i]));
oGrammalecte.nMenu += 1;
}
} else if (mutation.addedNodes[i].getElementsByTagName) {
if (that.oOptions === null || that.oOptions.textarea) {
for (let xNode of mutation.addedNodes[i].getElementsByTagName("textarea")) {
oGrammalecte.lMenu.push(new GrammalecteMenu(oGrammalecte.nMenu, xNode));
oGrammalecte.nMenu += 1;
}
}
}
}
});
});
|
|
|
|
|
|
|
|
|
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
}, true);
},
clearRightClickedNode: function () {
this.xRightClickedNode = null;
},
createButtons: function () {
if (bChrome) {
browser.storage.local.get("ui_options", this._createButtons.bind(this));
return;
}
browser.storage.local.get("ui_options").then(this._createButtons.bind(this), showError);
},
_createButtons: function (oOptions) {
if (oOptions.hasOwnProperty("ui_options")) {
this.oOptions = oOptions.ui_options;
if (this.oOptions.textarea) {
for (let xNode of document.getElementsByTagName("textarea")) {
if (xNode.style.display !== "none" && xNode.style.visibility !== "hidden" && xNode.getAttribute("spellcheck") !== "false") {
this.lMenu.push(new GrammalecteButton(this.nMenu, xNode));
this.nMenu += 1;
}
}
}
if (this.oOptions.editablenode) {
for (let xNode of document.querySelectorAll("[contenteditable]")) {
this.lMenu.push(new GrammalecteButton(this.nMenu, xNode));
this.nMenu += 1;
}
}
}
},
observePage: function () {
// When a textarea is added via jascript we add the menu
let that = this;
this.xObserver = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
for (let i = 0; i < mutation.addedNodes.length; i++){
if (mutation.addedNodes[i].tagName == "TEXTAREA") {
if (that.oOptions === null || that.oOptions.textarea) {
oGrammalecte.lMenu.push(new GrammalecteButton(oGrammalecte.nMenu, mutation.addedNodes[i]));
oGrammalecte.nMenu += 1;
}
} else if (mutation.addedNodes[i].getElementsByTagName) {
if (that.oOptions === null || that.oOptions.textarea) {
for (let xNode of mutation.addedNodes[i].getElementsByTagName("textarea")) {
oGrammalecte.lMenu.push(new GrammalecteButton(oGrammalecte.nMenu, xNode));
oGrammalecte.nMenu += 1;
}
}
}
}
});
});
|
︙ | | | ︙ | |
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
//if (this.oLxgPanel !== null) { this.oLxgPanel.hide(); }
if (this.oGCPanel !== null) { this.oGCPanel.hide(); }
for (let oMenu of this.lMenu) {
oMenu.deleteNodes();
}
this.lMenu.length = 0; // to clear an array
this.listenRightClick();
this.createMenus();
},
createTFPanel: function () {
if (this.oTFPanel === null) {
this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 760, 600, false);
//this.oTFPanel.logInnerHTML();
this.oTFPanel.insertIntoPage();
window.setTimeout(function(self){
self.oTFPanel.adjustHeight();
}, 50, this);
}
},
|
|
|
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
//if (this.oLxgPanel !== null) { this.oLxgPanel.hide(); }
if (this.oGCPanel !== null) { this.oGCPanel.hide(); }
for (let oMenu of this.lMenu) {
oMenu.deleteNodes();
}
this.lMenu.length = 0; // to clear an array
this.listenRightClick();
this.createButtons();
},
createTFPanel: function () {
if (this.oTFPanel === null) {
this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 760, 595, false);
//this.oTFPanel.logInnerHTML();
this.oTFPanel.insertIntoPage();
window.setTimeout(function(self){
self.oTFPanel.adjustHeight();
}, 50, this);
}
},
|
︙ | | | ︙ | |
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
this.oGCPanel.clear();
this.oGCPanel.show();
this.oGCPanel.showEditor();
this.oGCPanel.start(xNode);
this.oGCPanel.startWaitIcon();
},
startLxgPanel: function () {
this.createGCPanel();
this.oGCPanel.clearLexicographer();
this.oGCPanel.showLexicographer();
this.oGCPanel.startWaitIcon();
},
startFTPanel: function (xNode=null) {
this.createTFPanel();
this.oTFPanel.start(xNode);
this.oTFPanel.show();
},
showMessage: function (sMessage) {
this.createMessageBox();
this.oMessageBox.show();
this.oMessageBox.setMessage(sMessage);
},
getPageText: function () {
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
this.oGCPanel.clear();
this.oGCPanel.show();
this.oGCPanel.showEditor();
this.oGCPanel.start(xNode);
this.oGCPanel.startWaitIcon();
},
showMessage: function (sMessage) {
this.createMessageBox();
this.oMessageBox.show();
this.oMessageBox.setMessage(sMessage);
},
getPageText: function () {
|
︙ | | | ︙ | |
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
xGrammalectePort.onMessage.addListener(function (oMessage) {
let {sActionDone, result, dInfo, bEnd, bError} = oMessage;
switch (sActionDone) {
case "init":
oGrammalecte.sExtensionUrl = oMessage.sUrl;
// Start
oGrammalecte.listenRightClick();
oGrammalecte.createMenus();
oGrammalecte.observePage();
break;
case "parseAndSpellcheck":
if (!bEnd) {
oGrammalecte.oGCPanel.addParagraphResult(result);
} else {
oGrammalecte.oGCPanel.stopWaitIcon();
|
|
|
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
xGrammalectePort.onMessage.addListener(function (oMessage) {
let {sActionDone, result, dInfo, bEnd, bError} = oMessage;
switch (sActionDone) {
case "init":
oGrammalecte.sExtensionUrl = oMessage.sUrl;
// Start
oGrammalecte.listenRightClick();
oGrammalecte.createButtons();
oGrammalecte.observePage();
break;
case "parseAndSpellcheck":
if (!bEnd) {
oGrammalecte.oGCPanel.addParagraphResult(result);
} else {
oGrammalecte.oGCPanel.stopWaitIcon();
|
︙ | | | ︙ | |