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 Apr 5, 2024
2 parents 9e1f212 + 4f77c3d commit 082ee65
Show file tree
Hide file tree
Showing 75 changed files with 2,334 additions and 1,837 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ dist
pnpm-lock.yaml
Dockerfile
*.md

6 changes: 6 additions & 0 deletions .github/.dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ jobs:
files: dist/firefox
dest: gaming-gundai-firefox.zip

- name: Submit
run: npx chrome-webstore-upload-cli@2 upload --source gaming-gundai-chrome.zip --auto-publish
env:
EXTENSION_ID: ${{ secrets.EXTENSION_ID }}
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }}

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},
"[shellscript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
6 changes: 4 additions & 2 deletions devtools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bump_command() {
done

echo "Format files" >&2
prettier --write "$script_path/package.json" "$script_path/public/manifest_chrome.json" "$script_path/public/manifest_firefox.json"
pnpm prettier --write "$script_path/package.json" "$script_path/public/manifest_chrome.json" "$script_path/public/manifest_firefox.json"

return 0
}
Expand All @@ -94,7 +94,9 @@ main() {
done
eval set -- "${_noopts-""}"
_cmd="${1-""}"
shift 1 || true
if [ $# -ge 1 ]; then
shift 1
fi
case "${_cmd-""}" in
"init")
init_command "$@"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 13 additions & 5 deletions src/class/SSO/index.ts → lib/class/SSO/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ export const SSO = new GundaiWebSite<{
export default SSO;

SSO.rainbow.enable = function () {
this.bg.apply(".input_form");
//this.text.apply("#login_button"); // ログインボタン
this.text.apply("a"); // リンク
this.text.apply(".product"); // タイトル
//this.text.apply(".login_comment");

this.bg.apply(".login__main"); // ログイン画面

this.bg.apply("#login_button");

changeQueryInnerHTML(".product", "群馬大学ゲーミングサインオンシステム");
changeQueryInnerHTML("#login_button", "→ ログイン ←");
};
SSO.options.isAuto2FAEnabled = async (): Promise<boolean> => {
const isAuto2FAEnabled = await SSO.storage.get("auto-2fa");
return isAuto2FAEnabled;
};

SSO.options.isAuto2FAEnabled = () => SSO.storage.get("auto-2fa");

SSO.options.enableAuto2FA = () => {
SSO.storage.getBool("auto-2fa").then((isAuto2FAEnabled) => {
if (isAuto2FAEnabled) {
Expand Down
38 changes: 21 additions & 17 deletions src/class/StorageTool/index.ts → lib/class/Storage/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,24 @@

import Browser from "webextension-polyfill";

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

import IsTrue from "../../utils/isTrue";
import { StorageTool } from "./storage";
import { StorageIds, StorageKeys } from "./type";

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

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

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

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async set(key: StorageKeys, value: any) {
let newData = { [key]: value };
const storage = StorageTool.getChromeStorage();
const storage = BrowserStorage.getChromeStorage();
if (!storage) {
console.error("Storage is not supported");
return;
Expand All @@ -43,7 +33,7 @@ export default class StorageTool {
storage.set({ [this.id]: newData });
}
async getBool(key: StorageKeys) {
const storage = StorageTool.getChromeStorage();
const storage = BrowserStorage.getChromeStorage();
if (!storage) {
console.error("Storage is not supported");
return;
Expand All @@ -54,7 +44,7 @@ export default class StorageTool {
return IsTrue(rawdata);
}
async get(key: StorageKeys) {
const storage = StorageTool.getChromeStorage();
const storage = BrowserStorage.getChromeStorage();
if (!storage) {
console.error("Storage is not supported");
return;
Expand All @@ -65,4 +55,18 @@ export default class StorageTool {
if (rawdata === undefined) return undefined;
return rawdata[key];
}

async toggle(key: StorageKeys) {
const storage = BrowserStorage.getChromeStorage();
if (!storage) {
console.error("Storage is not supported");
return;
}

const rawdata = await this.getBool(key);

if (rawdata === undefined) return;

await this.set(key, !rawdata ? "true" : "false");
}
}
14 changes: 14 additions & 0 deletions lib/class/Storage/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { StorageIds, StorageKeys } from "./type";

export interface StorageTool {
id: StorageIds;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
set(key: StorageKeys, value: any): Promise<void>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getBool(key: StorageKeys): Promise<boolean | undefined>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
get(key: StorageKeys): Promise<any>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
toggle(key: StorageKeys): Promise<void>;
}
28 changes: 28 additions & 0 deletions lib/class/Storage/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { StorageTool } from "..";
import { StorageIds } from "./type";

export class TestStorage implements StorageTool {
id: StorageIds;
constructor(id: StorageIds) {
this.id = id;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async set(key: string, value: any) {
console.log(`Set ${key} to ${value}`);
}

async getBool(key: string) {
console.log(`Get ${key}`);
return true;
}

async get(key: string) {
console.log(`Get ${key}`);
return true;
}

async toggle(key: string) {
console.log(`Toggle ${key}`);
}
}
11 changes: 11 additions & 0 deletions lib/class/Storage/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { WebsiteIds } from "@/data/websites";

export type StorageKeys =
| "dark"
| "rainbow"
| "enabled-hidden"
| "show-hidden-option"
| "installed"
| "auto-2fa"
| "quick-switch";
export type StorageIds = WebsiteIds | "other";
19 changes: 13 additions & 6 deletions src/class/UnivWebsite/index.ts → lib/class/UnivWebsite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { WebsiteIds } from "@/data/websites";

import isTrue from "../../utils/isTrue";
import { DarkApplicator, HiddenApplicator, RainbowApplicator } from "../ClassApplicator";
import StorageTool from "../StorageTool";
import BrowserStorage from "../Storage/browser";
//import Storage from "../../utils/Storage";

// UnivWebSiteはゲーミング化するウェブサイトを定義したクラス
Expand All @@ -15,7 +15,7 @@ export class UnivWebsite<T> {
// 基本情報
id: WebsiteIds;

storage: StorageTool;
storage: BrowserStorage;

// Applicator
rainbow: RainbowApplicator;
Expand All @@ -24,6 +24,8 @@ export class UnivWebsite<T> {

// 追加情報
options: T; // 型変数使うとかっこいいよね

// load時に実行する関数
#funcs: (() => void)[];
addLoader(func: () => void) {
this.#funcs.push(func);
Expand All @@ -34,13 +36,18 @@ export class UnivWebsite<T> {
this.id = id;
this.options = {} as T;
this.#funcs = [];
this.storage = new StorageTool(id);
this.storage = new BrowserStorage(id);

this.rainbow = new RainbowApplicator();
this.dark = new DarkApplicator();
this.hidden = new HiddenApplicator();
}

async initilizeWebsiteDb() {
await this.storage.set("rainbow", "false");
await this.storage.set("dark", "false");
}

async isRainbowEnabled() {
const isRainbowEnabled = await this.storage.get("rainbow");
return isTrue(isRainbowEnabled);
Expand All @@ -52,7 +59,7 @@ export class UnivWebsite<T> {
}

async isHiddenEnabled() {
const otherStorage = new StorageTool("other");
const otherStorage = new BrowserStorage("other");
const isHiddenEnabled = await otherStorage.getBool("enabled-hidden");
return isTrue(isHiddenEnabled);
}
Expand Down Expand Up @@ -84,14 +91,14 @@ export class UnivWebsite<T> {
}

const isHiddenEnabled = await site.isHiddenEnabled();
const otherStorage = new StorageTool("other");
const otherStorage = new BrowserStorage("other");
if (isHiddenEnabled) {
document.documentElement.dataset.gaming_gundai_hidden = "true";
otherStorage.set("enabled-hidden", "true");
site.hidden.enable();
} else {
document.documentElement.dataset.gaming_gundai_hidden = "false";
site.storage.set("enabled-hidden", "false");
otherStorage.set("enabled-hidden", "false");
site.hidden.disable();
}

Expand Down
2 changes: 1 addition & 1 deletion src/class/index.ts → lib/class/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export { Media } from "./Media";
export { Moodle } from "./Moodle";
export { MyLibrary } from "./MyLibrary";
export { SSO } from "./SSO";
export { default as StorageTool } from "./StorageTool";
export { default as StorageTool } from "./Storage/browser";
export { GundaiWebSite, UnivWebsite } from "./UnivWebsite";
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { ComponentColor } from "react-daisyui/dist/types";

import BrowserStorage from "@/class/Storage/browser";

import { WebsiteConfig } from "../data/websites";
import { ToggleWithStorage } from "./ToggleWithStorage";
import { Category } from "./type";
Expand All @@ -17,5 +19,7 @@ export function SwitchItem({
color?: ComponentColor;
readonly?: boolean;
}) {
return <ToggleWithStorage dataId={config.class.id} dataKey={category} color={color} readonly={readonly} />;
return (
<ToggleWithStorage storage={new BrowserStorage(config.class.id)} dataKey={category} color={color} readonly={readonly} />
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ import { useCallback, useEffect, useState } from "react";
import { Toggle } from "react-daisyui";
import { ComponentColor } from "react-daisyui/dist/types";

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

interface ToggleProps {
dataId: StorageIds;
storage: StorageTool;
dataKey: StorageKeys;
color?: ComponentColor;
readonly?: boolean;
}

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

useEffect(() => {
//console.log("render ToggleWithStorage");
storage.get(dataKey).then((value) => {
const istrue = IsTrue(value);
if (istrue !== undefined) setEnabled(istrue);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions lib/utils/isTrue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function isTrue(value: any) {
if (value === undefined) return undefined;

let str: string;

if (typeof value === "boolean") {
str = value.toString();
} else if (typeof value === "string") {
str = value.toLowerCase();
} else {
str = value;
}
return str === "true";
}
File renamed without changes.
12 changes: 12 additions & 0 deletions lib/utils/popupControl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Browser from "webextension-polyfill";

export const disablePopup = () => {
//Browser.browserAction.setPopup({ popup: "" });
//console.log("disablePopup");
Browser.action.setPopup({ popup: "" });
};

export const enablePopup = () => {
//Browser.browserAction.setPopup({ popup: "popup.html" });
Browser.action.setPopup({ popup: "popup.html" });
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const sendMsgToAllTab = <T>(msg: T) => {
const urls = getUrlsFromManifest();
browser.tabs
.query({
url: urls,
url: [...urls, `chrome-extension://${browser.runtime.id}/*`],
})
.then((tabs) => {
tabs.forEach((tab) => {
Expand Down
Loading

0 comments on commit 082ee65

Please sign in to comment.