diff --git a/.eslintrc.json b/.eslintrc.json index e9d4292..5b60220 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -26,6 +26,7 @@ "HTMLMetaElement", "HTMLParagraphElement", "HTMLSpanElement", + "HTMLStyleElement", "HTMLUListElement", "Promise", "Response", diff --git a/src/js/changelog-topic.js b/src/js/changelog-topic.js index 425e033..51d56dd 100644 --- a/src/js/changelog-topic.js +++ b/src/js/changelog-topic.js @@ -1,8 +1,7 @@ import ChangelogService from "./changelog/ChangelogService"; +import { loadCss } from "./common"; -const style = document.createElement("style"); -document.getElementsByTagName("head")[0].appendChild(style); -style.appendChild(document.createTextNode(require("../css/changelog.css"))); +loadCss(require("../css/changelog.css")); /** * @param {URL} url diff --git a/src/js/changelog.js b/src/js/changelog.js index 28fc777..538bce5 100644 --- a/src/js/changelog.js +++ b/src/js/changelog.js @@ -1,9 +1,8 @@ import ChangelogList from "./changelog/ChangelogList"; import ChangelogService from "./changelog/ChangelogService"; +import { loadCss } from "./common"; -const style = document.createElement("style"); -document.getElementsByTagName("head")[0].appendChild(style); -style.appendChild(document.createTextNode(require("../css/changelog.css"))); +loadCss(require("../css/changelog.css")); /** @type {string} */ const apiBase = document.location.hostname.match(/(localhost|127\.0\.0\.1)/) ? "" : "https://bitrise.io"; @@ -42,4 +41,4 @@ if (queryLAstVisit) { changelogLoadMoreButton.remove(); changelogService.loadTopics("/changelog.json").then(topics => { changelogList.render(topics, lastVisitedDate); -}); \ No newline at end of file +});}); diff --git a/src/js/common.js b/src/js/common.js index bcf40ee..15176ba 100644 --- a/src/js/common.js +++ b/src/js/common.js @@ -83,4 +83,25 @@ function fancyConsoleLog(text) { console.log('%c' + text, tpl + 'white'); } -export {capitalize, icaseEqual, icaseIncludes, getElementTextContent, getFirstElementByClassname, getMetaTag, setMetaContent, fancyConsoleLog}; \ No newline at end of file +/** + * @param {string} cssData + * @returns {HTMLStyleElement} + */ +function loadCss(cssData) { + const style = document.createElement("style"); + document.getElementsByTagName("head")[0].appendChild(style); + style.appendChild(document.createTextNode(cssData)); + return style; +} + +export { + capitalize, + fancyConsoleLog, + getElementTextContent, + getFirstElementByClassname, + getMetaTag, + icaseEqual, + icaseIncludes, + loadCss, + setMetaContent, +}; \ No newline at end of file diff --git a/src/js/integrations.js b/src/js/integrations.js index c37a2f9..1a69e55 100644 --- a/src/js/integrations.js +++ b/src/js/integrations.js @@ -2,10 +2,9 @@ import IntegrationsService from "./integrations/IntegrationsService"; import StepListSection from "./integrations/StepListSection"; import SidebarSection from "./integrations/SidebarSection"; import { fancyConsoleLog } from "./common"; +import { loadCss } from "./common"; -const style = document.createElement("style"); -document.getElementsByTagName("head")[0].appendChild(style); -style.appendChild(document.createTextNode(require("../css/integrations.css"))); +loadCss(require("../css/integrations.css")); const url = new URL(document.location.href); const platformFilter = url.searchParams.get("platform");