Skip to content

Commit

Permalink
Fix: Moodle undefined this variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Oct 16, 2023
1 parent 9f897e0 commit 7ff09af
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/class/GundaiWebsite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
// GundaiWebSiteはゲーミング化するウェブサイトを定義したクラス
// 型変数とAdditionalInfoプロパティによって任意の情報を追加できる
export default class GundaiWebSite<T> {
EnableRainbow?: () => void;
DisableRainbow?: () => void;
constructor(enable?: () => void, disable?: () => void) {
this.EnableRainbow = enable;
this.DisableRainbow = disable;
if (enable) this.EnableRainbow = enable;
if (disable) this.DisableRainbow = disable;
this.AdditionalInfo = {} as T;
}
EnableRainbow() {}
DisableRainbow() {}
AdditionalInfo: T;
}

Expand Down
14 changes: 5 additions & 9 deletions src/class/Moodle/DisableRainbow.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { RemoveRainbowBg } from "../../utils/AddClass";
import changeQueryInnerHTML from "../../utils/ChangeQueryInnerHTML";
import GundaiWebSite from "../GundaiWebsite";
import { MoodleAdditionalInfo } from "./type";

export default function DisableRainbowFunc(this: GundaiWebSite<MoodleAdditionalInfo>) {
changeQueryInnerHTML("#instance-320-header", "現在のログイン人数");
export const DisableRainbowBg = () => {
RemoveRainbowBg(".navbar", ".addinghtml");
RemoveRainbowBg(".page-header-headings h1");
RemoveRainbowBg("a");
};

const headerText = this.AdditionalInfo.headerText;
document.querySelectorAll(".page-header-headings h1").forEach((e) => {
if (e.innerHTML.includes(headerText)) e.innerHTML.replace(headerText, "");
});
}
export const ReplaceImagesToDefault = () => {
changeQueryInnerHTML("#instance-320-header", "現在のログイン人数");
};
44 changes: 30 additions & 14 deletions src/class/Moodle/EnableRainbow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,44 @@ import changeQueryInnerHTML from "../../utils/ChangeQueryInnerHTML";
import GundaiWebSite from "../GundaiWebsite";
import { MoodleAdditionalInfo } from "./type";

export default function EnableRainbowFunc(this: GundaiWebSite<MoodleAdditionalInfo>) {
const headerText = this.AdditionalInfo.headerText;
document.querySelectorAll(".page-header-headings h1").forEach((e) => {
if (!e.innerHTML.includes(headerText)) e.innerHTML = e.innerHTML + headerText;
});

changeQueryInnerHTML("#instance-320-header", "現在のプレイ人数");
AddRainbowBg(".navbar", ".addinghtml");
export const EnableRainbowText = () => {
AddRainbowText(".page-header-headings h1");
AddRainbowText("a");
};

export const EnableRainbowBg = () => {
AddRainbowBg(".navbar", ".addinghtml");
};

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 = () => {
document.querySelectorAll(".logo").forEach((e) => {
if (e.getAttribute("src")) e.setAttribute("src", chrome.runtime.getURL("assets/GULMS.png"));
});

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

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 ReplaceTextToGaimgFunc = (moodle: GundaiWebSite<MoodleAdditionalInfo>) => {
return () => {
const headerText = moodle.AdditionalInfo.headerText;

document.querySelectorAll(".page-header-headings h1").forEach((e) => {
if (!e.innerHTML.includes(headerText)) e.innerHTML = e.innerHTML + headerText;
});
document.querySelectorAll(".page-header-headings h1").forEach((e) => {
if (!e.innerHTML.includes(headerText)) e.innerHTML = e.innerHTML + headerText;
});

changeQueryInnerHTML("#instance-320-header", "現在のプレイ人数");
};
};
28 changes: 23 additions & 5 deletions src/class/Moodle/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
// 情報の信頼性は社会の構築において重要な要素である
// 個人の信頼性は家庭の構築において重要な要素である
import GundaiWebSite from "../GundaiWebsite";
import DisableRainbow from "./DisableRainbow";
import EnableRainbow from "./EnableRainbow";
import { DisableRainbowBg, ReplaceImagesToDefault } from "./DisableRainbow";
import { EnableRainbowBg, EnableRainbowText, InjectLink, ReplaceImagesToGamimg, ReplaceTextToGaimgFunc } from "./EnableRainbow";
import { MoodleAdditionalInfo } from "./type";

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

Moodle.EnableRainbow = function () {
EnableRainbowBg();
EnableRainbowText();
InjectLink();
ReplaceImagesToGamimg();
ReplaceTextToGaimgFunc(this)();
};

Moodle.DisableRainbow = function () {
DisableRainbowBg();
ReplaceImagesToDefault();

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

0 comments on commit 7ff09af

Please sign in to comment.