Rewrote code for the input box.

This commit is contained in:
flash 2024-07-01 21:38:07 +00:00
parent cd16a5d1b5
commit 46549845b9
24 changed files with 483 additions and 584 deletions
src/mami.js

View file

@ -1,91 +1,93 @@
#include utility.js
#include ui/markup.js
if(!Umi.Parser) Umi.Parser = {};
if(!Umi.Parser.SockChatBBcode) Umi.Parser.SockChatBBcode = {};
Umi.Parsing = (function() {
const bbCodes = [
{
tag: 'b',
replace: '<b>{0}</b>',
button: true,
},
{
tag: 'i',
replace: '<i>{0}</i>',
button: true,
},
{
tag: 'u',
replace: '<u>{0}</u>',
button: true,
},
{
tag: 's',
replace: '<del>{0}</del>',
button: true,
},
{
tag: 'quote',
replace: '<q style="font-variant: small-caps;">{0}</q>',
button: true,
},
{
tag: 'code',
replace: '<span style="white-space: pre-wrap; font-family: monospace;">{0}</span>',
button: true,
},
{
tag: 'sjis',
replace: '<span class="sjis" style="white-space: pre-wrap;">{0}</span>',
},
{
tag: 'color',
hasArg: true,
stripArg: ';:{}<>&|\\/~\'"',
replace: '<span style="color:{0};">{1}</span>',
isToggle: true,
button: true,
},
{
tag: 'img',
stripText: '"\'',
replace: '<span title="{0}"><span title="link"><a class="markup__link" href="{0}" target="_blank" rel="nofollow noreferrer noopener">{0}</a></span>&nbsp;[<a href="#" onclick="Umi.Parser.SockChatBBcode.EmbedImage(this);return false;" class="markup__link">Embed</a>]</span>',
button: true,
},
{
tag: 'url',
stripText: '"\'',
replace: '<a href="{0}" target="_blank" rel="nofollow noreferrer noopener" class="markup__link">{0}</a>',
},
{
tag: 'url',
hasArg: true,
stripArg: '"\'',
replace: '<a href="{0}" target="_blank" rel="nofollow noreferrer noopener" class="markup__link">{1}</a>',
button: true,
},
{
tag: 'video',
stripText: '"\'',
replace: '<span title="{0}"><span title="link"><a class="markup__link" href="{0}" target="_blank" rel="nofollow noreferrer noopener">{0}</a></span>&nbsp;[<a href="#" onclick="Umi.Parser.SockChatBBcode.EmbedVideo(this);return false;" class="markup__link">Embed</a>]</span>',
button: true,
},
{
tag: 'audio',
stripText: '"\'',
replace: '<span title="{0}"><span title="link"><a class="markup__link" href="{0}" target="_blank" rel="nofollow noreferrer noopener">{0}</a></span>&nbsp;[<a href="#" onclick="Umi.Parser.SockChatBBcode.EmbedAudio(this);return false;" class="markup__link">Embed</a>]</span>',
button: true,
},
{
tag: 'spoiler',
stripText: '"\'',
replace: '<span data-shit="{0}"><span>*** HIDDEN ***</span>&nbsp;[<a href="#" onclick="Umi.Parser.SockChatBBcode.ToggleSpoiler(this);return false;" class="markup__link">Reveal</a>]</span>',
button: true,
}
];
const UmiBBCodes = [
{
tag: 'b',
text: 'B',
style: 'font-weight: 700',
replace: '<b>{0}</b>',
},
{
tag: 'i',
text: 'I',
style: 'font-style: italic',
replace: '<i>{0}</i>',
},
{
tag: 'u',
text: 'U',
style: 'text-decoration: underline',
replace: '<u>{0}</u>',
},
{
tag: 's',
text: 'S',
style: 'text-decoration: line-through',
replace: '<del>{0}</del>',
},
{
tag: 'quote',
text: 'Quote',
replace: '<q style="font-variant: small-caps;">{0}</q>',
},
{
tag: 'code',
text: 'Code',
replace: '<span style="white-space: pre-wrap; font-family: monospace;">{0}</span>',
},
{
tag: 'sjis',
replace: '<span class="sjis" style="white-space: pre-wrap;">{0}</span>',
},
{
tag: 'color',
text: 'Colour',
hasArg: true,
stripArg: ';:{}<>&|\\/~\'"',
replace: '<span style="color:{0};">{1}</span>',
},
{
tag: 'img',
text: 'Image',
stripText: '"\'',
replace: '<span title="{0}"><span title="link"><a class="markup__link" href="{0}" target="_blank" rel="nofollow noreferrer noopener">{0}</a></span>&nbsp;[<a href="#" onclick="Umi.Parser.SockChatBBcode.EmbedImage(this);return false;" class="markup__link">Embed</a>]</span>',
},
{
tag: 'url',
stripText: '"\'',
replace: '<a href="{0}" target="_blank" rel="nofollow noreferrer noopener" class="markup__link">{0}</a>',
},
{
tag: 'url',
text: 'URL',
hasArg: true,
stripArg: '"\'',
replace: '<a href="{0}" target="_blank" rel="nofollow noreferrer noopener" class="markup__link">{1}</a>',
},
{
tag: 'video',
text: 'Video',
stripText: '"\'',
replace: '<span title="{0}"><span title="link"><a class="markup__link" href="{0}" target="_blank" rel="nofollow noreferrer noopener">{0}</a></span>&nbsp;[<a href="#" onclick="Umi.Parser.SockChatBBcode.EmbedVideo(this);return false;" class="markup__link">Embed</a>]</span>',
},
{
tag: 'audio',
text: 'Audio',
stripText: '"\'',
replace: '<span title="{0}"><span title="link"><a class="markup__link" href="{0}" target="_blank" rel="nofollow noreferrer noopener">{0}</a></span>&nbsp;[<a href="#" onclick="Umi.Parser.SockChatBBcode.EmbedAudio(this);return false;" class="markup__link">Embed</a>]</span>',
},
{
tag: 'spoiler',
text: 'Spoiler',
stripText: '"\'',
replace: '<span data-shit="{0}"><span>*** HIDDEN ***</span>&nbsp;[<a href="#" onclick="Umi.Parser.SockChatBBcode.ToggleSpoiler(this);return false;" class="markup__link">Reveal</a>]</span>',
},
];
Umi.Parsing = (function() {
const replaceAll = function(haystack, needle, replace, ignore) {
return haystack.replace(
new RegExp(
@ -362,21 +364,9 @@ Umi.Parsing = (function() {
Umi.Parser.SockChatBBcode.ToggleSpoiler = toggleSpoiler;
return {
Init: function() {
for (let i = 0; i < bbCodes.length; i++) {
const bbCode = bbCodes[i];
if(!bbCode.button)
continue;
const start = '[{0}]'.replace('{0}', bbCode.tag + (bbCode.arg ? '=' : '')), end = '[/{0}]'.replace('{0}', bbCode.tag);
const text = (bbCode.tag.length > 1 ? bbCode.tag.substring(0, 1).toUpperCase() + bbCode.tag.substring(1) : bbCode.tag).replace('Color', 'Colour');
Umi.UI.Markup.Add(bbCode.tag, text, start, end);
}
},
Parse: function(element, message) {
for(let i = 0; i < bbCodes.length; i++) {
const bbCode = bbCodes[i];
for(let i = 0; i < UmiBBCodes.length; i++) {
const bbCode = UmiBBCodes[i];
if(!bbCode.hasArg) {
let at = 0;