Skip to content

Commit dac11bc

Browse files
committed
Change authorNote code to DOM
1 parent 8d2797f commit dac11bc

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

src/popup.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,54 +86,74 @@ function getContent (notif: Notification): string {
8686
}
8787
}
8888

89-
function getAuthorNote (notif: Notification): string {
89+
function getAuthorNote (notif: Notification): Node {
90+
const noteTag = document.createElement("p");
91+
const authorTag = document.createElement("b");
92+
const titleTag = document.createElement("b");
93+
9094
if (notif.modNickname) {
9195
/* Moderator Message */
92-
return `<b>${escapeHTML(notif.modNickname)}</b> sent you a guardian message:`;
96+
authorTag.innerHTML = notif.modNickname;
97+
noteTag.appendChild(authorTag);
98+
noteTag.innerText = noteTag.innerText + " sent you a guardian message:"
9399
} else if (notif.authorNickname) {
94100
/* New Comment or Reply */
95-
return `<b>${escapeHTML(notif.authorNickname)}</b> added a comment on <b>${escapeHTML(notif.translatedFocusTitle || notif.translatedScratchpadTitle || "")}</b>`;
101+
authorTag.innerHTML = notif.authorNickname;
102+
noteTag.appendChild(authorTag);
103+
noteTag.innerText = noteTag.innerText + " added a comment on ";
104+
titleTag.innerHTML = notif.translatedFocusTitle || notif.translatedScratchpadTitle || "";
105+
noteTag.appendChild(titleTag);
96106
} else if (notif.coachName && notif.contentTitle) {
97107
/* Coach Assignment */
98-
return `<b>${escapeHTML(notif.coachName)}</b> assigned you <b>${escapeHTML(notif.contentTitle)}</b>`;
108+
authorTag.innerHTML = notif.coachName;
109+
noteTag.appendChild(authorTag);
110+
noteTag.innerText = noteTag.innerText + " assigned you ";
111+
titleTag.innerHTML = notif.contentTitle;
112+
noteTag.appendChild(titleTag);
99113
} else if (notif.missionName && notif.class_.includes("ClassMissionNotification")) {
100114
/* New Mission */
101-
return `New Mission: <b>${escapeHTML(notif.missionName)}</b>`;
115+
noteTag.innerText = "New Mission: ";
116+
authorTag.innerHTML = notif.missionName;
117+
noteTag.appendChild(authorTag);
102118
} else if (notif.translatedDisplayName && notif.class_.includes("RewardNotification")) {
103119
/* New Reward (?) */
104-
return `New Reward: <b>${escapeHTML(notif.translatedDisplayName)}</b>`;
120+
noteTag.innerText = "New Reward: ";
121+
authorTag.innerHTML = notif.translatedDisplayName;
122+
noteTag.appendChild(authorTag)
105123
} else if (notif.iconSrc && notif.extendedDescription && notif.description) {
106124
/* New Badge */
107-
return `New Badge: <b>${escapeHTML(notif.description)}</b>`;
125+
noteTag.innerText = "New Badge: ";
126+
authorTag.innerHTML = notif.description;
127+
noteTag.appendChild(authorTag)
108128
}
109129

110-
return "";
130+
return noteTag;
111131
}
112132

113133
function genNotif (notif: NotifElm): Node {
114-
let container = document.createElement("div")
134+
const container = document.createElement("div")
115135
container.className = "new-notif";
116136

117-
let linkTag = document.createElement("a");
137+
const linkTag = document.createElement("a");
118138
linkTag.target = "_blank";
119139
linkTag.href = notif.href;
120140

121-
let wrapTag = document.createElement("div");
141+
const wrapTag = document.createElement("div");
122142
wrapTag.className = "notif-wrap";
123143

124-
let imgTag = document.createElement("img");
144+
const imgTag = document.createElement("img");
125145
imgTag.className = "notif-img";
126146
imgTag.src = notif.imgSrc;
127147

128-
let noteTag = document.createElement("p");
148+
const noteTag = document.createElement("p");
129149
noteTag.className = "author-note";
130-
noteTag.innerText = notif.authorNote;
150+
noteTag.appendChild(notif.authorNote);
131151

132-
let contentTag = document.createElement("p");
152+
const contentTag = document.createElement("p");
133153
contentTag.className = "notif-content";
134154
contentTag.innerText = notif.content;
135155

136-
let dateTag = document.createElement("div");
156+
const dateTag = document.createElement("div");
137157
dateTag.className = "notif-date";
138158
dateTag.innerText = notif.date;
139159

@@ -144,16 +164,16 @@ function genNotif (notif: NotifElm): Node {
144164
linkTag.appendChild(wrapTag);
145165
container.appendChild(linkTag);
146166

147-
let replyTag = document.createElement("div");
167+
const replyTag = document.createElement("div");
148168
replyTag.className = "reply";
149169
replyTag.setAttribute("programID", notif.programID);
150170
replyTag.setAttribute("feedback", notif.feedback);
151171

152-
let replyButtonTag = document.createElement("a")
172+
const replyButtonTag = document.createElement("a")
153173
replyButtonTag.className = "reply-button";
154174
replyButtonTag.innerText = "Reply";
155175

156-
let replyTextTag = document.createElement("textarea");
176+
const replyTextTag = document.createElement("textarea");
157177
replyTextTag.className = "reply-text hide";
158178

159179
if (notif.isComment) {

src/types/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ interface NotifElm {
163163
imgSrc: string;
164164
content: string;
165165
date: string;
166-
authorNote: string;
166+
authorNote: Node;
167167
isComment: boolean;
168168
programID: string;
169169
feedback: string;

0 commit comments

Comments
 (0)