21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
-
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
+
-
-
-
-
+
+
+
+
+
-
+
|
let xNodeInsertAfter = this.xNode;
if (document.location.host == "twitter.com" && this.xNode.classList.contains('rich-editor')) {
xNodeInsertAfter = this.xNode.parentNode;
}
this.bShadow = document.body.createShadowRoot || document.body.attachShadow;
if (this.bShadow){
if (this.bShadow) {
let nMarginTop = -1 * (parseInt(xStyle.marginBottom.replace('px', ''), 10));
this.oShadowBtn = oGrammalecte.createNode("div", {style: "display:none;position:absolute;width:0;height:0;"});
this.oShadowBtnNode = this.oShadowBtn.attachShadow({mode: "open"});
oGrammalecte.createStyle("content_scripts/menu.css", null, this.oShadowBtnNode);
this.oShadowBtnNode.appendChild(this.xButton);
this._insertAfter(this.oShadowBtn, xNodeInsertAfter, nMarginTop);
this.xShadowBtn = oGrammalecte.createNode("div", {style: "display:none;position:absolute;width:0;height:0;"});
this.xShadowBtnNode = this.xShadowBtn.attachShadow({mode: "open"});
oGrammalecte.createStyle("content_scripts/menu.css", null, this.xShadowBtnNode);
this.xShadowBtnNode.appendChild(this.xButton);
this._insertAfter(this.xShadowBtn, xNodeInsertAfter, nMarginTop);
this.oShadowMenu = oGrammalecte.createNode("div", {id: this.sMenuId+"_shadow", style: "display:none;position:absolute;width:0;height:0;"});
this.oShadowMenuNode = this.oShadowMenu.attachShadow({mode: "open"});
oGrammalecte.createStyle("content_scripts/menu.css", null, this.oShadowMenuNode);
this.oShadowMenuNode.appendChild(this.xMenu);
this._insertAfter(this.oShadowMenu, xNodeInsertAfter, nMarginTop + 8);
this.xShadowMenu = oGrammalecte.createNode("div", {id: this.sMenuId+"_shadow", style: "display:none;position:absolute;width:0;height:0;"});
this.xShadowMenuNode = this.xShadowMenu.attachShadow({mode: "open"});
oGrammalecte.createStyle("content_scripts/menu.css", null, this.xShadowMenuNode);
this.xShadowMenuNode.appendChild(this.xMenu);
this._insertAfter(this.xShadowMenu, xNodeInsertAfter, nMarginTop + 8);
} else {
let nMarginTop = -1 * (8 + parseInt(xStyle.marginBottom.replace('px', ''), 10));
if (!document.getElementById("grammalecte_cssmenu")){
if (!document.getElementById("grammalecte_cssmenu")) {
oGrammalecte.createStyle("content_scripts/menu.css", "grammalecte_cssmenu", document.head);
}
this._insertAfter(this.xButton, xNodeInsertAfter, nMarginTop);
this._insertAfter(this.xMenu, xNodeInsertAfter, nMarginTop + 8);
}
this._createListeners();
}
_insertAfter (xNewNode, xReferenceNode, nMarginTop) {
xReferenceNode.parentNode.insertBefore(xNewNode, xReferenceNode.nextSibling);
xNewNode.style.marginTop = nMarginTop + "px";
}
_createListeners () {
this.xNode.addEventListener('focus', (e) => {
if (this.bShadow){
this.oShadowBtn.style.display = "block";
}
this.xButton.style.display = "block";
if (this.bShadow) {
this.xShadowBtn.style.display = "block";
} else {
this.xButton.style.display = "block";
}
});
/*this.xNode.addEventListener('blur', (e) => {
window.setTimeout(() => {this.xButton.style.display = "none";}, 300);
});*/
}
_getText () {
return (this.xNode.tagName == "TEXTAREA") ? this.xNode.value.normalize("NFC") : this.xNode.innerText.normalize("NFC");
}
_createMenu () {
try {
let xMenu = oGrammalecte.createNode("div", {id: this.sMenuId, className: "grammalecte_menu"});
let xCloseButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_close_button", textContent: "×"} );
xCloseButton.onclick = () => {
if (this.bShadow){
this.oShadowBtn.style.display = "none";
this.xShadowBtn.style.display = "none";
}
this.xButton.style.display = "none";
this.switchMenu();
}
xMenu.appendChild(xCloseButton);
xMenu.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_menu_header", textContent: "GRAMMALECTE"}));
// Text formatter
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
|
}
catch (e) {
showError(e);
}
}
deleteNodes () {
if (this.bShadow){
this.oShadowMenu.parentNode.removeChild(this.oShadowMenu);
this.oShadowBtn.parentNode.removeChild(this.oShadowBtn);
if (this.bShadow) {
this.xShadowMenu.parentNode.removeChild(this.xShadowMenu);
this.xShadowBtn.parentNode.removeChild(this.xShadowBtn);
} else {
this.xMenu.parentNode.removeChild(this.xMenu);
this.xButton.parentNode.removeChild(this.xButton);
}
}
switchMenu () {
if (this.bShadow){
this.oShadowMenu.style.display = (this.oShadowMenu.style.display == "block") ? "none" : "block";
}
this.xMenu.style.display = (this.xMenu.style.display == "block") ? "none" : "block";
}
}
if (this.bShadow) {
this.xShadowMenu.style.display = (this.xShadowMenu.style.display == "block") ? "none" : "block";
} else {
this.xMenu.style.display = (this.xMenu.style.display == "block") ? "none" : "block";
}
}
}
|