diff --git a/public/manifest.json b/public/manifest.json index b2ed8d1..2d1439e 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -21,15 +21,18 @@ "content_scripts": [ { "matches": ["*://idp.gunma-u.ac.jp/pub/login.cgi*", "*://idp.gunma-u.ac.jp/pub/allotplogin_force.cgi*"], - "js": ["sso.js"] + "js": ["common.js", "sso.js"] }, { "matches": ["*://mdl.media.gunma-u.ac.jp/*"], - "js": ["moodle.js"] + "js": ["common.js", "moodle.js"] }, { "matches": ["*://*.kyomu-sys.gunma-u.ac.jp/*"], - "js": ["kyomu.js"] + "js": ["common.js","kyomu.js"] + },{ + "matches": ["*://www.media.gunma-u.ac.jp/*"], + "js": ["common.js","media.js"] } ] } diff --git a/src/Kyomu/index.ts b/src/Kyomu/index.ts deleted file mode 100644 index 3c80bb0..0000000 --- a/src/Kyomu/index.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { addRainbowBg, addRainbowText } from "../utils/addClass"; -import changeQueryInnerHTML from "../utils/changeQueryInnerHTML"; - -export default class Kyomu { - static EnableRainbow() { - // ログインボタン - // https://qiita.com/Sekky0905/items/a88721f2af41050c93f2 - const loginBtn: HTMLInputElement = document.getElementById("ctl21_btnLoginShibbolethGunma"); - if (loginBtn) { - loginBtn.value = "群馬大学ゲーミング\nアカウントでログイン"; - } - - // ページ遷移リンク - addRainbowText(".commonTopPageLink", ".commonTopPageLinkWithPadding"); - - addRainbowText( - "#CtlInfLstBfrLginEmrgncy_LblTitle", - "#CtlInfLstBfrLginNrml_LblTitle", - "#AllAnnualList_LblTitle", - "#JeLblSyllabiHeader_lbl", - ); - addRainbowBg(".infoListEntryOrgName"); - addRainbowBg(".infoListBeforeLoginGrid"); - - // ログイン後のトップページ - addRainbowBg(".top_title_header", ".top_now_title"); - - // トップページのウェルカムメッセージ - changeQueryInnerHTML(["#loginHeader_lblWelcome_1_lbl"], "よおこそ、群馬大学ゲーミング教務システムへ"); - changeQueryInnerHTML( - ["#loginHeader_lblWelcome_2_lbl"], - "このサイトでは、プレーヤーの群馬大学での𝑮𝒂𝒎𝒊𝒏𝒈 𝑳𝒊𝒇𝒆 𝑺𝒕𝒚𝒍𝒆をいい感じにします", - ); - - // トップページのお知らせ - changeQueryInnerHTML(["#AllAnnualList_LblTitle"], "ゲーミング ライフ スタイル"); - - // 受信メッセージ一覧 - addRainbowBg("#ctl00_phContents_ctlMesReceive_gridMes tr"); - } - static DisableRainbow() {} -} diff --git a/src/Moodle/index.ts b/src/Moodle/index.ts deleted file mode 100644 index db53d19..0000000 --- a/src/Moodle/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import DisableRainbow from "./DisableRainbow"; -import EnableRainbow from "./EnableRainbow"; - -export const HeaderAppendText = " Gaming Edition🎮"; - -export default class Moodle { - static EnableRainbow() { - EnableRainbow(); - } - - static DisableRainbow() { - DisableRainbow(); - } -} diff --git a/src/SSO/index.ts b/src/SSO/index.ts deleted file mode 100644 index 192d740..0000000 --- a/src/SSO/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import EnableRainbow from "./EnableRainbow"; - -export default class SSO { - static EnableRainbow() { - EnableRainbow(); - } - static DisableRainbow() { - //DisableRainbow(); - } -} diff --git a/src/class/GundaiWebsite/index.ts b/src/class/GundaiWebsite/index.ts new file mode 100644 index 0000000..5d2b779 --- /dev/null +++ b/src/class/GundaiWebsite/index.ts @@ -0,0 +1,10 @@ +export default class GundaiWebSite { + HeaderAppendText: string; + EnableRainbow: () => void; + DisableRainbow: () => void; + constructor() { + this.HeaderAppendText = ""; + this.EnableRainbow = () => {}; + this.DisableRainbow = () => {}; + } +} diff --git a/src/class/Kyomu/index.ts b/src/class/Kyomu/index.ts new file mode 100644 index 0000000..0a6f9a5 --- /dev/null +++ b/src/class/Kyomu/index.ts @@ -0,0 +1,45 @@ +import { addRainbowBg, addRainbowText } from "../../utils/addClass"; +import changeQueryInnerHTML from "../../utils/changeQueryInnerHTML"; +import GundaiWebSite from "../GundaiWebsite"; + +export default class Kyomu extends GundaiWebSite { + constructor() { + super(); + this.EnableRainbow = () => { + // ログインボタン + // https://qiita.com/Sekky0905/items/a88721f2af41050c93f2 + const loginBtn: HTMLInputElement = document.getElementById("ctl21_btnLoginShibbolethGunma"); + if (loginBtn) { + loginBtn.value = "群馬大学ゲーミング\nアカウントでログイン"; + } + + // ページ遷移リンク + addRainbowText(".commonTopPageLink", ".commonTopPageLinkWithPadding"); + + addRainbowText( + "#CtlInfLstBfrLginEmrgncy_LblTitle", + "#CtlInfLstBfrLginNrml_LblTitle", + "#AllAnnualList_LblTitle", + "#JeLblSyllabiHeader_lbl", + ); + addRainbowBg(".infoListEntryOrgName"); + addRainbowBg(".infoListBeforeLoginGrid"); + + // ログイン後のトップページ + addRainbowBg(".top_title_header", ".top_now_title"); + + // トップページのウェルカムメッセージ + changeQueryInnerHTML(["#loginHeader_lblWelcome_1_lbl"], "よおこそ、群馬大学ゲーミング教務システムへ"); + changeQueryInnerHTML( + ["#loginHeader_lblWelcome_2_lbl"], + "このサイトでは、プレーヤーの群馬大学での𝑮𝒂𝒎𝒊𝒏𝒈 𝑳𝒊𝒇𝒆 𝑺𝒕𝒚𝒍𝒆をいい感じにします", + ); + + // トップページのお知らせ + changeQueryInnerHTML(["#AllAnnualList_LblTitle"], "ゲーミング ライフ スタイル"); + + // 受信メッセージ一覧 + addRainbowBg("#ctl00_phContents_ctlMesReceive_gridMes tr"); + }; + } +} diff --git a/src/class/Media/index.ts b/src/class/Media/index.ts new file mode 100644 index 0000000..6df406f --- /dev/null +++ b/src/class/Media/index.ts @@ -0,0 +1,7 @@ +import GundaiWebSite from "../GundaiWebsite"; + +export default class MediaCenter extends GundaiWebSite { + constructor() { + super(); + } +} diff --git a/src/Moodle/DisableRainbow.ts b/src/class/Moodle/DisableRainbow.ts similarity index 79% rename from src/Moodle/DisableRainbow.ts rename to src/class/Moodle/DisableRainbow.ts index babe392..41fa305 100644 --- a/src/Moodle/DisableRainbow.ts +++ b/src/class/Moodle/DisableRainbow.ts @@ -1,5 +1,5 @@ -import { removeRainbowBg } from "../utils/addClass"; -import changeQueryInnerHTML from "../utils/changeQueryInnerHTML"; +import { removeRainbowBg } from "../../utils/addClass"; +import changeQueryInnerHTML from "../../utils/changeQueryInnerHTML"; import { HeaderAppendText } from "."; export const DisableRainbow = () => { diff --git a/src/Moodle/EnableRainbow.ts b/src/class/Moodle/EnableRainbow.ts similarity index 89% rename from src/Moodle/EnableRainbow.ts rename to src/class/Moodle/EnableRainbow.ts index 00bb894..67810d3 100644 --- a/src/Moodle/EnableRainbow.ts +++ b/src/class/Moodle/EnableRainbow.ts @@ -1,5 +1,5 @@ -import { addRainbowBg, addRainbowText } from "../utils/addClass"; -import changeQueryInnerHTML from "../utils/changeQueryInnerHTML"; +import { addRainbowBg, addRainbowText } from "../../utils/addClass"; +import changeQueryInnerHTML from "../../utils/changeQueryInnerHTML"; import { HeaderAppendText } from "."; export const EnableRainbow = () => { diff --git a/src/class/Moodle/index.ts b/src/class/Moodle/index.ts new file mode 100644 index 0000000..c8f799f --- /dev/null +++ b/src/class/Moodle/index.ts @@ -0,0 +1,13 @@ +import GundaiWebSite from "../GundaiWebsite"; +import DisableRainbow from "./DisableRainbow"; +import EnableRainbow from "./EnableRainbow"; + +export const HeaderAppendText = " Gaming Edition🎮"; + +export default class Moodle extends GundaiWebSite { + constructor() { + super(); + this.EnableRainbow = EnableRainbow; + this.DisableRainbow = DisableRainbow; + } +} diff --git a/src/SSO/EnableRainbow.ts b/src/class/SSO/EnableRainbow.ts similarity index 68% rename from src/SSO/EnableRainbow.ts rename to src/class/SSO/EnableRainbow.ts index 4306b4c..a05f587 100644 --- a/src/SSO/EnableRainbow.ts +++ b/src/class/SSO/EnableRainbow.ts @@ -1,5 +1,5 @@ -import { addClass } from "../utils/addClass"; -import changeQueryInnerHTML from "../utils/changeQueryInnerHTML"; +import { addClass } from "../../utils/addClass"; +import changeQueryInnerHTML from "../../utils/changeQueryInnerHTML"; export const EnableRainbow = () => { addClass([".header_column", ".input_form", ".input_column"], ["rainbow-bg"]); diff --git a/src/class/SSO/index.ts b/src/class/SSO/index.ts new file mode 100644 index 0000000..632bb78 --- /dev/null +++ b/src/class/SSO/index.ts @@ -0,0 +1,9 @@ +import GundaiWebSite from "../GundaiWebsite"; +import EnableRainbow from "./EnableRainbow"; + +export default class SSO extends GundaiWebSite { + constructor() { + super(); + this.EnableRainbow = EnableRainbow; + } +} diff --git a/src/content_kyomu.ts b/src/content_kyomu.ts deleted file mode 100644 index b21d58c..0000000 --- a/src/content_kyomu.ts +++ /dev/null @@ -1,13 +0,0 @@ -import "./styles/gaming.scss"; -import "./styles/kyomu.scss"; - -import Kyomu from "./Kyomu"; -import runIfEnabled from "./utils/runIfEnabled"; - -window.addEventListener("load", async () => await runIfEnabled(Kyomu.EnableRainbow)); - -chrome.runtime.onMessage.addListener((message) => { - if (message === "reload") { - location.reload(); - } -}); diff --git a/src/content_moodle.ts b/src/content_moodle.ts deleted file mode 100644 index 6510bae..0000000 --- a/src/content_moodle.ts +++ /dev/null @@ -1,24 +0,0 @@ -//import addClass from "./utils/addClass"; -import "./styles/moodle.scss"; -import "./styles/gaming.scss"; - -import Moodle from "./Moodle"; -import runIfEnabled from "./utils/runIfEnabled"; - -window.addEventListener("load", async () => await runIfEnabled(Moodle.EnableRainbow)); - -chrome.runtime.onMessage.addListener((message) => { - if (message === "reload") location.reload(); -}); - -// あとでリロード無しでゲーミングモード解除を実装する -/* -chrome.action.onClicked.addListener(async () => { - const isEnable = await isEnabled(); - if (isEnable) { - EnableRainbow(); - } else { - DisableRainbow(); - } -}); -*/ diff --git a/src/content_sso.ts b/src/content_sso.ts deleted file mode 100644 index 383e031..0000000 --- a/src/content_sso.ts +++ /dev/null @@ -1,13 +0,0 @@ -import "./styles/gaming.scss"; -import "./styles/sso.scss"; - -import SSO from "./SSO"; -import runIfEnabled from "./utils/runIfEnabled"; - -window.addEventListener("load", async () => await runIfEnabled(SSO.EnableRainbow)); - -chrome.runtime.onMessage.addListener((message) => { - if (message === "reload") { - location.reload(); - } -}); diff --git a/src/background.ts b/src/scripts/background.ts similarity index 84% rename from src/background.ts rename to src/scripts/background.ts index ff2bfc6..18791d8 100644 --- a/src/background.ts +++ b/src/scripts/background.ts @@ -1,5 +1,5 @@ -import getIsEnabled from "./utils/getIsEnabled"; -import { storage } from "./utils/storage"; +import getIsEnabled from "../utils/getIsEnabled"; +import { storage } from "../utils/storage"; chrome.runtime.onInstalled.addListener(() => { storage.set({ enabled: true }); diff --git a/src/scripts/content_common.ts b/src/scripts/content_common.ts new file mode 100644 index 0000000..59df46a --- /dev/null +++ b/src/scripts/content_common.ts @@ -0,0 +1,8 @@ +import "../styles/gaming.scss"; +import "../styles/kyomu.scss"; + +chrome.runtime.onMessage.addListener((message) => { + if (message === "reload") { + location.reload(); + } +}); diff --git a/src/scripts/content_kyomu.ts b/src/scripts/content_kyomu.ts new file mode 100644 index 0000000..985fd25 --- /dev/null +++ b/src/scripts/content_kyomu.ts @@ -0,0 +1,4 @@ +import Kyomu from "../class/Kyomu"; +import loadGamingWebsite from "../utils/loadGamingWebsite"; + +loadGamingWebsite(new Kyomu()); diff --git a/src/scripts/content_media.ts b/src/scripts/content_media.ts new file mode 100644 index 0000000..f0cea97 --- /dev/null +++ b/src/scripts/content_media.ts @@ -0,0 +1 @@ +window.addEventListener("load", () => {}); diff --git a/src/scripts/content_moodle.ts b/src/scripts/content_moodle.ts new file mode 100644 index 0000000..dc63254 --- /dev/null +++ b/src/scripts/content_moodle.ts @@ -0,0 +1,17 @@ +import Moodle from "../class/Moodle"; +import loadGamingWebsite from "../utils/loadGamingWebsite"; + +//window.addEventListener("load", async () => await runFuncIfEnabled(Moodle.EnableRainbow)); +loadGamingWebsite(new Moodle()); + +// あとでリロード無しでゲーミングモード解除を実装する +/* +chrome.action.onClicked.addListener(async () => { + const isEnable = await isEnabled(); + if (isEnable) { + EnableRainbow(); + } else { + DisableRainbow(); + } +}); +*/ diff --git a/src/scripts/content_sso.ts b/src/scripts/content_sso.ts new file mode 100644 index 0000000..0e67306 --- /dev/null +++ b/src/scripts/content_sso.ts @@ -0,0 +1,6 @@ +import SSO from "../class/SSO"; +import loadGamingWebsite from "../utils/loadGamingWebsite"; + +//window.addEventListener("load", async () => await runFuncIfEnabled(SSO.EnableRainbow)); + +loadGamingWebsite(new SSO()); diff --git a/src/utils/loadGamingWebsite.ts b/src/utils/loadGamingWebsite.ts new file mode 100644 index 0000000..1cad03e --- /dev/null +++ b/src/utils/loadGamingWebsite.ts @@ -0,0 +1,6 @@ +import GundaiWebSite from "../class/GundaiWebsite"; +import runFuncIfEnabled from "./runFuncIfEnabled"; + +export default function loadGamingWebsite(website: GundaiWebSite) { + window.addEventListener("load", async () => await runFuncIfEnabled(website.EnableRainbow)); +} diff --git a/src/utils/runIfEnabled.ts b/src/utils/runFuncIfEnabled.ts similarity index 66% rename from src/utils/runIfEnabled.ts rename to src/utils/runFuncIfEnabled.ts index a893f8a..13a9c81 100644 --- a/src/utils/runIfEnabled.ts +++ b/src/utils/runFuncIfEnabled.ts @@ -1,6 +1,6 @@ import getIsEnabled from "./getIsEnabled"; -export default async function runIfEnabled(func: () => void) { +export default async function runFuncIfEnabled(func: () => void) { const isEnable = await getIsEnabled(); if (isEnable) { func(); diff --git a/webpack.config.js b/webpack.config.js index b40c269..e08467b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,18 +1,25 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -const Path = require("path"); +const path = require("path"); +const fs = require("fs"); const CopyPlugin = require("copy-webpack-plugin"); const ESLintPlugin = require("eslint-webpack-plugin"); +const loadFilesInScripts = function () { + const dir = path.join(__dirname, "src/scripts"); + const files = fs.readdirSync(dir); + const entry = {}; + files.forEach(function (file) { + const name = file.replace(".ts", "").replace("content_", ""); + entry[name] = path.join(dir, file); + }); + return entry; +}; + module.exports = { - entry: { - sso: "./src/content_sso.ts", - moodle: "./src/content_moodle.ts", - kyomu: "./src/content_kyomu.ts", - background: "./src/background.ts", - }, + entry: loadFilesInScripts(), output: { - path: Path.join(__dirname, "dist"), + path: path.join(__dirname, "dist"), clean: true, },