Skip to content

Commit

Permalink
Clean: Change utils function name
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Oct 14, 2023
1 parent 29a9545 commit 6853fc6
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/class/Kyomu/index.ts
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 GundaiWebSite from "../GundaiWebsite";

const EnableRainbow = () => {
Expand Down
10 changes: 5 additions & 5 deletions src/class/Moodle/DisableRainbow.ts
Original file line number Diff line number Diff line change
@@ -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, "");
Expand Down
4 changes: 2 additions & 2 deletions src/class/Moodle/EnableRainbow.ts
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 "./common";

export const EnableRainbow = () => {
Expand Down
6 changes: 3 additions & 3 deletions src/class/SSO/EnableRainbow.ts
Original file line number Diff line number Diff line change
@@ -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"], "群馬大学ゲーミングサインオンシステム");
};

Expand Down
8 changes: 4 additions & 4 deletions src/scripts/background.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/scripts/content_kyomu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Kyomu } from "../class";
import loadGamingWebsite from "../utils/loadGamingWebsite";
import LoadGamingWebsite from "../utils/LoadGamingWebsite";

loadGamingWebsite(Kyomu);
LoadGamingWebsite(Kyomu);
2 changes: 1 addition & 1 deletion src/scripts/content_media.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Media } from "../class";
import loadGamingWebsite from "../utils/loadGamingWebsite";
import loadGamingWebsite from "../utils/LoadGamingWebsite";

loadGamingWebsite(Media);
2 changes: 1 addition & 1 deletion src/scripts/content_moodle.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/content_sso.ts
Original file line number Diff line number Diff line change
@@ -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));

Expand Down
16 changes: 8 additions & 8 deletions src/utils/addClass.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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"]);
}
2 changes: 1 addition & 1 deletion src/utils/changeQueryInnerHTML.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/getIsEnabled.ts
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 4 additions & 3 deletions src/utils/loadGamingWebsite.ts
Original file line number Diff line number Diff line change
@@ -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));
}
4 changes: 2 additions & 2 deletions src/utils/runFuncIfEnabled.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const storage = chrome.storage.sync;
export const Storage = chrome.storage.sync;
export default Storage;

0 comments on commit 6853fc6

Please sign in to comment.