Skip to content

Commit 53d42f3

Browse files
committed
Use textContent instead of innerHTML/innerText
1 parent 7441584 commit 53d42f3

File tree

4 files changed

+29
-40
lines changed

4 files changed

+29
-40
lines changed

src/buttons.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function addLinkButton (buttons: HTMLDivElement, program: Program): void {
7272
copyLinkButton.setAttribute("role", "button");
7373
copyLinkButton.classList.add("kae-program-button");
7474
const copyLinkText = document.createElement("span");
75-
copyLinkText.innerText = "Copy Link";
75+
copyLinkText.textContent = "Copy Link";
7676
copyLinkButton.appendChild(copyLinkText);
7777
copyLinkButton.addEventListener("click", function () {
7878
if (window.navigator.hasOwnProperty("clipboard")) {
@@ -134,7 +134,7 @@ function addProgramReportButton (buttons: HTMLDivElement, program: Program, kaid
134134
})}`;
135135
reportButton.setAttribute("role", "button");
136136
const reportText = document.createElement("span");
137-
reportText.innerText = "Report";
137+
reportText.textContent = "Report";
138138
reportButton.appendChild(reportText);
139139
buttons.insertBefore(reportButton, buttons.children[1]);
140140
buttons.insertBefore(document.createTextNode(" "), reportButton.nextSibling);

src/popup.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -94,37 +94,37 @@ function getAuthorNote (notif: Notification): Node {
9494

9595
if (notif.modNickname) {
9696
/* Moderator Message */
97-
authorTag.innerHTML = notif.modNickname;
97+
authorTag.textContent = notif.modNickname;
9898
noteTag.appendChild(authorTag);
99-
noteTag.innerText = noteTag.innerText + " sent you a guardian message:";
99+
noteTag.textContent = noteTag.textContent + " sent you a guardian message:";
100100
} else if (notif.authorNickname) {
101101
/* New Comment or Reply */
102-
authorTag.innerHTML = notif.authorNickname;
102+
authorTag.textContent = notif.authorNickname;
103103
noteTag.appendChild(authorTag);
104-
noteTag.innerText = noteTag.innerText + " added a comment on ";
105-
titleTag.innerHTML = notif.translatedFocusTitle || notif.translatedScratchpadTitle || "";
104+
noteTag.textContent = noteTag.textContent + " added a comment on ";
105+
titleTag.textContent = notif.translatedFocusTitle || notif.translatedScratchpadTitle || "";
106106
noteTag.appendChild(titleTag);
107107
} else if (notif.coachName && notif.contentTitle) {
108108
/* Coach Assignment */
109-
authorTag.innerHTML = notif.coachName;
109+
authorTag.textContent = notif.coachName;
110110
noteTag.appendChild(authorTag);
111-
noteTag.innerText = noteTag.innerText + " assigned you ";
112-
titleTag.innerHTML = notif.contentTitle;
111+
noteTag.textContent = noteTag.textContent + " assigned you ";
112+
titleTag.textContent = notif.contentTitle;
113113
noteTag.appendChild(titleTag);
114114
} else if (notif.missionName && notif.class_.includes("ClassMissionNotification")) {
115115
/* New Mission */
116-
noteTag.innerText = "New Mission: ";
117-
authorTag.innerHTML = notif.missionName;
116+
noteTag.textContent = "New Mission: ";
117+
authorTag.textContent = notif.missionName;
118118
noteTag.appendChild(authorTag);
119119
} else if (notif.translatedDisplayName && notif.class_.includes("RewardNotification")) {
120120
/* New Reward (?) */
121-
noteTag.innerText = "New Reward: ";
122-
authorTag.innerHTML = notif.translatedDisplayName;
121+
noteTag.textContent = "New Reward: ";
122+
authorTag.textContent = notif.translatedDisplayName;
123123
noteTag.appendChild(authorTag);
124124
} else if (notif.iconSrc && notif.extendedDescription && notif.description) {
125125
/* New Badge */
126-
noteTag.innerText = "New Badge: ";
127-
authorTag.innerHTML = notif.description;
126+
noteTag.textContent = "New Badge: ";
127+
authorTag.textContent = notif.description;
128128
noteTag.appendChild(authorTag);
129129
}
130130

@@ -148,11 +148,11 @@ function genNotif (notif: NotifElm): Node {
148148

149149
const contentTag = document.createElement("p");
150150
contentTag.className = "notif-content";
151-
contentTag.innerText = notif.content;
151+
contentTag.textContent = notif.content;
152152

153153
const dateTag = document.createElement("div");
154154
dateTag.className = "notif-date";
155-
dateTag.innerText = notif.date;
155+
dateTag.textContent = notif.date;
156156

157157
wrapTag.appendChild(imgTag);
158158
wrapTag.appendChild(notif.authorNote);
@@ -168,7 +168,7 @@ function genNotif (notif: NotifElm): Node {
168168

169169
const replyButtonTag = document.createElement("a");
170170
replyButtonTag.className = "reply-button";
171-
replyButtonTag.innerText = "Reply";
171+
replyButtonTag.textContent = "Reply";
172172

173173
const replyTextTag = document.createElement("textarea");
174174
replyTextTag.className = "reply-text hide";
@@ -257,7 +257,7 @@ function fkeyNotFound () {
257257
notifsContainer!.innerHTML = "";
258258
const infoTag = document.createElement("h2");
259259
infoTag.className = "please-sign-in";
260-
infoTag.innerText = "Please visit KA and make sure you're signed in";
260+
infoTag.textContent = "Please visit KA and make sure you're signed in";
261261
notifsContainer!.appendChild(infoTag);
262262
}
263263

src/profile.ts

+8-19
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ async function addUserInfo (uok: UsernameOrKaid): Promise<void> {
4848
const trTag = document.createElement("tr");
4949
const tdLabelTag = document.createElement("td");
5050
tdLabelTag.className = "user-statistics-label";
51-
tdLabelTag.innerText = entry;
51+
tdLabelTag.textContent = entry;
5252
trTag.appendChild(tdLabelTag);
5353
const tdEntryTag = document.createElement("td");
5454
if (entry !== "More info") {
55-
tdEntryTag.innerText = `${entries[entry]}`;
55+
tdEntryTag.textContent = `${entries[entry]}`;
5656
} else {
5757
const profileLinkTag = document.createElement("a");
5858
profileLinkTag.href = `${userEndpoint}/profile?${uok.type}=${uok.id}&format=pretty`;
5959
profileLinkTag.target = "_blank";
60-
profileLinkTag.innerText = `${entries[entry]}`;
60+
profileLinkTag.textContent = `${entries[entry]}`;
6161
tdEntryTag.appendChild(profileLinkTag);
6262
}
6363
trTag.appendChild(tdEntryTag);
@@ -76,7 +76,7 @@ async function addUserInfo (uok: UsernameOrKaid): Promise<void> {
7676
if (DEVELOPERS.includes(User.kaid)) {
7777
const statsLabelTag = document.createElement("div");
7878
statsLabelTag.className = "kae-green user-statistics-label";
79-
statsLabelTag.innerText = "KA Extension Developer";
79+
statsLabelTag.textContent = "KA Extension Developer";
8080
table.appendChild(statsLabelTag);
8181
}
8282

@@ -86,30 +86,19 @@ async function addUserInfo (uok: UsernameOrKaid): Promise<void> {
8686
if (!data.hasOwnProperty("discussion_banned")) {
8787
throw new Error("Error loading ban information.");
8888
}else {
89-
const bannedTag = document.createElement("tr");
90-
const bannedLabelTag = document.createElement("td");
91-
bannedLabelTag.className = "user-statistics-label";
92-
bannedLabelTag.innerText = "Banned";
93-
bannedTag.appendChild(bannedLabelTag);
89+
let bannedHTML = `<tr><td class="user-statistics-label">Banned</td>`;
9490

9591
if (data.discussion_banned === false) {
96-
const bannedLabelTag2 = document.createElement("td");
97-
bannedLabelTag2.innerText = "No";
98-
bannedTag.appendChild(bannedLabelTag2);
92+
bannedHTML += `<td>No</td>`;
9993
}else if (data.discussion_banned === true) {
100-
const bannedLabelTag2 = document.createElement("td");
101-
bannedLabelTag2.style.color = "red";
102-
bannedLabelTag2.innerText = "Discussion banned";
103-
bannedTag.appendChild(bannedLabelTag2);
94+
bannedHTML += `<td style="color: red">Discussion banned</td>`;
10495
}else {
10596
throw new Error("Error loading ban information.");
10697
}
10798

10899
const lastTR = table.querySelector("tr:last-of-type");
109100
if (!lastTR) { throw new Error("Table has no tr"); }
110-
// TODO - need to finish this
111-
lastTR.parentNode.replaceChild(bannedTag, lastTR)
112-
//lastTR.outerHTML = bannedHTML + `</tr>` + lastTR.outerHTML;
101+
lastTR.outerHTML = bannedHTML + `</tr>` + lastTR.outerHTML;
113102
}
114103
});
115104
}

src/report.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function addProfileReportButton (uok: UsernameOrKaid, loggedInKaid: string
2828
callback: window.location.href
2929
})}`;
3030
const buttonText = document.createElement("span");
31-
buttonText.innerText = "Report user";
31+
buttonText.textContent = "Report user";
3232
button.appendChild(buttonText);
3333
const dWidget = document.getElementById("discussion-widget");
3434
const widget = discussionWidget.getElementsByClassName("profile-widget-contents")[0];

0 commit comments

Comments
 (0)