Skip to content

Commit

Permalink
Update: Use base class and function
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Oct 14, 2023
1 parent d74684b commit c7b29ce
Show file tree
Hide file tree
Showing 24 changed files with 156 additions and 136 deletions.
9 changes: 6 additions & 3 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
]
}
42 changes: 0 additions & 42 deletions src/Kyomu/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/Moodle/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/SSO/index.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/class/GundaiWebsite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default class GundaiWebSite {
HeaderAppendText: string;
EnableRainbow: () => void;
DisableRainbow: () => void;
constructor() {
this.HeaderAppendText = "";
this.EnableRainbow = () => {};
this.DisableRainbow = () => {};
}
}
45 changes: 45 additions & 0 deletions src/class/Kyomu/index.ts
Original file line number Diff line number Diff line change
@@ -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 = <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");
};
}
}
7 changes: 7 additions & 0 deletions src/class/Media/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import GundaiWebSite from "../GundaiWebsite";

export default class MediaCenter extends GundaiWebSite {
constructor() {
super();
}
}
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
13 changes: 13 additions & 0 deletions src/class/Moodle/index.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 2 additions & 2 deletions src/SSO/EnableRainbow.ts → src/class/SSO/EnableRainbow.ts
Original file line number Diff line number Diff line change
@@ -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"]);
Expand Down
9 changes: 9 additions & 0 deletions src/class/SSO/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import GundaiWebSite from "../GundaiWebsite";
import EnableRainbow from "./EnableRainbow";

export default class SSO extends GundaiWebSite {
constructor() {
super();
this.EnableRainbow = EnableRainbow;
}
}
13 changes: 0 additions & 13 deletions src/content_kyomu.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/content_moodle.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/content_sso.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/background.ts → src/scripts/background.ts
Original file line number Diff line number Diff line change
@@ -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 });
Expand Down
8 changes: 8 additions & 0 deletions src/scripts/content_common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "../styles/gaming.scss";
import "../styles/kyomu.scss";

chrome.runtime.onMessage.addListener((message) => {
if (message === "reload") {
location.reload();
}
});
4 changes: 4 additions & 0 deletions src/scripts/content_kyomu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Kyomu from "../class/Kyomu";
import loadGamingWebsite from "../utils/loadGamingWebsite";

loadGamingWebsite(new Kyomu());
1 change: 1 addition & 0 deletions src/scripts/content_media.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.addEventListener("load", () => {});
17 changes: 17 additions & 0 deletions src/scripts/content_moodle.ts
Original file line number Diff line number Diff line change
@@ -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();
}
});
*/
6 changes: 6 additions & 0 deletions src/scripts/content_sso.ts
Original file line number Diff line number Diff line change
@@ -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());
6 changes: 6 additions & 0 deletions src/utils/loadGamingWebsite.ts
Original file line number Diff line number Diff line change
@@ -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));
}
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
23 changes: 15 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -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,
},

Expand Down

0 comments on commit c7b29ce

Please sign in to comment.