From e36a46b1cbba74fc83a43f9389fd91ca2c9501e3 Mon Sep 17 00:00:00 2001 From: hide_d Date: Thu, 16 Dec 2021 03:23:11 +0900 Subject: [PATCH] =?UTF-8?q?refacor:=20customCSS=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/ts/common_deprecated.ts | 14 +++++--------- hwe/ts/legacy/main.ts | 8 ++------ hwe/ts/util/customCSS.ts | 9 +++++++++ 3 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 hwe/ts/util/customCSS.ts diff --git a/hwe/ts/common_deprecated.ts b/hwe/ts/common_deprecated.ts index 90131575..3aa4e772 100644 --- a/hwe/ts/common_deprecated.ts +++ b/hwe/ts/common_deprecated.ts @@ -11,21 +11,17 @@ import { nl2br } from "@util/nl2br"; import jQuery from "jquery"; import "@scss/common_legacy.scss"; +import { insertCustomCSS } from "./util/customCSS"; +import { htmlReady } from "./util/htmlReady"; exportWindow(jQuery, '$'); exportWindow(jQuery, 'jQuery'); -jQuery(function ($) { +htmlReady(function(){ initTooltip(); activateFlip(); - - const customCSS = localStorage.getItem('sam_customCSS'); - if (customCSS) { - const $style = $(''); - $style.text(customCSS); - $style.appendTo($('head')); - } -}); + insertCustomCSS(); +}) /** * {0}, {1}, {2}형태로 포맷해주는 함수 diff --git a/hwe/ts/legacy/main.ts b/hwe/ts/legacy/main.ts index c681ac97..d72a9aae 100644 --- a/hwe/ts/legacy/main.ts +++ b/hwe/ts/legacy/main.ts @@ -6,6 +6,7 @@ import { initTooltip } from './initTooltip'; import { exportWindow } from '@/util/exportWindow'; import { reloadWorldMap } from '@/map'; import { refreshMsg } from '@/msg'; +import { insertCustomCSS } from '@/util/customCSS'; exportWindow(jQuery, '$'); @@ -50,12 +51,7 @@ htmlReady(() => { void refreshMsg(); }, 5000); - const customCSS = localStorage.getItem('sam_customCSS'); - if (customCSS) { - const styleEl = document.createElement('style'); - styleEl.innerHTML = customCSS; - document.head.appendChild(styleEl); - } + insertCustomCSS(); }); (() => { diff --git a/hwe/ts/util/customCSS.ts b/hwe/ts/util/customCSS.ts new file mode 100644 index 00000000..29e55eff --- /dev/null +++ b/hwe/ts/util/customCSS.ts @@ -0,0 +1,9 @@ +export function insertCustomCSS(key = 'sam_customCSS'){ + const customCSS = localStorage.getItem(key); + if (customCSS) { + const css = document.createElement('style'); + css.innerHTML = customCSS; + console.log(css); + document.getElementsByTagName('head')[0].appendChild(css); + } +}