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 @@ -212,10 +212,32 @@ if (oDataset) { Object.assign(xNode.dataset, oDataset); } return xNode; } + catch (e) { + showError(e); + } + }, + + createStyle: function (sLinkCss, sLinkId=null, oAppend=null) { + try { + let xNode = document.createElement("link"); + Object.assign(xNode, { + rel: "stylesheet", + type: "text/css", + media: "all", + href: this.sExtensionUrl + sLinkCss + }); + if (sLinkId) { + Object.assign(xNode, {id: sLinkId}); + } + if (oAppend) { + oAppend.appendChild(xNode); + } + return xNode; + } catch (e) { showError(e); } } }; Index: gc_lang/fr/webext/content_scripts/menu.js ================================================================== --- gc_lang/fr/webext/content_scripts/menu.js +++ gc_lang/fr/webext/content_scripts/menu.js @@ -27,29 +27,23 @@ this.bShadow = document.body.createShadowRoot || document.body.attachShadow; 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"}); - this.oShadowBtnNode.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/menu.css"}) - ); + oGrammalecte.createStyle("content_scripts/menu.css", null, this.oShadowBtnNode); this.oShadowBtnNode.appendChild(this.xButton); this._insertAfter(this.oShadowBtn, 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"}); - this.oShadowMenuNode.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/menu.css"}) - ); + oGrammalecte.createStyle("content_scripts/menu.css", null, this.oShadowMenuNode); this.oShadowMenuNode.appendChild(this.xMenu); this._insertAfter(this.oShadowMenu, xNodeInsertAfter, nMarginTop + 8); } else { let nMarginTop = -1 * (8 + parseInt(xStyle.marginBottom.replace('px', ''), 10)); if (!document.getElementById("grammalecte_cssmenu")){ - document.head.appendChild( - oGrammalecte.createNode("link", {id: "grammalecte_cssmenu", rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/menu.css"}) - ); + 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(); Index: gc_lang/fr/webext/content_scripts/message_box.js ================================================================== --- gc_lang/fr/webext/content_scripts/message_box.js +++ gc_lang/fr/webext/content_scripts/message_box.js @@ -63,26 +63,18 @@ return xButton; } insertIntoPage () { if (this.bShadow){ - this.oShadow.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel.css"}) - ); - this.oShadow.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/message_box.css"}) - ); + oGrammalecte.createStyle("content_scripts/panel.css", null, this.oShadow); + oGrammalecte.createStyle("content_scripts/message_box.css", null, this.oShadow); this.oShadow.appendChild(this.xMessageBox); document.body.appendChild(this.oShadowPanel); } else { if (!document.getElementById("grammalecte_cssmsg")){ - document.head.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel.css"}) - ); - document.head.appendChild( - oGrammalecte.createNode("link", {id: "grammalecte_cssmsg", rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/message_box.css"}) - ); + oGrammalecte.createStyle("content_scripts/panel.css", null, document.head); + oGrammalecte.createStyle("content_scripts/message_box.css", "grammalecte_cssmsg", document.head); } document.body.appendChild(this.xMessageBox); } } Index: gc_lang/fr/webext/content_scripts/panel.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel.js +++ gc_lang/fr/webext/content_scripts/panel.js @@ -96,38 +96,22 @@ return xButton; } insertIntoPage () { if (this.bShadow){ - this.oShadow.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel.css"}) - ); - this.oShadow.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel_gc.css"}) - ); - this.oShadow.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel_lxg.css"}) - ); - this.oShadow.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel_tf.css"}) - ); + oGrammalecte.createStyle("content_scripts/panel.css", null, this.oShadow); + oGrammalecte.createStyle("content_scripts/panel_gc.css", null, this.oShadow); + oGrammalecte.createStyle("content_scripts/panel_lxg.css", null, this.oShadow); + oGrammalecte.createStyle("content_scripts/panel_tf.css", null, this.oShadow); this.oShadow.appendChild(this.xPanel); document.body.appendChild(this.oShadowPanel); } else { if (!document.getElementById("grammalecte_csspanel")){ - document.head.appendChild( - oGrammalecte.createNode("link", {id: "grammalecte_csspanel", rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel.css"}) - ); - document.head.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel_gc.css"}) - ); - document.head.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel_lxg.css"}) - ); - document.head.appendChild( - oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: oGrammalecte.sExtensionUrl + "content_scripts/panel_tf.css"}) - ); + oGrammalecte.createStyle("content_scripts/panel.css", "grammalecte_csspanel", document.head); + oGrammalecte.createStyle("content_scripts/panel_gc.css", null, document.head); + oGrammalecte.createStyle("content_scripts/panel_lxg.css", null, document.head); + oGrammalecte.createStyle("content_scripts/panel_tf.css", null, document.head); } document.body.appendChild(this.xPanel); } }