From 4c12e45d4f561c7b886254d44ed80b48d1065ed5 Mon Sep 17 00:00:00 2001 From: mirusu400 Date: Sun, 31 Oct 2021 23:03:22 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Add=20build=20scripts=20for=20ex?= =?UTF-8?q?tension=20(#78)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/paths.ts | 4 +++- config/webpack.config.ts | 12 +++++++++++- package.json | 3 +++ src/main-ext.js | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/main-ext.js diff --git a/config/paths.ts b/config/paths.ts index 0d7b810..440cb72 100644 --- a/config/paths.ts +++ b/config/paths.ts @@ -9,6 +9,7 @@ interface Paths { appSrc: string; appUserscript: string; appMain: string; + appExtMain: string; } const paths: Paths = { @@ -16,7 +17,8 @@ const paths: Paths = { appDist: resolveApp('dist'), appSrc: resolveApp('src'), appUserscript: resolveApp('src/klas-helper.user.js'), - appMain: resolveApp('src/main.js') + appMain: resolveApp('src/main.js'), + appExtMain: resolveApp('src/main-ext.js') }; export default paths; \ No newline at end of file diff --git a/config/webpack.config.ts b/config/webpack.config.ts index a96d96a..bc6f333 100644 --- a/config/webpack.config.ts +++ b/config/webpack.config.ts @@ -72,4 +72,14 @@ const mainConfig: webpack.Configuration = { ...commonConfig }; -export default [userscriptConfig, mainConfig]; \ No newline at end of file +const mainExtConfig: webpack.Configuration = { + name: 'main-ext', + entry: paths.appExtMain, + output: { + filename: 'main-ext.js', + path: paths.appDist + }, + ...commonConfig +}; + +export default [userscriptConfig, mainConfig, mainExtConfig]; \ No newline at end of file diff --git a/package.json b/package.json index 11e426e..0c96bc1 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "dev:build": "cross-env NODE_ENV=development webpack --config config/webpack.config.ts --config-name userscript --progress", "dev:start": "cross-env NODE_ENV=development webpack-dev-server --config config/webpack.config.ts --config-name main --host 0.0.0.0 --watch-poll", "dev": "npm run dev:build && npm run dev:start", + "ext:build": "cross-env NODE_ENV=development webpack --config config/webpack.config.ts --config-name userscript --progress", + "ext:start": "cross-env NODE_ENV=development webpack-dev-server --config config/webpack.config.ts --config-name main-ext --host 0.0.0.0 --watch-poll", + "ext": "npm run ext:build && npm run ext:start", "lint": "eslint .", "lint:fix": "eslint . --fix", "build": "cross-env NODE_ENV=production webpack --config config/webpack.config.ts --progress" diff --git a/src/main-ext.js b/src/main-ext.js new file mode 100644 index 0000000..e8c01c7 --- /dev/null +++ b/src/main-ext.js @@ -0,0 +1,40 @@ +import routes from './routes'; +import { + insertLibrary +} from './utils/dom'; + +// 확장 프로그램은 load가 필요없습니다 +(() => { + const dependencies = [ + 'https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css', + 'https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js' + ]; + + // 의존성 삽입 + for (const url of dependencies) { + insertLibrary(url); + } + + // 메인 함수 실행 + if (Object.prototype.hasOwnProperty.call(routes, location.pathname)) { + routes[location.pathname](); + } + + // KLAS Helper 사용 여부 문구 추가 + $('.navtxt').prepend(` + + KLAS Helper 사용 중 + + `); + + // 위로 가기 버튼 위치 고정 + $('.btnup').css({ + bottom: '30px', + position: 'fixed', + right: '30px' + }); + + // 로그인 세션 유지 + setInterval(() => { fetch('/'); }, 600000); +})(); \ No newline at end of file