Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Nov 10, 2023
2 parents 5b74294 + c7f028b commit b55e37e
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 111 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,27 @@ jobs:
run: ./devtools.sh init

- name: Build
run: pnpm run build-chrome
run: |
pnpm run build-chrome
pnpm run build-firefox
- name: Compress files
uses: vimtor/[email protected]
with:
files: dist/
dest: gaming-gundai.zip
files: dist/chrome
dest: gaming-gundai-chrome.zip

- name: Compress files
uses: vimtor/[email protected]
with:
files: dist/firefox
dest: gaming-gundai-firefox.zip

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: gaming-gundai.zip
files: |
gaming-gundai-chrome.zip
gaming-gundai-firefox.zip
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "gunma-univ-gaming-edition",
"description": "The browser extension of Gunma University Gaming Edition",
"license": "MIT",
"version": "2.1.0",
"version": "2.1.1",
"scripts": {
"build": "pnpm run build-chrome",
"build:dev": "pnpm run build-chrome:dev",
Expand Down Expand Up @@ -30,6 +30,7 @@
"@types/node": "^20.8.10",
"@types/react": "^18.2.36",
"@types/react-dom": "^18.2.14",
"@types/webextension-polyfill": "^0.10.6",
"@types/webpack": "^5.28.4",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
Expand Down Expand Up @@ -71,6 +72,7 @@
"ts-node": "^10.9.1",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.2.2",
"webextension-polyfill": "^0.10.0",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-remove-empty-scripts": "^1.0.4"
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion public/manifest_chrome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "ゲーミング群馬大学 -Gaming Gunma University-",
"version": "2.1.0",
"version": "2.1.1",
"description": "辺境の地にある群馬大学のウェブサイトをゲーミングでエキサイティングにします",
"author": "[email protected]",
"permissions": ["storage", "tabs"],
Expand Down Expand Up @@ -33,22 +33,27 @@
"content_scripts": [
{
"matches": ["*://idp.gunma-u.ac.jp/pub/login.cgi*", "*://idp.gunma-u.ac.jp/pub/allotplogin_force.cgi*"],
"css": ["common.css", "sso.css"],
"js": ["common.js", "sso.js"]
},
{
"matches": ["*://mdl.media.gunma-u.ac.jp/*"],
"css": ["common.css", "moodle.css"],
"js": ["common.js", "moodle.js"]
},
{
"matches": ["*://*.kyomu-sys.gunma-u.ac.jp/*"],
"css": ["common.css", "kyomu.css"],
"js": ["common.js", "kyomu.js"]
},
{
"matches": ["*://www.media.gunma-u.ac.jp/*"],
"css": ["common.css", "media.css"],
"js": ["common.js", "media.js"]
},
{
"matches": ["*://opac.lib.gunma-u.ac.jp/*"],
"css": ["common.css", "mylib.css"],
"js": ["common.js", "mylib.js"]
}
]
Expand Down
18 changes: 14 additions & 4 deletions public/manifest_firefox.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "ゲーミング群馬大学 -Gaming Gunma University-",
"version": "2.1.0",
"version": "2.1.1",
"description": "辺境の地にある群馬大学のウェブサイトをゲーミングでエキサイティングにします",
"author": "[email protected]",
"permissions": ["storage", "tabs"],
Expand All @@ -27,29 +27,39 @@
"open_in_tab": true
},
"background": {
"service_worker": "background.js",
"type": "module"
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["*://idp.gunma-u.ac.jp/pub/login.cgi*", "*://idp.gunma-u.ac.jp/pub/allotplogin_force.cgi*"],
"css": ["common.css", "sso.css"],
"js": ["common.js", "sso.js"]
},
{
"matches": ["*://mdl.media.gunma-u.ac.jp/*"],
"css": ["common.css", "moodle.css"],
"js": ["common.js", "moodle.js"]
},
{
"matches": ["*://*.kyomu-sys.gunma-u.ac.jp/*"],
"css": ["common.css", "kyomu.css"],
"js": ["common.js", "kyomu.js"]
},
{
"matches": ["*://www.media.gunma-u.ac.jp/*"],
"css": ["common.css", "media.css"],
"js": ["common.js", "media.js"]
},
{
"matches": ["*://opac.lib.gunma-u.ac.jp/*"],
"css": ["common.css", "mylib.css"],
"js": ["common.js", "mylib.js"]
}
]
],
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "42.0"
}
}
}
4 changes: 3 additions & 1 deletion src/class/Moodle/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Browser from "webextension-polyfill";

import changeQueryInnerHTML from "../../utils/changeQueryInnerHTML";

export const injectLink = () => {
Expand All @@ -10,7 +12,7 @@ export const injectLink = () => {

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

Expand Down
4 changes: 3 additions & 1 deletion src/class/Moodle/enableRainbow.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Browser from "webextension-polyfill";

import changeQueryInnerHTML from "../../utils/changeQueryInnerHTML";
import { RainbowApplicator } from "../ClassApplicator";
import { GundaiWebSite } from "../UnivWebsite";
Expand Down Expand Up @@ -26,7 +28,7 @@ const textAndBg = (rainbow: RainbowApplicator) => {
};
const replaceIconToGamimg = () => {
document.querySelectorAll("img.userpicture").forEach((e) => {
if (e.getAttribute("src")) e.setAttribute("src", chrome.runtime.getURL("assets/partyparrot.gif"));
if (e.getAttribute("src")) e.setAttribute("src", Browser.runtime.getURL("assets/partyparrot.gif"));
});
};
const replaceTextToGaimg = (moodle: GundaiWebSite<MoodleAdditionalInfo>) => {
Expand Down
22 changes: 17 additions & 5 deletions src/class/StorageTool/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
// 最近が物忘れが激しい。どうしてだろうか。
// 人間は嫌なことやつらいこと、思い出さないようなことはすぐに忘れるようにできているらしい。
// となると、最近はつらいことが多いのかもしれない。例えばchrome.storage.sync.get()の返り値がany型であることとか。
// なんか非同期処理が動かないとき闇雲にasync awaitをつけるのがつらい。

import Browser from "webextension-polyfill";

import { WebsiteIds } from "@/data/websites";

import IsTrue from "../../utils/isTrue";

export type StorageKeys = "dark" | "rainbow" | "enabled-hidden" | "show-hidden-option" | "installed" | "auto-2fa";
export type StorageKeys =
| "dark"
| "rainbow"
| "enabled-hidden"
| "show-hidden-option"
| "installed"
| "auto-2fa"
| "quick-switch";
export type StorageIds = WebsiteIds | "other";

export default class StorageTool {
id: string;
constructor(id: string) {
id: StorageIds;
constructor(id: StorageIds) {
this.id = id;
}

static getChromeStorage() {
return chrome.storage ? chrome.storage.sync : null;
return Browser.storage ? Browser.storage.sync : null;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
6 changes: 4 additions & 2 deletions src/class/UnivWebsite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// しかし今の日本では大学は高校の延長線上であり、学士を得るための場所と化している。
// こういった人々の認識が変わって欲しいと日々願っている。

import { WebsiteIds } from "@/data/websites";

import isTrue from "../../utils/isTrue";
import { DarkApplicator, HiddenApplicator, RainbowApplicator } from "../ClassApplicator";
import StorageTool from "../StorageTool";
Expand All @@ -11,7 +13,7 @@ import StorageTool from "../StorageTool";
// 型変数とoptionsプロパティによって任意の情報を追加できる
export class UnivWebsite<T> {
// 基本情報
id: string;
id: WebsiteIds;

storage: StorageTool;

Expand All @@ -28,7 +30,7 @@ export class UnivWebsite<T> {
}

// コンストラクタ
constructor(id: string) {
constructor(id: WebsiteIds) {
this.id = id;
this.options = {} as T;
this.#funcs = [];
Expand Down
17 changes: 1 addition & 16 deletions src/class/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
// 中間管理職は上司と部下の間に立つ存在であり、糊である

import { Kyomu } from "./Kyomu";
import { Media } from "./Media";
import { Moodle } from "./Moodle";
import { MyLibrary } from "./MyLibrary";
import { SSO } from "./SSO";
import { UnivWebsite } from "./UnivWebsite";

export { Kyomu } from "./Kyomu";
export { Media } from "./Media";
export { Moodle } from "./Moodle";
export { MyLibrary } from "./MyLibrary";
export { SSO } from "./SSO";
export { default as StorageTool } from "./StorageTool";
export { GundaiWebSite, UnivWebsite } from "./UnivWebsite";

export const WebSiteClasses = (function () {
const sites: { [id: string]: UnivWebsite<unknown> } = {};

[Kyomu, Media, Moodle, MyLibrary, SSO].forEach((site) => {
sites[site.id] = site;
});
return sites;
})();
2 changes: 1 addition & 1 deletion src/components/SwitchItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export function SwitchItem({
color?: ComponentColor;
readonly?: boolean;
}) {
return <ToggleWithStorage section={config.id} dataKey={category} color={color} readonly={readonly} />;
return <ToggleWithStorage dataId={config.class.id} dataKey={category} color={color} readonly={readonly} />;
}
12 changes: 6 additions & 6 deletions src/components/ToggleWithStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import { useCallback, useEffect, useState } from "react";
import { Toggle } from "react-daisyui";
import { ComponentColor } from "react-daisyui/dist/types";

import { WebSiteClasses } from "@/class";
import { StorageKeys } from "@/class/StorageTool";
import StorageTool, { StorageIds, StorageKeys } from "@/class/StorageTool";
import IsTrue from "@/utils/isTrue";
import { sendMsgToAllTab } from "@/utils/sendMsgToAllTab";

interface ToggleProps {
section: string;
dataId: StorageIds;
dataKey: StorageKeys;
color?: ComponentColor;
readonly?: boolean;
}

export function ToggleWithStorage({ section, color, dataKey, readonly }: ToggleProps) {
export function ToggleWithStorage({ dataId, color, dataKey, readonly }: ToggleProps) {
const [enabled, setEnabled] = useState(false);
const storage = new StorageTool(dataId);

useEffect(() => {
WebSiteClasses[section].storage.get(dataKey).then((value) => {
storage.get(dataKey).then((value) => {
const istrue = IsTrue(value);
if (istrue !== undefined) setEnabled(istrue);
});
Expand All @@ -30,7 +30,7 @@ export function ToggleWithStorage({ section, color, dataKey, readonly }: ToggleP
if (readonly) return;
return (e: React.ChangeEvent<HTMLInputElement>) => {
setEnabled(e.target.checked);
WebSiteClasses[section].storage.set(dataKey, e.target.checked.toString());
storage.set(dataKey, e.target.checked.toString());
sendMsgToAllTab<string>("reload");
};
}, []);
Expand Down
Loading

0 comments on commit b55e37e

Please sign in to comment.