Skip to content

Commit

Permalink
Update: Rewrite without innerHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Nov 20, 2023
1 parent aa4a327 commit 1158ff1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/class/Kyomu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Kyomu.rainbow.enable = function () {
'<tr><td align="center">ゲーミング群馬大学についての問い合わせは<a href="https://twitter.com/Hayao0819" style="font-size: small;">@Hayao0819</a>までお願いします。</td></tr>';
document.querySelectorAll(".footerTable").forEach((e) => {
const tbody = e.querySelector("tbody");
if (tbody) tbody.innerHTML += linkHTML;
if (tbody) tbody.innerText += linkHTML;
});
}

Expand Down
26 changes: 22 additions & 4 deletions src/class/Moodle/common.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import Browser from "webextension-polyfill";

import { createElem } from "@/utils/createElem";

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

export const injectLink = () => {
console.log("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>`;
if (supportSection) {
const link = createElem(
"a",
{ href: "https://twitter.com/Hayao0819", class: "rainbow-text" },
createElem("span", {}, "Gaming Edition開発者に連絡する"),
createElem("i", { class: "icon fa fa-external-link fa-fw ml-1", "aria-hidden": "true" }),
);
supportSection.appendChild(link);
}

const userMenu = document.getElementById("usermenu-carousel");
if (userMenu) {
const link = createElem(
"a",
{ href: "https://twitter.com/Hayao0819", class: "dropdown-item", role: "menuitem", tabindex: "-1" },
"ゲーミング群馬大学",
);
userMenu.appendChild(link);
}
};

export const replaceLMSLogo = () => {
Expand Down
3 changes: 3 additions & 0 deletions src/class/Moodle/enableRainbow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const replaceIconToGamimg = () => {
if (e.getAttribute("src")) e.setAttribute("src", Browser.runtime.getURL("assets/partyparrot.gif"));
});
};

/* eslint-disable no-unsanitized/property */
const replaceTextToGaimg = (moodle: GundaiWebSite<MoodleAdditionalInfo>) => {
const headerText = moodle.options.headerText;

Expand All @@ -43,6 +45,7 @@ const replaceTextToGaimg = (moodle: GundaiWebSite<MoodleAdditionalInfo>) => {

changeQueryInnerHTML("#instance-320-header", "現在のプレイ人数");
};
/* eslint-enable no-unsanitized/property */

const headerHover = () => {
// メニューバーでホバー時にclassを追加
Expand Down
1 change: 1 addition & 0 deletions src/utils/changeQueryInnerHTML.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default function changeQueryInnerHTML(query: string, innerHTML: string) {
const elements = document.querySelectorAll(query);
elements.forEach((element) => {
/* eslint-disable-next-line no-unsanitized/property */
element.innerHTML = innerHTML;
});
}
13 changes: 13 additions & 0 deletions src/utils/createElem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const createElem = (tag: string, attr: { [key: string]: string }, ...children: (Node | string)[]) => {
const elem = document.createElement(tag);
for (const [key, value] of Object.entries(attr)) {
elem.setAttribute(key, value);
}
for (const child of children) {
if (typeof child === "string") elem.innerText = child;
else elem.appendChild(child);
}
return elem;
};

export default createElem;

0 comments on commit 1158ff1

Please sign in to comment.