Skip to content
This repository was archived by the owner on Oct 28, 2022. It is now read-only.

Commit 0190905

Browse files
committed
Add formatting in message page. Add markdown tripple and single tick for code
1 parent 61f95bb commit 0190905

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

javascript.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ sf.init = function() {
126126
sf.formatter.appendChild(icon);
127127
continue;
128128
}
129-
129+
130130
// Set up code for each icon
131131
icon.fillers = sf.tags[t].fillers;
132132
icon.onclick = function(event) {
@@ -171,20 +171,29 @@ sf.init = function() {
171171
event.target.parentElement.prepend(sf.formatter);
172172
sf.formatter.style.width = event.target.offsetWidth + "px";
173173
event.target.style.resize = "auto";
174-
175174
}
176175
}
177176
}
178177

179178
// Initial background formatting loop.
179+
// This just checks for new comments
180180
setInterval(function() {
181181
sf.format();
182182
}, 300);
183183
}
184184

185-
// This is a 1 second timeout for page load, since I am
186-
// too lazy to figure out real page load times
187-
setTimeout(sf.init, 1000);
185+
// Simply a .5 second timer after page load. JS onload doesn't seem
186+
// to work very well.
187+
setTimeout(function() {
188+
var messages = document.getElementsByClassName("comment-text");
189+
if (messages.length == 0) {
190+
sf.init();
191+
} else {
192+
for (var i = 0; i < messages.length; i++) {
193+
messages[i].innerHTML = sf.parse(messages[i].innerHTML);
194+
}
195+
}
196+
}, 500);
188197

189198
// Function to format comments that are not already
190199
// formatted
@@ -213,11 +222,17 @@ sf.parseMD = function(text) {
213222
// Bold, then italics
214223
text = text.replace(/\*\*(.*?)\*\*/g, "<b>$1</b>");
215224
text = text.replace(/\*(.*?)\*/g, "<i>$1</i>");
225+
226+
text = text.replace(/```((.|\n*)*?)```/gm, "<code>$1</code>");
227+
text = text.replace(/`(.*?)`/g, "<code>$1</code>");
228+
229+
// Don't format links that already have a tag with them
216230
text = text.replace(/(https:|http:|www\.)([^\"\>\<]*$)/gm, "<a href='$1$2'>$1$2</a>");
231+
217232
return text;
218233
}
219234

220-
// Custom regex SFML* parser. It parses differently than HTML. Instead
235+
// Custom regex SFCode* parser. It parses differently than BBcode. Instead
221236
// Of replacing [b] with <b>, it it replaces both tags with
222237
// text between them. Therefore, "[b][b]Hello[/b][/b]" will not work.
223238
// It doesn't really matter though, and won't be changed unless it

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "21.0",
55
"content_scripts": [
66
{
7-
"matches": ["https://scratch.mit.edu/users*","https://scratch.mit.edu/studios*", "https://scratch.mit.edu/projects*"],
7+
"matches": ["https://scratch.mit.edu/users*","https://scratch.mit.edu/studios*", "https://scratch.mit.edu/projects*", "https://scratch.mit.edu/messages*"],
88
"js": ["loader.js"],
99
"css": ["style.css"]
1010
}

0 commit comments

Comments
 (0)