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

Commit 198b9f3

Browse files
committed
Fixed regex parameter matching
Load ScratchFormat onto the page instead of in the extension bugs
1 parent ea5b618 commit 198b9f3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

javascript.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var tags = [
5050
"name": "link",
5151
"tag": "link",
5252
"src": "https://raw.githubusercontent.com/Remix-Design/RemixIcon/master/icons/Editor/link.svg",
53-
"fillers": ["[link=", "]Link[/link]"],
53+
"fillers": ["[link=https://example.com", "]Link[/link]"],
5454
"formatter": function(part1, part2) {
5555
return "<a href='" + part1 + "' target='_newtab'>" + part2 + "</a>";
5656
}
@@ -78,15 +78,20 @@ var tags = [
7878
setTimeout(function() {
7979
var textareaFinder = "[name=compose-comment],[name=content]";
8080

81+
// Helpful first textarea message
8182
var findFirst = document.querySelectorAll(textareaFinder);
8283
if (findFirst.length > 0) {
8384
findFirst[0].placeholder = "Click here to activate ScratchFormat";
85+
} else {
86+
// Kill all if there are no textareas
87+
return;
8488
}
8589

8690
formatter = document.createElement("div");
8791
formatter.id = "formatter";
8892
for (var t = 0; t < tags.length; t++) {
8993
if (tags[t].dontshow) {
94+
// Basically, skip to next part
9095
continue;
9196
}
9297

@@ -97,9 +102,10 @@ setTimeout(function() {
97102
if (tags[t].help) {
98103
icon.style.float = "right";
99104
icon.onclick = function() {
105+
// Popup message HTML got a bit out of hand here
100106
smod.dialogText("ScratchFormat Help", `
101-
<a href="https://github.com/ScratchFormat/ScratchFormat2/issues" style="color: #12b1e4;">Report issues at our Github</a>
102-
If you do not own a Github account, simply comment on my profile <a href="https://scratch.mit.edu/users/pufflegamerz/" style="color: #12b1e4;">@pufflegamerz</a>
107+
<a href="https://github.com/ScratchFormat/ScratchFormat2/issues" style="color: #12b1e4;">Report issues at our Github</a>
108+
If you do not own a Github account, simply comment on my profile <a href="https://scratch.mit.edu/users/pufflegamerz/" style="color: #12b1e4;">@pufflegamerz</a>
103109
`, version);
104110
}
105111

@@ -146,7 +152,7 @@ If you do not own a Github account, simply comment on my profile <a href="https:
146152
document.body.onclick = function(event) {
147153
if (event.target.name == "content" || event.target.name == "compose-comment") {
148154
event.target.parentElement.prepend(formatter);
149-
formatter.style.width = event.target.style.width;
155+
formatter.style.width = event.target.offsetWidth + "px";
150156
}
151157
}
152158

@@ -170,7 +176,7 @@ function format() {
170176
for (var c = 0; c < comments.length; c++) {
171177
comments[c].style.whiteSpace = "pre-line";
172178
if (comments[c].className == "emoji-text") {
173-
comments[c].style.marginLeft = "5px";
179+
comments[c].style.marginLeft = "3px";
174180
}
175181

176182
comments[c].innerHTML = parse(comments[c].innerText);
@@ -194,7 +200,7 @@ function parse(text) {
194200
var regex = "";
195201
regex += startBracket;
196202
regex += tags[t].tag;
197-
regex += "(=(.*))*";
203+
regex += "[=]*([^\\]\\[\\)\\(]*)";
198204
regex += endBracket;
199205

200206
// If just 1 tag (Ex [br])
@@ -207,9 +213,9 @@ function parse(text) {
207213
regex += tags[t].tag;
208214
regex += endBracket;
209215
}
210-
216+
console.log(regex);
211217
regex = new RegExp(regex, "gm");
212-
text = text.replace(regex, tags[t].formatter("$2", "$3"));
218+
text = text.replace(regex, tags[t].formatter("$1", "$2"));
213219
}
214220

215221
// Format trailing breaklines and spaces

loader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Loads javascript onto page
12
{var s = document.createElement('script');
23
s.src = chrome.extension.getURL('smod.js');
34
(document.head||document.documentElement).appendChild(s);}

smod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var smod = {
3030
// This is bad, bad, bad. If anybody can find the native
3131
// way to create popups in Scratch 3.0 React.js, let me know.
3232
dialog3: function(title, text) {
33-
var html = `"<div class="ReactModalPortal"><div class="modal-overlay modal-overlay"><div aria-label="Report Comment" class="modal-content mod-report modal-sizes modal-content mod-report" role="dialog" tabindex="-1"><div class="modal-content-close" onclick="this.parentElement.parentElement.style.display = 'none';"><img alt="close-icon" class="modal-content-close-img" draggable="true" src="/svgs/modal/close-x.svg"></div><div><div class="report-modal-header" style="background-color: #395c79; box-shadow: inset 0 -1px 0 0 #001fff;"><div class="report-content-label"><span>` + title + `</span></div></div><div class="report-modal-content" style="padding-bottom: 50px;"><div><div class="instructions"><span>` + text +`</span></div></div></div></div></div></div>"</div>`;
33+
var html = `"<div class="ReactModalPortal"><div class="modal-overlay modal-overlay"><div aria-label="Report Comment" class="modal-content mod-report modal-sizes modal-content mod-report" role="dialog" tabindex="-1"><div class="modal-content-close" onclick="this.parentElement.parentElement.parentElement.outerHTML = null;"><img alt="close-icon" class="modal-content-close-img" draggable="true" src="/svgs/modal/close-x.svg"></div><div><div class="report-modal-header" style="background-color: #395c79; box-shadow: inset 0 -1px 0 0 #001fff;"><div class="report-content-label"><span>` + title + `</span></div></div><div class="report-modal-content" style="padding-bottom: 50px;"><div><div class="instructions"><span>` + text +`</span></div></div></div></div></div></div>"</div>`;
3434
document.body.innerHTML += html;
3535
},
3636

0 commit comments

Comments
 (0)