Remove embed if empty

This commit is contained in:
Lorem Ipsum 2020-12-17 20:47:14 +00:00
parent 1a38e43b67
commit 18fcbc5056
2 changed files with 21 additions and 14 deletions

View file

@ -591,9 +591,11 @@ u {
.embed blockquote { .embed blockquote {
max-width: 100%; max-width: 100%;
} }
.blockquote { .blockquote {
display: flex; display: flex;
} }
.blockquote blockquote { .blockquote blockquote {
padding: 0 8px 0 12px; padding: 0 8px 0 12px;
box-sizing: border-box; box-sizing: border-box;
@ -604,6 +606,7 @@ u {
width: 4px; width: 4px;
border-radius: 4px; border-radius: 4px;
} }
.blockquoteDivider { .blockquoteDivider {
background-color: var(--interactive-muted); background-color: var(--interactive-muted);
} }
@ -645,12 +648,11 @@ u {
white-space: pre-wrap; white-space: pre-wrap;
} }
.markup .markup :is(pre, blockquote) { .markup pre, .markup blockquote {
max-width: 90%; max-width: 90%;
} }
.markup pre { .markup pre {
max-width: 90%;
border-radius: 4px; border-radius: 4px;
padding: 0; padding: 0;
font-family: Consolas, Andale Mono WT, Andale Mono, Lucida Console, Lucida Sans Typewriter, DejaVu Sans Mono, Bitstream Vera Sans Mono, Liberation Mono, Nimbus Mono L, Monaco, Courier New, Courier, monospace; font-family: Consolas, Andale Mono WT, Andale Mono, Lucida Console, Lucida Sans Typewriter, DejaVu Sans Mono, Bitstream Vera Sans Mono, Liberation Mono, Nimbus Mono L, Monaco, Courier New, Courier, monospace;
@ -786,8 +788,9 @@ u {
margin-top: 5px; margin-top: 5px;
animation: notifAn .5s ease; animation: notifAn .5s ease;
background-color: #202225; background-color: #202225;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
padding: 10px; padding: 10px;
border-radius: 4px;
color: #8c4949; color: #8c4949;
display: none; display: none;
width: 100%; width: 100%;

View file

@ -28,10 +28,16 @@ window.onload = () => {
if (mediaWidth && window.matchMedia(`(max-width:${mediaWidth}px)`).matches) if (mediaWidth && window.matchMedia(`(max-width:${mediaWidth}px)`).matches)
return txt.length > (length - 3) ? txt.substring(0, length - 3) + '...' : txt; return txt.length > (length - 3) ? txt.substring(0, length - 3) + '...' : txt;
return txt; return txt;
}, error = (msg, html) => { }, error = (msg, time) => {
if (html) notif.innerHTML = msg; notif.innerHTML = msg, notif.style.display = 'block';
else notif.innerText = msg; time && setTimeout(() => notif.animate({ opacity: '0', bottom: '-50px', offset: 1 }, { easing: 'ease', duration: 500 })
notif.style.display = 'block'; .onfinish = () => notif.style.removeProperty('display'), time);
return false;
}, allGood = e => {
let re = /"((icon_)?url")(: *)("(?!https?:\/\/).+?")/g.exec(editor.getValue());
if (re) return error(`URL should start with <code>https://</code> or <code>http://</code> on this line <span class="inline full">${makeShort(re[0], 30, 600)}</span>`);
if (e.timestamp && new Date(e.timestamp).toString() === "Invalid Date") return error('Timestamp is invalid');
return true;
}, markup = (txt, opts) => { }, markup = (txt, opts) => {
txt = txt txt = txt
.replace(/<:[^:]+:(\d+)>/g, '<img class="emoji" src="https://cdn.discordapp.com/emojis/$1.png"/>') .replace(/<:[^:]+:(\d+)>/g, '<img class="emoji" src="https://cdn.discordapp.com/emojis/$1.png"/>')
@ -73,13 +79,13 @@ window.onload = () => {
if (data) el.innerHTML = data; if (data) el.innerHTML = data;
el.style.display = displayType || "unset"; el.style.display = displayType || "unset";
}, hide = el => el.style.removeProperty('display'), }, hide = el => el.style.removeProperty('display'),
regEscape = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'),
toObj = jsonString => JSON.parse(jsonString.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (x, y) => y ? "" : x)), toObj = jsonString => JSON.parse(jsonString.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (x, y) => y ? "" : x)),
update = data => { update = data => {
try { try {
content.innerHTML = data.content ? markup(data.content, { replaceEmojis: true }) : ''; content.innerHTML = data.content ? markup(data.content, { replaceEmojis: true }) : '';
if (data.embed) { if (data.embed) {
let e = data.embed; let e = data.embed;
if (!allGood(e)) return;
if (e.title) display(embedTitle, markup(`${e.url ? '<a class="anchor" target="_blank" href="' + url(e.url) + '">' + e.title + '</a>' : e.title}`, { replaceEmojis: true, inlineBlock: true })); if (e.title) display(embedTitle, markup(`${e.url ? '<a class="anchor" target="_blank" href="' + url(e.url) + '">' + e.title + '</a>' : e.title}`, { replaceEmojis: true, inlineBlock: true }));
else hide(embedTitle); else hide(embedTitle);
if (e.description) display(embedDescription, markup(e.description, { inEmbed: true, replaceEmojis: true })); if (e.description) display(embedDescription, markup(e.description, { inEmbed: true, replaceEmojis: true }));
@ -130,11 +136,9 @@ window.onload = () => {
display(fields, undefined, 'grid'); display(fields, undefined, 'grid');
} else hide(fields); } else hide(fields);
embed.classList.remove('empty'); embed.classList.remove('empty');
let re = /"((icon_)?url")(: *)("(?!https?:\/\/).+?")/g.exec(editor.getValue()) notif.animate({ opacity: '0', bottom: '-50px', offset: 1 }, { easing: 'ease', duration: 500 }).onfinish = () => notif.style.removeProperty('display');
if (re) error(`URL should start with <code>https://</code> or <code>http://</code> on this line <span class="inline full">${makeShort(re[0], 30, 600)}</span>`, true);
else notif.animate({ opacity: '0', bottom: '-50px', offset: 1 }, { easing: 'ease', duration: 500 }).onfinish = () => notif.style.removeProperty('display');
twemoji.parse(msgEmbed); twemoji.parse(msgEmbed);
} } else embed.classList.add('empty');
} catch (e) { } catch (e) {
error(e); error(e);
} }
@ -151,8 +155,8 @@ window.onload = () => {
}); });
update(toObj(editor.getValue())); update(toObj(editor.getValue()));
document.querySelector('.timeText').innerText = tstamp() document.querySelector('.timeText').innerText = tstamp();
document.querySelectorAll('.markup pre > code').forEach((block) => hljs.highlightBlock(block)) document.querySelectorAll('.markup pre > code').forEach((block) => hljs.highlightBlock(block));
!window.navigator.userAgent.match(/Firefox\/[\d\.]+$/g) && // Firefox pushes the text up a little !window.navigator.userAgent.match(/Firefox\/[\d\.]+$/g) && // Firefox pushes the text up a little
document.querySelector('.botText').style.removeProperty('top'); document.querySelector('.botText').style.removeProperty('top');
}; };