Update index.js, index.css

This commit is contained in:
Glitchii 2021-06-28 13:17:57 +01:00
parent 0d36d0760c
commit c37a104b3b
2 changed files with 218 additions and 205 deletions

View file

@ -773,8 +773,6 @@ u {
.notification .inline { .notification .inline {
width: auto; width: auto;
height: auto; height: auto;
padding: .2em;
margin: -.2em 0;
border-radius: 3px; border-radius: 3px;
font-size: 85%; font-size: 85%;
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;
@ -782,11 +780,12 @@ u {
border: none; border: none;
overflow: hidden; overflow: hidden;
white-space: pre-wrap; white-space: pre-wrap;
background-color: #4a3535;
color: white; color: white;
color: inherit; color: inherit;
background-color: inherit; /* border: 1px dashed; */
border: 1px dashed; padding: .3em 0em;
border-radius: 2px;
margin: -.2em 5px;
} }
@keyframes notifAn { @keyframes notifAn {
@ -1253,7 +1252,7 @@ textarea {
.browse.error>p::after { .browse.error>p::after {
color: #ee9191; color: #ee9191;
content: "Request failed. (Check dev-tools)"; content: "Request failed. (Check console)";
} }
.linkName { .linkName {
@ -1651,8 +1650,9 @@ body {
height: 100%; height: 100%;
} }
.notification .inline { .notification .inline {
display: block;
margin-top: 5px; margin-top: 5px;
background-color: #20222500;
border: none;
} }
.bottom .colrs { .bottom .colrs {
bottom: 40px; bottom: 40px;

View file

@ -99,11 +99,24 @@ window.onload = () => {
.onfinish = () => notif.style.removeProperty('display'), time); .onfinish = () => notif.style.removeProperty('display'), time);
return false; return false;
}, allGood = e => { }, allGood = e => {
let re = /"((icon_)?url")(: *)("(?!https?:\/\/).+?")/g.exec(editor.getValue()); let str = JSON.stringify(e, null, 4), re = /("(?:icon_)?url": *")((?!\w+?:\/\/).+)"/g.exec(str);
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'); if (e.timestamp && new Date(e.timestamp).toString() === "Invalid Date") return error('Timestamp is invalid');
if (re) { // If a URL is found without a protocol
if (!/\w+:|\/\/|^\//g.exec(re[2]) && re[2].includes('.')) {
let activeInput = document.querySelector('input[class$="link" i]:focus')
if (activeInput) {
lastPos = activeInput.selectionStart + 7;
authorLink.value = `http://${re[2]}`;
update(JSON.parse(str.replace(re[0], `${re[1]}http://${re[2]}"`)));
activeInput.setSelectionRange(lastPos, lastPos)
return true; return true;
}, markup = (txt, opts) => { }
}
return error(`URL should have a protocol. Did you mean <span class="inline full short">http://${makeShort(re[2], 30, 600).replace(' ', '')}</span>?`);
}
return true;
},
markup = (txt, opts) => {
txt = txt txt = txt
.replace(/\&#60;:[^:]+:(\d+)\&#62;/g, '<img class="emoji" src="https://cdn.discordapp.com/emojis/$1.png"/>') .replace(/\&#60;:[^:]+:(\d+)\&#62;/g, '<img class="emoji" src="https://cdn.discordapp.com/emojis/$1.png"/>')
.replace(/\&#60;a:[^:]+:(\d+)\&#62;/g, '<img class="emoji" src="https://cdn.discordapp.com/emojis/$1.gif"/>') .replace(/\&#60;a:[^:]+:(\d+)\&#62;/g, '<img class="emoji" src="https://cdn.discordapp.com/emojis/$1.gif"/>')
@ -145,7 +158,7 @@ window.onload = () => {
el.style.display = displayType || "unset"; el.style.display = displayType || "unset";
}, hide = el => el.style.removeProperty('display'), }, hide = el => el.style.removeProperty('display'),
imgSrc = (elm, src, remove) => remove ? elm.style.removeProperty('content') : elm.style.content = `url(${src})`, imgSrc = (elm, src, remove) => remove ? elm.style.removeProperty('content') : elm.style.content = `url(${src})`,
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)),
buildGui = (object, opts) => { buildGui = (object, opts) => {
gui.innerHTML = ` gui.innerHTML = `
<div class="item content"><p class="ttle">Message content</p></div> <div class="item content"><p class="ttle">Message content</p></div>
@ -437,32 +450,32 @@ window.onload = () => {
}) })
gui.querySelectorAll('textarea, input').forEach(e => e.addEventListener('input', el => { gui.querySelectorAll('textarea, input').forEach(e => e.addEventListener('input', el => {
let v = el.target.value, field = el.target.closest('.field'); let value = el.target.value, field = el.target.closest('.field');
if (field) { if (field) {
let jsonField = json.embed.fields[Array.from(fields.children).indexOf(field)]; let jsonField = json.embed.fields[Array.from(fields.children).indexOf(field)];
if (jsonField) { if (jsonField) {
if (el.target.type === 'text') jsonField.name = v; if (el.target.type === 'text') jsonField.name = value;
else if (el.target.type === 'textarea') jsonField.value = v; else if (el.target.type === 'textarea') jsonField.value = value;
else jsonField.inline = el.target.checked; else jsonField.inline = el.target.checked;
} else { } else {
let obj = {} let obj = {}
if (el.target.type === 'text') obj.name = v; if (el.target.type === 'text') obj.name = value;
else if (el.target.type === 'textarea') obj.value = v; else if (el.target.type === 'textarea') obj.value = value;
else obj.inline = el.target.checked; else obj.inline = el.target.checked;
json.embed.fields.push(obj); json.embed.fields.push(obj);
} }
} else { } else {
json.embed ??= {}; json.embed ??= {};
switch (el.target) { switch (el.target) {
case content: json.content = v; break; case content: json.content = value; break;
case title: json.embed.title = v; break; case title: json.embed.title = value; break;
case authorName: json.embed.author ??= {}, json.embed.author.name = v; break; case authorName: json.embed.author ??= {}, json.embed.author.name = value; break;
case authorLink: json.embed.author ??= {}, json.embed.author.icon_url = v, imgSrc(el.target.previousElementSibling, v); break; case authorLink: json.embed.author ??= {}, json.embed.author.icon_url = value, imgSrc(el.target.previousElementSibling, value); break;
case desc: json.embed.description = v; break; case desc: json.embed.description = value; break;
case thumbLink: json.embed.thumbnail ??= {}, json.embed.thumbnail.url = v, imgSrc(el.target.closest('.editIcon').querySelector('.imgParent'), v); break; case thumbLink: json.embed.thumbnail ??= {}, json.embed.thumbnail.url = value, imgSrc(el.target.closest('.editIcon').querySelector('.imgParent'), value); break;
case imgLink: json.embed.image ??= {}, json.embed.image.url = v, imgSrc(el.target.closest('.editIcon').querySelector('.imgParent'), v); break; case imgLink: json.embed.image ??= {}, json.embed.image.url = value, imgSrc(el.target.closest('.editIcon').querySelector('.imgParent'), value); break;
case footerText: json.embed.footer ??= {}, json.embed.footer.text = v; break; case footerText: json.embed.footer ??= {}, json.embed.footer.text = value; break;
case footerLink: json.embed.footer ??= {}, json.embed.footer.icon_url = v, imgSrc(el.target.previousElementSibling, v); break; case footerLink: json.embed.footer ??= {}, json.embed.footer.icon_url = value, imgSrc(el.target.previousElementSibling, value); break;
} }
} }
update(json); update(json);
@ -510,13 +523,13 @@ window.onload = () => {
imgSrc(e.target.previousElementSibling.querySelector('.editIcon > .imgParent') || e.target.closest('.editIcon').querySelector('.imgParent'), res.link); imgSrc(e.target.previousElementSibling.querySelector('.editIcon > .imgParent') || e.target.closest('.editIcon').querySelector('.imgParent'), res.link);
let input = e.target.previousElementSibling.querySelector('.editIcon > input') || e.target.previousElementSibling; let input = e.target.previousElementSibling.querySelector('.editIcon > input') || e.target.previousElementSibling;
input.value = res.link; input.value = res.link;
if (input === authorLink) json.embed.author.icon_url = res.link; if (input === authorLink) ((json.embed ??= {}).author ??= {}).icon_url = res.link;
else if (input === thumbLink) json.embed.thumbnail.url = res.link; else if (input === thumbLink) ((json.embed ??= {}).thumbnail ??= {}).url = res.link;
else if (input === imgLink) json.embed.image.url = res.link; else if (input === imgLink) ((json.embed ??= {}).image ??= {}).url = res.link;
else json.embed.footer.icon_url = res.link; else ((json.embed ??= {}).footer ??= {}).url = res.link;
update(json); update(json);
console.info(`Image (${res.link}) will be deleted in 5 minutes. To delete it now got to ${res.link.replace('/files', '/del')} and enter this code: ${res.authkey}`); console.info(`Image (${res.link}) will be deleted in 10 minutes. To delete it now, go to ${res.link.replace('/files', '/del')} and enter this code: ${res.authkey}`);
}).catch(err => `Request to tempfile.site failed with error: ${err}`) }).catch(err => error(`Request to tempfile.site failed with error: ${err}`, 5000))
})) }))
} }