Realized I forgot a couple of lines, this should hopefully ensure consistent behavior.
Just making sure that already formatted text will still be "postable" if something goes wrong. Most of this shit is irrelevant unless you are under the effect of the hieroglyph award.master
parent
b3331bf672
commit
b1558dc5e3
286
project.js
286
project.js
|
@ -1,143 +1,145 @@
|
||||||
// Picks the first default chatbox, just to have something here by default
|
// Picks the first default chatbox, just to have something here by default
|
||||||
// I ASSUME, this is done automatically when the page loads, but IDK how JS is actually implemented by browsers
|
// I ASSUME, this is done automatically when the page loads, but IDK how JS is actually implemented by browsers
|
||||||
// You can't force me to read the documentation, I REFUSE! I just WON'T, OK?? Haha.
|
// You can't force me to read the documentation, I REFUSE! I just WON'T, OK?? Haha.
|
||||||
let textBox = document.querySelector('[id*="reply-form-body-"]');
|
let textBox = document.querySelector('[id*="reply-form-body-"]');
|
||||||
let vari = "";
|
let vari = "";
|
||||||
let originalFunction = null;
|
let originalFunction = null;
|
||||||
let fucName = null;
|
let fucName = null;
|
||||||
let funcFull = "";
|
let funcFull = "";
|
||||||
let Marseys = [];
|
let Marseys = [];
|
||||||
|
|
||||||
//The comments are terrible, I know. Too bad!
|
//The comments are terrible, I know. Too bad!
|
||||||
|
|
||||||
const specialCases = {
|
const specialCases = {
|
||||||
"å": ":aa:", "Å": ":aa:",
|
"å": ":aa:", "Å": ":aa:",
|
||||||
"æ": ":ae:", "Æ": ":ae:",
|
"æ": ":ae:", "Æ": ":ae:",
|
||||||
"ø": ":oo:", "Ø": ":oo:",
|
"ø": ":oo:", "Ø": ":oo:",
|
||||||
" ": ":space:",
|
" ": ":space:",
|
||||||
"?": ":questionmark:",
|
"?": ":questionmark:",
|
||||||
"!": ":exclamationpoint:",
|
"!": ":exclamationpoint:",
|
||||||
".": ":period:",
|
".": ":period:",
|
||||||
",": ":comma:",
|
",": ":comma:",
|
||||||
"-": ":dash:",
|
"-": ":dash:",
|
||||||
"'": ":apostrophe:",
|
"'": ":apostrophe:",
|
||||||
'"': ":quotation:",
|
'"': ":quotation:",
|
||||||
"/": ":slash:", "\\": ":!slash:",
|
"/": ":slash:", "\\": ":!slash:",
|
||||||
"+": ":plus:",
|
"+": ":plus:",
|
||||||
"*": ":asterisk:",
|
"*": ":asterisk:",
|
||||||
"<": ":angle:", ">": ":!angle:",
|
"<": ":angle:", ">": ":!angle:",
|
||||||
"=": ":equals:",
|
"=": ":equals:",
|
||||||
"_": ":underscore:",
|
"_": ":underscore:",
|
||||||
"^": ":land:",
|
"^": ":land:",
|
||||||
":": ":colon:",
|
":": ":colon:",
|
||||||
"(": ":paren:", ")": ":!paren:",
|
"(": ":paren:", ")": ":!paren:",
|
||||||
"{": ":brace:", "}": ":!brace:",
|
"{": ":brace:", "}": ":!brace:",
|
||||||
"@": ":at:",
|
"@": ":at:",
|
||||||
"&": ":ampersand:",
|
"&": ":ampersand:",
|
||||||
"|": ":vert:",
|
"|": ":vert:",
|
||||||
"%": ":percent:",
|
"%": ":percent:",
|
||||||
"#": ":pound:",
|
"#": ":pound:",
|
||||||
"¤": "\n" // Use "¤" as a placeholder for newlines. Who uses ¤ for anything anyway?
|
"¤": "\n" // Use "¤" as a placeholder for newlines. Who uses ¤ for anything anyway?
|
||||||
};
|
};
|
||||||
|
|
||||||
//This pile of shit was made by @Count_Sprpr, I hate JS like I hate the antichrist
|
//This pile of shit was made by @Count_Sprpr, I hate JS like I hate the antichrist
|
||||||
//Things to MAYBE improve:
|
//Things to MAYBE improve:
|
||||||
//3. Fix bugs that I haven't experienced or thought of
|
//3. Fix bugs that I haven't experienced or thought of
|
||||||
|
|
||||||
//Removes the function in the button element so that clicking the button won't immediately post the comment
|
//Removes the function in the button element so that clicking the button won't immediately post the comment
|
||||||
//This triggers on hover
|
//This triggers on hover
|
||||||
document.addEventListener("mouseover", function (event) {
|
document.addEventListener("mouseover", function (event) {
|
||||||
if (event.target.id.includes("save-reply-to-p") || event.target.id.includes("save-reply-to-c") || event.target.id.includes("save-reply-to-u")) {
|
if (event.target.id.includes("save-reply-to-p") || event.target.id.includes("save-reply-to-c") || event.target.id.includes("save-reply-to-u")) {
|
||||||
const dataOnClickValue = event.target.getAttribute('data-onclick');
|
const dataOnClickValue = event.target.getAttribute('data-onclick');
|
||||||
if (dataOnClickValue === null) {
|
if (dataOnClickValue === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fucName = dataOnClickValue.match(/(\w+)\(/);
|
fucName = dataOnClickValue.match(/(\w+)\(/);
|
||||||
vari = dataOnClickValue.match(/\(([^)]*)\)/); // Match arguments inside the parentheses
|
vari = dataOnClickValue.match(/\(([^)]*)\)/); // Match arguments inside the parentheses
|
||||||
funcFull = fucName[1] + vari[0];
|
funcFull = fucName[1] + vari[0];
|
||||||
event.target.removeAttribute('data-onclick');
|
event.target.removeAttribute('data-onclick');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Adds the function back when we stop hovering over, this should hopefully prevent weird behavior.
|
//Adds the function back when we stop hovering over, this should hopefully prevent weird behavior.
|
||||||
document.addEventListener("mouseout", function (event) {
|
document.addEventListener("mouseout", function (event) {
|
||||||
if (event.target.id.includes("save-reply-to-p") || event.target.id.includes("save-reply-to-c") || event.target.id.includes("save-reply-to-u")) {
|
if (event.target.id.includes("save-reply-to-p") || event.target.id.includes("save-reply-to-c") || event.target.id.includes("save-reply-to-u")) {
|
||||||
event.target.setAttribute('data-onclick', funcFull);
|
event.target.setAttribute('data-onclick', funcFull);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("click", function (event) {
|
document.addEventListener("click", function (event) {
|
||||||
// Will automatically set the textbox when you hit the "reply" button to spawn it
|
// Will automatically set the textbox when you hit the "reply" button to spawn it
|
||||||
if (event.target.id.includes("toggle-reply-")) {
|
if (event.target.id.includes("toggle-reply-")) {
|
||||||
let id = "reply-form-body-" + event.target.id.toString().substr(13);
|
let id = "reply-form-body-" + event.target.id.toString().substr(13);
|
||||||
id = '[id*="' + id + '"]';
|
id = '[id*="' + id + '"]';
|
||||||
textBox = document.querySelector(id);
|
textBox = document.querySelector(id);
|
||||||
}
|
}
|
||||||
// This should handle posts
|
// This should handle posts
|
||||||
if (event.target.id.toString() === "submit-btn") {
|
if (event.target.id.toString() === "submit-btn") {
|
||||||
document.querySelector('[id*="post-title"]').value = formattText(document.querySelector('[id*="post-title"]').value);
|
document.querySelector('[id*="post-title"]').value = formattText(document.querySelector('[id*="post-title"]').value);
|
||||||
document.querySelector('[id*="post-text"]').value = formattText(document.querySelector('[id*="post-text"]').value);
|
document.querySelector('[id*="post-text"]').value = formattText(document.querySelector('[id*="post-text"]').value);
|
||||||
}
|
}
|
||||||
//If you reply to someone, click the textbox you write in, and it will be set here
|
//If you reply to someone, click the textbox you write in, and it will be set here
|
||||||
if (event.target.tagName === "TEXTAREA") {
|
if (event.target.tagName === "TEXTAREA") {
|
||||||
textBox = event.target;
|
textBox = event.target;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.target.id.includes("save-reply-to-p") || event.target.id.includes("save-reply-to-c") || event.target.id.includes("save-reply-to-u")) {
|
if (event.target.id.includes("save-reply-to-p") || event.target.id.includes("save-reply-to-c") || event.target.id.includes("save-reply-to-u")) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let unformattedText = textBox.value;
|
let unformattedText = textBox.value;
|
||||||
//If the text has already been formatted, indicated by the unformatted text starting with ":", don't do it again. This is flawed, I know.
|
//If the text has already been formatted, indicated by the unformatted text starting with ":", don't do it again. This is flawed, I know.
|
||||||
if (unformattedText[0] === ":") {
|
if (unformattedText[0] === ":") {
|
||||||
return;
|
event.target.setAttribute('data-onclick', funcFull);
|
||||||
}
|
event.target.click();
|
||||||
// Do I need to initialize this to a string? Probably not, but it makes it easier to work with in VScode
|
return;
|
||||||
// I HATE dynamic typing, I HATE dynamic typing, I HATE dynamic typing
|
}
|
||||||
let formattedText = "";
|
// Do I need to initialize this to a string? Probably not, but it makes it easier to work with in VScode
|
||||||
formattedText = formattText(unformattedText);
|
// I HATE dynamic typing, I HATE dynamic typing, I HATE dynamic typing
|
||||||
//Replace text
|
let formattedText = "";
|
||||||
textBox.value = formattedText;
|
formattedText = formattText(unformattedText);
|
||||||
//Add the onclick function back to the button.
|
//Replace text
|
||||||
event.target.setAttribute('data-onclick', funcFull);
|
textBox.value = formattedText;
|
||||||
//Click the button.
|
//Add the onclick function back to the button.
|
||||||
event.target.click();
|
event.target.setAttribute('data-onclick', funcFull);
|
||||||
}
|
//Click the button.
|
||||||
});
|
event.target.click();
|
||||||
|
}
|
||||||
|
});
|
||||||
// Helper function to format the text
|
|
||||||
function formattText(unformattedText) {
|
|
||||||
//To fix newlines I replace them with ¤, this is bad-ish, I know
|
// Helper function to format the text
|
||||||
unformattedText = unformattedText.replace(/\n/g, "¤");
|
function formattText(unformattedText) {
|
||||||
unformattedText = replaceSubstrings(unformattedText);
|
//To fix newlines I replace them with ¤, this is bad-ish, I know
|
||||||
let formattedText = "";
|
unformattedText = unformattedText.replace(/\n/g, "¤");
|
||||||
for (let i = 0; i < unformattedText.length; i++) {
|
unformattedText = replaceSubstrings(unformattedText);
|
||||||
// Checks ASCII codes, normal text is the most common symbols, so having this here first should hopefully improve performance
|
let formattedText = "";
|
||||||
// Apparently you can't test test char with String[i] in JS. Hurray.
|
for (let i = 0; i < unformattedText.length; i++) {
|
||||||
if ((unformattedText.charCodeAt(i) >= 48 && unformattedText.charCodeAt(i) < 58)
|
// Checks ASCII codes, normal text is the most common symbols, so having this here first should hopefully improve performance
|
||||||
|| (unformattedText.charCodeAt(i) >= 65 && unformattedText.charCodeAt(i) < 91)
|
// Apparently you can't test test char with String[i] in JS. Hurray.
|
||||||
|| (unformattedText.charCodeAt(i) >= 97 && unformattedText.charCodeAt(i) < 123)) {
|
if ((unformattedText.charCodeAt(i) >= 48 && unformattedText.charCodeAt(i) < 58)
|
||||||
// Normal cases, why can't they all be like this??
|
|| (unformattedText.charCodeAt(i) >= 65 && unformattedText.charCodeAt(i) < 91)
|
||||||
formattedText += ":" + unformattedText[i] + ":";
|
|| (unformattedText.charCodeAt(i) >= 97 && unformattedText.charCodeAt(i) < 123)) {
|
||||||
} else if (unformattedText[i] === "€") {
|
// Normal cases, why can't they all be like this??
|
||||||
formattedText += Marseys.shift();
|
formattedText += ":" + unformattedText[i] + ":";
|
||||||
} else if (specialCases[unformattedText[i]] !== undefined) {
|
} else if (unformattedText[i] === "€") {
|
||||||
formattedText += specialCases[unformattedText[i]];
|
formattedText += Marseys.shift();
|
||||||
} else {
|
} else if (specialCases[unformattedText[i]] !== undefined) {
|
||||||
formattedText += unformattedText[i];
|
formattedText += specialCases[unformattedText[i]];
|
||||||
}
|
} else {
|
||||||
}
|
formattedText += unformattedText[i];
|
||||||
return formattedText;
|
}
|
||||||
}
|
}
|
||||||
|
return formattedText;
|
||||||
function replaceSubstrings(unformattedText) {
|
}
|
||||||
// Regular expression to find substrings that start and end with ":" and "["+"]". Thanks chatGPT
|
|
||||||
let regex = /(:[^:]*:|\[[^\]]*\])/g;
|
function replaceSubstrings(unformattedText) {
|
||||||
let match;
|
// Regular expression to find substrings that start and end with ":" and "["+"]". Thanks chatGPT
|
||||||
// Find all matches and add to the array
|
let regex = /(:[^:]*:|\[[^\]]*\])/g;
|
||||||
while ((match = regex.exec(unformattedText)) !== null) {
|
let match;
|
||||||
Marseys.push(match[0].trim()); // Add full match including the colons
|
// Find all matches and add to the array
|
||||||
}
|
while ((match = regex.exec(unformattedText)) !== null) {
|
||||||
// Replace all substrings with "€"
|
Marseys.push(match[0].trim()); // Add full match including the colons
|
||||||
let modifiedString = unformattedText.replace(regex, "€");
|
}
|
||||||
return modifiedString;
|
// Replace all substrings with "€"
|
||||||
|
let modifiedString = unformattedText.replace(regex, "€");
|
||||||
|
return modifiedString;
|
||||||
}
|
}
|
Loading…
Reference in New Issue