From 6853fc60a8e63c1444372dfa4e807688612cc2f0 Mon Sep 17 00:00:00 2001 From: hayao Date: Sat, 14 Oct 2023 19:02:39 +0900 Subject: [PATCH] Clean: Change utils function name --- src/class/Kyomu/index.ts | 4 ++-- src/class/Moodle/DisableRainbow.ts | 10 +++++----- src/class/Moodle/EnableRainbow.ts | 4 ++-- src/class/SSO/EnableRainbow.ts | 6 +++--- src/scripts/background.ts | 8 ++++---- src/scripts/content_kyomu.ts | 4 ++-- src/scripts/content_media.ts | 2 +- src/scripts/content_moodle.ts | 2 +- src/scripts/content_sso.ts | 2 +- src/utils/addClass.ts | 16 ++++++++-------- src/utils/changeQueryInnerHTML.ts | 2 +- src/utils/getIsEnabled.ts | 6 +++--- src/utils/loadGamingWebsite.ts | 7 ++++--- src/utils/runFuncIfEnabled.ts | 4 ++-- src/utils/storage.ts | 3 ++- 15 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/class/Kyomu/index.ts b/src/class/Kyomu/index.ts index b1565e1..06e5230 100644 --- a/src/class/Kyomu/index.ts +++ b/src/class/Kyomu/index.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 GundaiWebSite from "../GundaiWebsite"; const EnableRainbow = () => { diff --git a/src/class/Moodle/DisableRainbow.ts b/src/class/Moodle/DisableRainbow.ts index 782d6ea..62d8d15 100644 --- a/src/class/Moodle/DisableRainbow.ts +++ b/src/class/Moodle/DisableRainbow.ts @@ -1,12 +1,12 @@ -import { removeRainbowBg } from "../../utils/addClass"; -import changeQueryInnerHTML from "../../utils/changeQueryInnerHTML"; +import { RemoveRainbowBg } from "../../utils/AddClass"; +import changeQueryInnerHTML from "../../utils/ChangeQueryInnerHTML"; import { HeaderAppendText } from "./common"; export const DisableRainbow = () => { changeQueryInnerHTML(["#instance-320-header"], "現在のログイン人数"); - removeRainbowBg(".navbar", ".addinghtml"); - removeRainbowBg(".page-header-headings h1"); - removeRainbowBg("a"); + RemoveRainbowBg(".navbar", ".addinghtml"); + RemoveRainbowBg(".page-header-headings h1"); + RemoveRainbowBg("a"); document.querySelectorAll(".page-header-headings h1").forEach((e) => { if (e.innerHTML.includes(HeaderAppendText)) e.innerHTML.replace(HeaderAppendText, ""); diff --git a/src/class/Moodle/EnableRainbow.ts b/src/class/Moodle/EnableRainbow.ts index 19b5490..fd9aecf 100644 --- a/src/class/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 "./common"; export const EnableRainbow = () => { diff --git a/src/class/SSO/EnableRainbow.ts b/src/class/SSO/EnableRainbow.ts index a05f587..21b153e 100644 --- a/src/class/SSO/EnableRainbow.ts +++ b/src/class/SSO/EnableRainbow.ts @@ -1,8 +1,8 @@ -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"]); + AddClass([".header_column", ".input_form", ".input_column"], ["rainbow-bg"]); changeQueryInnerHTML([".product"], "群馬大学ゲーミングサインオンシステム"); }; diff --git a/src/scripts/background.ts b/src/scripts/background.ts index 18791d8..3806fcf 100644 --- a/src/scripts/background.ts +++ b/src/scripts/background.ts @@ -1,14 +1,14 @@ -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 }); + Storage.set({ enabled: true }); chrome.action.setBadgeText({ text: "ON" }); }); chrome.action.onClicked.addListener(async (tab) => { const isEnable = await getIsEnabled(); - storage.set({ enabled: !isEnable }); + Storage.set({ enabled: !isEnable }); chrome.action.setBadgeText({ text: isEnable ? "OFF" : "ON" }); console.log("enabled:", !isEnable); diff --git a/src/scripts/content_kyomu.ts b/src/scripts/content_kyomu.ts index 9d72d52..cdf02ed 100644 --- a/src/scripts/content_kyomu.ts +++ b/src/scripts/content_kyomu.ts @@ -1,4 +1,4 @@ import { Kyomu } from "../class"; -import loadGamingWebsite from "../utils/loadGamingWebsite"; +import LoadGamingWebsite from "../utils/LoadGamingWebsite"; -loadGamingWebsite(Kyomu); +LoadGamingWebsite(Kyomu); diff --git a/src/scripts/content_media.ts b/src/scripts/content_media.ts index f43d2ab..5530a93 100644 --- a/src/scripts/content_media.ts +++ b/src/scripts/content_media.ts @@ -1,4 +1,4 @@ import { Media } from "../class"; -import loadGamingWebsite from "../utils/loadGamingWebsite"; +import loadGamingWebsite from "../utils/LoadGamingWebsite"; loadGamingWebsite(Media); diff --git a/src/scripts/content_moodle.ts b/src/scripts/content_moodle.ts index 085ebb1..a3175db 100644 --- a/src/scripts/content_moodle.ts +++ b/src/scripts/content_moodle.ts @@ -1,5 +1,5 @@ import { Moodle } from "../class"; -import loadGamingWebsite from "../utils/loadGamingWebsite"; +import loadGamingWebsite from "../utils/LoadGamingWebsite"; //window.addEventListener("load", async () => await runFuncIfEnabled(Moodle.EnableRainbow)); loadGamingWebsite(Moodle); diff --git a/src/scripts/content_sso.ts b/src/scripts/content_sso.ts index d5dc248..3ab7cd2 100644 --- a/src/scripts/content_sso.ts +++ b/src/scripts/content_sso.ts @@ -1,5 +1,5 @@ import { SSO } from "../class"; -import loadGamingWebsite from "../utils/loadGamingWebsite"; +import loadGamingWebsite from "../utils/LoadGamingWebsite"; //window.addEventListener("load", async () => await runFuncIfEnabled(SSO.EnableRainbow)); diff --git a/src/utils/addClass.ts b/src/utils/addClass.ts index 58d77f3..2b08e43 100644 --- a/src/utils/addClass.ts +++ b/src/utils/addClass.ts @@ -1,4 +1,4 @@ -export function addClass(queries: string[], classNames: string[]) { +export function AddClass(queries: string[], classNames: string[]) { queries.forEach((query) => { const elements = document.querySelectorAll(query); elements.forEach((element) => { @@ -8,7 +8,7 @@ export function addClass(queries: string[], classNames: string[]) { }); } -export function removeClass(queries: string[], classNames: string[]) { +export function RemoveClass(queries: string[], classNames: string[]) { queries.forEach((query) => { const elements = document.querySelectorAll(query); elements.forEach((element) => { @@ -19,17 +19,17 @@ export function removeClass(queries: string[], classNames: string[]) { } export function addRainbowBg(...queries: string[]) { - addClass(queries, ["rainbow-bg"]); + AddClass(queries, ["rainbow-bg"]); } export function addRainbowText(...queries: string[]) { - addClass(queries, ["rainbow-text"]); + AddClass(queries, ["rainbow-text"]); } -export function removeRainbowBg(...queries: string[]) { - removeClass(queries, ["rainbow-bg"]); +export function RemoveRainbowBg(...queries: string[]) { + RemoveClass(queries, ["rainbow-bg"]); } -export function removeRainbowText(...queries: string[]) { - removeClass(queries, ["rainbow-text"]); +export function RemoveRainbowText(...queries: string[]) { + RemoveClass(queries, ["rainbow-text"]); } diff --git a/src/utils/changeQueryInnerHTML.ts b/src/utils/changeQueryInnerHTML.ts index 132b44e..2d2f087 100644 --- a/src/utils/changeQueryInnerHTML.ts +++ b/src/utils/changeQueryInnerHTML.ts @@ -1,4 +1,4 @@ -export default function changeQueryInnerHTML(queries: string[], innerHTML: string) { +export default function ChangeQueryInnerHTML(queries: string[], innerHTML: string) { queries.forEach((query) => { const elements = document.querySelectorAll(query); elements.forEach((element) => { diff --git a/src/utils/getIsEnabled.ts b/src/utils/getIsEnabled.ts index d4094b8..680edce 100644 --- a/src/utils/getIsEnabled.ts +++ b/src/utils/getIsEnabled.ts @@ -1,6 +1,6 @@ -import { storage } from "./storage"; +import Storage from "./Storage"; -export default async function getIsEnabled() { - const config = await storage.get("enabled"); +export default async function GetIsEnabled() { + const config = await Storage.get("enabled"); return config.enabled; } diff --git a/src/utils/loadGamingWebsite.ts b/src/utils/loadGamingWebsite.ts index 1cad03e..29f2352 100644 --- a/src/utils/loadGamingWebsite.ts +++ b/src/utils/loadGamingWebsite.ts @@ -1,6 +1,7 @@ import GundaiWebSite from "../class/GundaiWebsite"; -import runFuncIfEnabled from "./runFuncIfEnabled"; +import RunFuncIfEnabled from "./RunFuncIfEnabled"; -export default function loadGamingWebsite(website: GundaiWebSite) { - window.addEventListener("load", async () => await runFuncIfEnabled(website.EnableRainbow)); +// ウィンドウが読み込まれたらGundaiWebsiteのEnableRainbowを実行する +export default function LoadGamingWebsite(website: GundaiWebSite) { + window.addEventListener("load", async () => await RunFuncIfEnabled(website.EnableRainbow)); } diff --git a/src/utils/runFuncIfEnabled.ts b/src/utils/runFuncIfEnabled.ts index 13a9c81..28fcfa5 100644 --- a/src/utils/runFuncIfEnabled.ts +++ b/src/utils/runFuncIfEnabled.ts @@ -1,6 +1,6 @@ -import getIsEnabled from "./getIsEnabled"; +import getIsEnabled from "./GetIsEnabled"; -export default async function runFuncIfEnabled(func: () => void) { +export default async function RunFuncIfEnabled(func: () => void) { const isEnable = await getIsEnabled(); if (isEnable) { func(); diff --git a/src/utils/storage.ts b/src/utils/storage.ts index e9cd8fe..1ebc3ce 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -1 +1,2 @@ -export const storage = chrome.storage.sync; +export const Storage = chrome.storage.sync; +export default Storage;