Skip to content

Commit

Permalink
Merge branch 'darkmode'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Oct 28, 2023
2 parents 92c1c04 + c74ba43 commit 38e4d66
Show file tree
Hide file tree
Showing 27 changed files with 373 additions and 189 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"typescript.tsserver.experimental.enableProjectDiagnostics": true
}
39 changes: 32 additions & 7 deletions Todo.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
## Todo

### ウェブサイト
### ゲーミング

- [ ] [mdl.media.gunma-u.ac.jp](https://mdl.media.gunma-u.ac.jp/GU/index.php)
- [ ] [www.kyomu-sys.gunma-u.ac.jp](https://www.kyomu-sys.gunma-u.ac.jp/Portal/)
- [ ] [www.media.gunma-u.ac.jp](https://www.media.gunma-u.ac.jp/)
- [ ] [www.gunma-u.ac.jp](https://www.gunma-u.ac.jp/)
- SSOログイン画面
- [x] 基本的な実装
- [ ] 見やすさの改善
- [mdl.media.gunma-u.ac.jp](https://mdl.media.gunma-u.ac.jp/GU/index.php)
- [x] 基本的な実装
- [www.kyomu-sys.gunma-u.ac.jp](https://www.kyomu-sys.gunma-u.ac.jp/Portal/)
- [x] 基本的な実装
- [www.media.gunma-u.ac.jp](https://www.media.gunma-u.ac.jp/)
- [x] 基本的な実装
- [opac.lib.gunma-u.ac.jp](https://opac.lib.gunma-u.ac.jp/opc/)
- [x] 基本的な実装
- [www.gunma-u.ac.jp](https://www.gunma-u.ac.jp/)
- [ ] 基本的な実装

### ダークモード

- SSOログイン画面
- [ ] 基本的な実装
- [mdl.media.gunma-u.ac.jp](https://mdl.media.gunma-u.ac.jp/GU/index.php)
- [ ] 基本的な実装
- [www.kyomu-sys.gunma-u.ac.jp](https://www.kyomu-sys.gunma-u.ac.jp/Portal/)
- [ ] 基本的な実装
- [www.media.gunma-u.ac.jp](https://www.media.gunma-u.ac.jp/)
- [ ] 基本的な実装
- [opac.lib.gunma-u.ac.jp](https://opac.lib.gunma-u.ac.jp/opc/)
- [ ] 基本的な実装
- [www.gunma-u.ac.jp](https://www.gunma-u.ac.jp/)
- [ ] 基本的な実装

### 開発

- [ ] [webpack-chrome-extension-reloader](https://www.npmjs.com/package/webpack-chrome-extension-reloader)でホットリロードに対応する
- [ ] SCSSで直にスタイルを書き込んだ場合に無効化できない問題を修正する
- [x] SCSSで直にスタイルを書き込んだ場合に無効化できない問題を修正する
- [ ] リロードなしで有効化/無効化できるようにする
- [ ] Reactコンポーネントを最適化する
- [ ] テストを書く
- [ ] ドキュメントを書く
- [ ] 設定を開いている間はポップアップを無効化する
- [x] 設定を開いている間はポップアップを無効化する
- [ ] ポップアップでの設定変更後に手動でリロードする必要がある問題を修正する
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"webpack-merge": "^5.10.0"
},
"volta": {
"node": "18.18.1"
"node": "20.9.0"
},
"dependencies": {
"classnames": "^2.3.2",
Expand Down
83 changes: 83 additions & 0 deletions src/class/ClassApplicator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { addClass, Elements, removeClass } from "../utils/addClass";

const rainbowBg = "rainbow-bg";
const rainbowText = "rainbow-text";
const rainbowBgShadow = "rainbow-bg-shadow";
const rainbowTextShadow = "rainbow-text-shadow";

// 要素にclassNameを追加します
// baseとclassesで追加するclassNameを指定し、applyで適用、removeで削除します
// selectorで適用されるセレクタを取得できます
// baseは初期化に必ず指定する必要があり書き換えるべきではありませんが、classesは追加で個別の設定を行うために指定できます
export class classApplicator {
#base: string[];
classes: string[];
constructor(base: string[]) {
this.#base = base;
this.classes = [];
}

apply(...elements: Elements[]) {
addClass(elements, [...this.#base, ...this.classes]);
}
remove(...elements: Elements[]) {
removeClass(elements, [...this.#base, ...this.classes]);
}
selector() {
if (this.classes.length === 0) return `.${this.#base}`;
else return `.${this.#base}.${this.classes.join(".")}`;
}
}

export class ApplicatorBase {
enable() {}
disable() {}
}

// classApplicatorを用いて虹色にするクラス
export class RainbowApplicator extends ApplicatorBase {
text: classApplicator;
bg: classApplicator;
textShadow: classApplicator;
bgShadow: classApplicator;

constructor() {
super();
this.text = new classApplicator([rainbowText]);
this.bg = new classApplicator([rainbowBg]);
this.textShadow = new classApplicator([rainbowText, rainbowTextShadow]);
this.bgShadow = new classApplicator([rainbowBg, rainbowBgShadow]);
}
}

// 隠し機能を有効化するクラス
export class HiddenApplicator extends ApplicatorBase {}

// classApplicatorを用いてダークテーマにするクラス
export class DarkApplicator extends ApplicatorBase {
bgBase: classApplicator;
bgBaseDarker: classApplicator;
bgContent: classApplicator;
bgNeutral: classApplicator;
bgAccent: classApplicator;
textBase: classApplicator;
textBaseDarker: classApplicator;
textContent: classApplicator;
textNeutral: classApplicator;
textAccent: classApplicator;

constructor() {
super();

this.bgBase = new classApplicator(["bg-base"]);
this.bgBaseDarker = new classApplicator(["bg-base-darker"]);
this.bgContent = new classApplicator(["bg-content"]);
this.bgNeutral = new classApplicator(["bg-neutral"]);
this.bgAccent = new classApplicator(["bg-accent"]);
this.textBase = new classApplicator(["text-base"]);
this.textBaseDarker = new classApplicator(["text-base-darker"]);
this.textContent = new classApplicator(["text-content"]);
this.textNeutral = new classApplicator(["text-neutral"]);
this.textAccent = new classApplicator(["text-accent"]);
}
}
16 changes: 8 additions & 8 deletions src/class/Kyomu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GundaiWebSite } from "../UnivWebsite";

export const Kyomu = new GundaiWebSite("kyomu");

Kyomu.enableRainbow = function () {
Kyomu.rainbow.enable = function () {
// ログインボタン
// https://qiita.com/Sekky0905/items/a88721f2af41050c93f2
const loginBtn: HTMLInputElement = <HTMLInputElement>document.getElementById("ctl21_btnLoginShibbolethGunma");
Expand All @@ -14,19 +14,19 @@ Kyomu.enableRainbow = function () {
}

// ページ遷移リンク
this.rainbowText.apply(".commonTopPageLink", ".commonTopPageLinkWithPadding");
this.text.apply(".commonTopPageLink", ".commonTopPageLinkWithPadding");

this.rainbowText.apply(
this.text.apply(
"#CtlInfLstBfrLginEmrgncy_LblTitle",
"#CtlInfLstBfrLginNrml_LblTitle",
"#AllAnnualList_LblTitle",
"#JeLblSyllabiHeader_lbl",
);
this.rainbowBg.apply(".infoListEntryOrgName");
this.rainbowBg.apply(".infoListBeforeLoginGrid");
this.bg.apply(".infoListEntryOrgName");
this.bg.apply(".infoListBeforeLoginGrid");

// ログイン後のトップページ
this.rainbowBg.apply(".top_title_header", ".top_now_title");
this.bg.apply(".top_title_header", ".top_now_title");

// トップページのウェルカムメッセージ
changeQueryInnerHTML("#loginHeader_lblWelcome_1_lbl", "よおこそ、群馬大学ゲーミング教務システムへ");
Expand All @@ -39,7 +39,7 @@ Kyomu.enableRainbow = function () {
changeQueryInnerHTML("#AllAnnualList_LblTitle", "ゲーミング ライフ スタイル");

// 受信メッセージ一覧
this.rainbowBgShadow.apply("#ctl00_phContents_ctlMesReceive_gridMes tr");
this.bgShadow.apply("#ctl00_phContents_ctlMesReceive_gridMes tr");

// リンクを挿入
if (["/portal/login.aspx", "/portal/"].includes(location.pathname.toLowerCase())) {
Expand All @@ -52,5 +52,5 @@ Kyomu.enableRainbow = function () {
}

//ヘッダー上部の名前
this.rainbowText.apply("#ctl00_bhHeader_lblName");
this.text.apply("#ctl00_bhHeader_lblName");
};
12 changes: 6 additions & 6 deletions src/class/Media/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import { GundaiWebSite } from "../UnivWebsite";

export const Media = new GundaiWebSite("media");
Media.enableRainbow = function () {
this.rainbowBgShadow.apply(".banner_list li");
this.rainbowBgShadow.apply(".banner_list li a");
this.rainbowBgShadow.apply(".menu_category h3");
this.rainbowText.apply("#news_list li a");
this.rainbowBg.apply("#news_category_list .active");
Media.rainbow.enable = function () {
this.bgShadow.apply(".banner_list li");
this.bgShadow.apply(".banner_list li a");
this.bgShadow.apply(".menu_category h3");
this.text.apply("#news_list li a");
this.bg.apply("#news_category_list .active");
};
12 changes: 0 additions & 12 deletions src/class/Moodle/DisableRainbow.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/class/Moodle/disable-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import changeQueryInnerHTML from "../../utils/changeQueryInnerHTML";
import { RainbowApplicator } from "../ClassApplicator";

export const DisableRainbowBg = (rainbow: RainbowApplicator) => {
rainbow.bg.remove(".navbar", ".addinghtml");
rainbow.bg.remove(".page-header-headings h1");
rainbow.bg.remove("a");
};

export const ReplaceImagesToDefault = () => {
changeQueryInnerHTML("#instance-320-header", "現在のログイン人数");
};
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
import { removeClass } from "../../utils/addClass";
import changeQueryInnerHTML from "../../utils/changeQueryInnerHTML";
import { RainbowApplicator } from "../ClassApplicator";
import { GundaiWebSite } from "../UnivWebsite";
import { Moodle } from "./type";
import { MoodleAdditionalInfo } from "./type";

export const EnableRainbowTextAndBg = (moodle: Moodle) => {
moodle.rainbowBg.apply(".navbar", "#action-menu-0-menu");
export const enableRainbowTextAndBg = (rainbow: RainbowApplicator) => {
rainbow.bg.apply(".navbar", "#action-menu-0-menu");

moodle.rainbowText.apply(".page-header-headings h1");
moodle.rainbowText.apply("#page-content a:not(#inst301 a)");
moodle.rainbowText.apply("#instance-301-header");
rainbow.text.apply(".page-header-headings h1");
rainbow.text.apply("#page-content a:not(#inst301 a)");
rainbow.text.apply("#instance-301-header");

// rainbowBgの中のrainbowTextを無効化
const rainbowBgSelector = moodle.rainbowBg.selector();
const targetElementsSelector = `${rainbowBgSelector} ${moodle.rainbowText.selector()}`;
removeClass([targetElementsSelector], moodle.rainbowText.base);
const rainbowBgSelector = rainbow.bg.selector();
const targetElementsSelector = `${rainbowBgSelector} ${rainbow.text.selector()}`;
//removeClass([targetElementsSelector], rainbow.text.base);
rainbow.text.remove(targetElementsSelector);
};

export const InjectLink = () => {
export const injectLink = () => {
const supportSection = document.querySelector(".footer-support-link");
if (supportSection)
supportSection.innerHTML =
supportSection.innerHTML +
`<a href="https://twitter.com/Hayao0819" target="blank" class="rainbow-text">Gaming Edition開発者に連絡する<i class="icon fa fa-external-link fa-fw ml-1" aria-hidden="true"></i></a>`;
};

export const ReplaceImagesToGamimg = () => {
export const replaceLMSLogo = () => {
document.querySelectorAll(".logo").forEach((e) => {
if (e.getAttribute("src")) e.setAttribute("src", chrome.runtime.getURL("assets/GULMS.png"));
});
};

export const replaceImagesToGamimg = () => {
document.querySelectorAll("img.userpicture").forEach((e) => {
if (e.getAttribute("src")) e.setAttribute("src", chrome.runtime.getURL("assets/partyparrot.gif"));
});
};

export const ReplaceTextToGaimg = (moodle: GundaiWebSite<MoodleAdditionalInfo>) => {
export const replaceTextToGaimg = (moodle: GundaiWebSite<MoodleAdditionalInfo>) => {
const headerText = moodle.additionalInfo.headerText;

document.querySelectorAll(".page-header-headings h1").forEach((e) => {
Expand Down
41 changes: 31 additions & 10 deletions src/class/Moodle/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// 情報の信頼性は社会の構築において重要な要素である
// 個人の信頼性は家庭の構築において重要な要素である
import { GundaiWebSite } from "../UnivWebsite";
import { DisableRainbowBg, ReplaceImagesToDefault } from "./DisableRainbow";
import { EnableRainbowTextAndBg, InjectLink, ReplaceImagesToGamimg, ReplaceTextToGaimg } from "./EnableRainbow";
import { DisableRainbowBg, ReplaceImagesToDefault } from "./disable-utils";
import { enableRainbowTextAndBg, injectLink, replaceImagesToGamimg, replaceLMSLogo, replaceTextToGaimg } from "./enable-utils";
import { MoodleAdditionalInfo } from "./type";

export const Moodle = new GundaiWebSite<MoodleAdditionalInfo>("moodle");
Moodle.additionalInfo = {
headerText: " Gaming Edition🎮",
};

Moodle.enableRainbow = function () {
EnableRainbowTextAndBg(this);
InjectLink();
ReplaceImagesToGamimg();
ReplaceTextToGaimg(this);
Moodle.rainbow.enable = function () {
enableRainbowTextAndBg(this);
injectLink();
replaceImagesToGamimg();
replaceTextToGaimg(Moodle);
replaceLMSLogo();

// メニューバーでホバー時にclassを追加
document.querySelectorAll(".moremenu .nav-link").forEach((e) => {
Expand All @@ -30,21 +31,41 @@ Moodle.enableRainbow = function () {
});
};

Moodle.disableRainbow = function () {
Moodle.rainbow.disable = function () {
DisableRainbowBg(this);
ReplaceImagesToDefault();
ReplaceImagesToDefault();

const headerText = this.additionalInfo.headerText;
const headerText = Moodle.additionalInfo.headerText;
document.querySelectorAll(".page-header-headings h1").forEach((e) => {
if (e.innerHTML.includes(headerText)) e.innerHTML.replace(headerText, "");
});
};

Moodle.enableHidden = () => {
Moodle.hidden.enable = () => {
const cardElement = document.querySelector(".card-text .no-overflow");
if (!cardElement) return;
const playCountUnderTextElement = cardElement.getElementsByTagName("p")[1];
if (!playCountUnderTextElement) return;

playCountUnderTextElement.innerHTML = "想定最大利用者乳首数:4,000";
};

Moodle.dark.enable = function () {
// 画像差し替え
replaceLMSLogo();

// トップページ
Moodle.dark.bgBase.apply("#page,#page.drawers .main-inner,#region-main");
this.textContent.apply("#page");
this.bgNeutral.apply(".activity-item .description .activity-altcontent.course-description-item");
this.bgBase.apply(".bg-white");

// Header
this.textContent.apply(".navbar-light .navbar-nav .nav-link");
this.textAccent.apply(".navbar-nav .nav-link.active");
this.textContent.apply(".primary-navigation .navigation .nav-link");

// dashboard
this.bgBase.apply(".card-body");
};
8 changes: 4 additions & 4 deletions src/class/MyLibrary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GundaiWebSite } from "../UnivWebsite";

export const MyLibrary = new GundaiWebSite("mylibrary");

MyLibrary.enableRainbow = function () {
MyLibrary.rainbow.enable = function () {
if (location.pathname == "/portal/portal/selectLogin/") {
//document.getElementById("explanation")
ChangeQueryInnerHTML(
Expand All @@ -13,11 +13,11 @@ MyLibrary.enableRainbow = function () {
ChangeQueryInnerHTML("#ssoLoginTitle", "全学ゲーミングアカウントでログイン");

// フッターをレインボー
this.rainbowBg.apply("#footer");
this.bg.apply("#footer");
document.getElementById("footer")!.id = "";
}

// ヘッダーとタイトルをレインボー
this.rainbowBg.apply("#header", "h2");
this.rainbowText.apply("#lblTitle", "#mainTitle");
this.bg.apply("#header", "h2");
this.text.apply("#lblTitle", "#mainTitle");
};
Loading

0 comments on commit 38e4d66

Please sign in to comment.