Add reverse and uodated URL options to menu, fix timestamp issue on start

This commit is contained in:
Glitchii 2022-03-07 19:17:13 +00:00
parent 3693b4d947
commit a8f2e1b35a
4 changed files with 108 additions and 39 deletions

View file

@ -43,6 +43,7 @@ placeholders=errors This also disables automatic insertion of 'http' for url
Except, warnings won't be silenced. The user will still see a warning that a url or timestamp (etc.) is incorrect for 5 seconds. Except, warnings won't be silenced. The user will still see a warning that a url or timestamp (etc.) is incorrect for 5 seconds.
``` ```
<small>Case matters, all parameters should be lowercase.</small>
### Example URL with all* the above parameters: ### Example URL with all* the above parameters:
https://glitchii.github.io/embedbuilder/?username=Troy&verified&reverse&guitabs=image,footer&avatar=https://cdn.discordapp.com/avatars/663074487335649292/576eb5f13519b9da10ba7807bdd83fab.webp https://glitchii.github.io/embedbuilder/?username=Troy&verified&reverse&guitabs=image,footer&avatar=https://cdn.discordapp.com/avatars/663074487335649292/576eb5f13519b9da10ba7807bdd83fab.webp

View file

@ -287,17 +287,17 @@ img[alt] {
} }
.mention.channel::before { .mention.channel::before {
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='hsl(236,calc(83.3%),92.9%)' fill-rule='evenodd' clip-rule='evenodd' d='M5.88657 21C5.57547 21 5.3399 20.7189 5.39427 20.4126L6.00001 17H2.59511C2.28449 17 2.04905 16.7198 2.10259 16.4138L2.27759 15.4138C2.31946 15.1746 2.52722 15 2.77011 15H6.35001L7.41001 9H4.00511C3.69449 9 3.45905 8.71977 3.51259 8.41381L3.68759 7.41381C3.72946 7.17456 3.93722 7 4.18011 7H7.76001L8.39677 3.41262C8.43914 3.17391 8.64664 3 8.88907 3H9.87344C10.1845 3 10.4201 3.28107 10.3657 3.58738L9.76001 7H15.76L16.3968 3.41262C16.4391 3.17391 16.6466 3 16.8891 3H17.8734C18.1845 3 18.4201 3.28107 18.3657 3.58738L17.76 7H21.1649C21.4755 7 21.711 7.28023 21.6574 7.58619L21.4824 8.58619C21.4406 8.82544 21.2328 9 20.9899 9H17.41L16.35 15H19.7549C20.0655 15 20.301 15.2802 20.2474 15.5862L20.0724 16.5862C20.0306 16.8254 19.8228 17 19.5799 17H16L15.3632 20.5874C15.3209 20.8261 15.1134 21 14.8709 21H13.8866C13.5755 21 13.3399 20.7189 13.3943 20.4126L14 17H8.00001L7.36325 20.5874C7.32088 20.8261 7.11337 21 6.87094 21H5.88657ZM9.41045 9L8.35045 15H14.3504L15.4104 9H9.41045Z'%3E%3C/path%3E%3C/svg%3E"); content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='hsl(236,calc(83.3%),92.9%)' fill-rule='evenodd' clip-rule='evenodd' d='M5.88657 21C5.57547 21 5.3399 20.7189 5.39427 20.4126L6.00001 17H2.59511C2.28449 17 2.04905 16.7198 2.10259 16.4138L2.27759 15.4138C2.31946 15.1746 2.52722 15 2.77011 15H6.35001L7.41001 9H4.00511C3.69449 9 3.45905 8.71977 3.51259 8.41381L3.68759 7.41381C3.72946 7.17456 3.93722 7 4.18011 7H7.76001L8.39677 3.41262C8.43914 3.17391 8.64664 3 8.88907 3H9.87344C10.1845 3 10.4201 3.28107 10.3657 3.58738L9.76001 7H15.76L16.3968 3.41262C16.4391 3.17391 16.6466 3 16.8891 3H17.8734C18.1845 3 18.4201 3.28107 18.3657 3.58738L17.76 7H21.1649C21.4755 7 21.711 7.28023 21.6574 7.58619L21.4824 8.58619C21.4406 8.82544 21.2328 9 20.9899 9H17.41L16.35 15H19.7549C20.0655 15 20.301 15.2802 20.2474 15.5862L20.0724 16.5862C20.0306 16.8254 19.8228 17 19.5799 17H16L15.3632 20.5874C15.3209 20.8261 15.1134 21 14.8709 21H13.8866C13.5755 21 13.3399 20.7189 13.3943 20.4126L14 17H8.00001L7.36325 20.5874C7.32088 20.8261 7.11337 21 6.87094 21H5.88657ZM9.41045 9L8.35045 15H14.3504L15.4104 9H9.41045Z'%3E%3C/path%3E%3C/svg%3E");
width: 1.05rem; width: 1.05rem;
height: 1.3rem; height: 1.3rem;
-o-object-fit: contain; -o-object-fit: contain;
object-fit: contain; object-fit: contain;
position: relative; position: relative;
left: .125rem; left: .125rem;
top: 3px; top: 3px;
display: inline-block; display: inline-block;
margin-right: .125rem; margin-right: .125rem;
color: hsl(236, calc(83.3%),92.9%); color: hsl(236, calc(83.3%), 92.9%);
} }
.mention.interactive:hover { .mention.interactive:hover {
@ -1009,7 +1009,7 @@ u {
color: #8c4949; color: #8c4949;
display: none; display: none;
width: 100%; width: 100%;
z-index: 5; z-index: 6;
} }
.col.cm-string.cm-property::before { .col.cm-string.cm-property::before {
@ -1845,14 +1845,37 @@ body {
margin-bottom: 5px; margin-bottom: 5px;
font-size: 13px; font-size: 13px;
transition: .5s ease; transition: .5s ease;
display: flex;
gap: 10px;
text-align: center;
align-content: center;
} }
.top-btn.menu>.box .item:hover { .top-btn.menu>.box .item:hover {
background: #35373f; background: #35373f;
} }
.top-btn.menu>.box .item.datalink>svg { .vs {
background: linear-gradient(to left, #3b3c4400, #44444d, #3b3c4400);
margin: 10px 0;
width: 100%;
height: 1px;
left: 50%;
position: relative;
transform: translateX(-50%);
}
/* .top-btn.menu>.box .item>svg {
transform: translateY(3px); transform: translateY(3px);
} */
.top-btn.menu>.box .item>* {
align-self: flex-end;
margin: 0;
}
.top-btn.menu>.box .item>input {
pointer-events: none;
} }
.top-btn.menu.active { .top-btn.menu.active {

View file

@ -11,12 +11,20 @@ var params = new URL(location).searchParams,
guiTabs = params.get('guitabs'), guiTabs = params.get('guitabs'),
useJsonEditor = params.get('editor') === 'json', useJsonEditor = params.get('editor') === 'json',
botVerified = hasParam('verified'), botVerified = hasParam('verified'),
reverseColmns = hasParam('reverse'), reverseColumns = hasParam('reverse'),
noUser = hasParam('nouser'), noUser = hasParam('nouser'),
onlyEmbed = hasParam('embed'), onlyEmbed = hasParam('embed'),
activeFields, colNum = 1, num = 0, validationError, activeFields, colNum = 1, num = 0, validationError,
allowPlaceholders = hasParam('placeholders'), allowPlaceholders = hasParam('placeholders'),
autoUpdateURL = localStorage.getItem('autoUpdateURL'), autoUpdateURL = localStorage.getItem('autoUpdateURL'),
autoParams = hasParam('autoparams') || localStorage.getItem('autoParams'),
toggleStored = item => {
const found = localStorage.getItem(item);
if (!found) return localStorage.setItem(item, true);
localStorage.removeItem(item);
return found;
},
jsonToBase64 = (jsonCode, withURL, redirect) => { jsonToBase64 = (jsonCode, withURL, redirect) => {
data = btoa(escape((JSON.stringify(typeof jsonCode === 'object' ? jsonCode : json)))); data = btoa(escape((JSON.stringify(typeof jsonCode === 'object' ? jsonCode : json))));
if (withURL) { if (withURL) {
@ -40,6 +48,21 @@ var params = new URL(location).searchParams,
hex = hex.replace('#', '').match(/.{1,2}/g) hex = hex.replace('#', '').match(/.{1,2}/g)
return [parseInt(hex[0], 16), parseInt(hex[1], 16), parseInt(hex[2], 16), 1]; return [parseInt(hex[0], 16), parseInt(hex[1], 16), parseInt(hex[2], 16), 1];
}, },
reverse = (reversed, callback) => {
const side = document.querySelector(reversed ? '.side2' : '.side1');
if (side.nextElementSibling) side.parentElement.insertBefore(side.nextElementSibling, side);
else side.parentElement.insertBefore(side, side.parentElement.firstElementChild);
const isReversed = document.body.classList.toggle('reversed');
if (autoParams) isReversed ? urlOptions({ set: ['reverse', ''] }) : urlOptions({ remove: 'reverse' });
},
urlOptions = ({ remove, set }) => {
const url = new URL(location.href);
if (remove) url.searchParams.delete(remove);
if (set) url.searchParams.set(set[0], set[1]);
// history.replaceState(null, null, url.href);
history.replaceState(null, null, url.href.replace(/=&|=$/g, x => x === '=' ? '' : '&'));
},
mainKeys = ["author", "footer", "color", "thumbnail", "image", "fields", "title", "description", "url", "timestamp"], mainKeys = ["author", "footer", "color", "thumbnail", "image", "fields", "title", "description", "url", "timestamp"],
jsonKeys = ["embed", "content", ...mainKeys], jsonKeys = ["embed", "content", ...mainKeys],
json = { json = {
@ -105,7 +128,7 @@ if (dataSpecified)
if (allowPlaceholders) if (allowPlaceholders)
allowPlaceholders = params.get('placeholders') === 'errors' ? 1 : 2; allowPlaceholders = params.get('placeholders') === 'errors' ? 1 : 2;
addEventListener('load', () => { addEventListener('DOMContentLoaded', () => {
if (onlyEmbed) if (onlyEmbed)
document.body.classList.add('only-embed'); document.body.classList.add('only-embed');
else { else {
@ -120,14 +143,12 @@ addEventListener('load', () => {
if (botIcon) document.querySelector('.avatar').src = botIcon; if (botIcon) document.querySelector('.avatar').src = botIcon;
if (botVerified) document.querySelector('.msgEmbed > .contents').classList.add('verified'); if (botVerified) document.querySelector('.msgEmbed > .contents').classList.add('verified');
} }
if (reverseColmns) { if (reverseColumns || localStorage.getItem('reverseColumns'))
const side1 = document.querySelector('.side1'); reverse();
side1.parentElement.insertBefore(side1.nextElementSibling, side1);
document.body.classList.add('reversed');
};
if (autoUpdateURL) if (autoUpdateURL)
document.querySelector('.top-btn.menu .item.auto input').checked = true; document.querySelector('.top-btn.menu .item.auto input').checked = true;
if (autoParams)
document.querySelector('.auto-params > input').checked = true;
document.querySelectorAll('.clickable > img') document.querySelectorAll('.clickable > img')
.forEach(e => e.parentElement.addEventListener('mouseup', el => window.open(el.target.src))); .forEach(e => e.parentElement.addEventListener('mouseup', el => window.open(el.target.src)));
@ -182,10 +203,11 @@ addEventListener('load', () => {
return false; return false;
}, allGood = e => { }, allGood = e => {
let invalid, err, str = JSON.stringify(e, null, 4), re = /("(?:icon_)?url": *")((?!\w+?:\/\/).+)"/g.exec(str); let invalid, err, str = JSON.stringify(e, null, 4), re = /("(?:icon_)?url": *")((?!\w+?:\/\/).+)"/g.exec(str);
if (e.timestamp && new Date(e.timestamp).toString() === "Invalid Date") if (e.timestamp && new Date(e.timestamp).toString() === "Invalid Date") {
if (allowPlaceholders === 2) return true; if (allowPlaceholders === 2) return true;
if (!allowPlaceholders) invalid = true, err = 'Timestamp is invalid'; if (!allowPlaceholders)
else if (re) { // If a URL is found without a protocol invalid = true, err = 'Timestamp is invalid';
} else if (re) { // If a URL is found without a protocol
if (!/\w+:|\/\/|^\//g.exec(re[2]) && re[2].includes('.')) { if (!/\w+:|\/\/|^\//g.exec(re[2]) && re[2].includes('.')) {
let activeInput = document.querySelector('input[class$="link" i]:focus') let activeInput = document.querySelector('input[class$="link" i]:focus')
if (activeInput && !allowPlaceholders) { if (activeInput && !allowPlaceholders) {
@ -538,7 +560,7 @@ addEventListener('load', () => {
} else if (txt && !smallerScreen.matches) } else if (txt && !smallerScreen.matches)
txt.focus(); txt.focus();
if (elm.classList.contains('fields')) { if (elm.classList.contains('fields')) {
if (reverseColmns && smallerScreen.matches) if (reverseColumns && smallerScreen.matches)
// return elm.nextElementSibling.scrollIntoView({ behavior: 'smooth', block: "end" }); // return elm.nextElementSibling.scrollIntoView({ behavior: 'smooth', block: "end" });
return elm.parentNode.scrollTop = elm.offsetTop; return elm.parentNode.scrollTop = elm.offsetTop;
elm.scrollIntoView({ behavior: "smooth", block: "center" }); elm.scrollIntoView({ behavior: "smooth", block: "center" });
@ -552,7 +574,7 @@ addEventListener('load', () => {
requiresView = matchMedia(`${smallerScreen.media}, (max-height: 845px)`); requiresView = matchMedia(`${smallerScreen.media}, (max-height: 845px)`);
document.querySelectorAll('.gui>.item:not(.fields)').forEach(e => e.addEventListener('click', () => { document.querySelectorAll('.gui>.item:not(.fields)').forEach(e => e.addEventListener('click', () => {
if (lastTabs.includes(e) || requiresView.matches) { if (lastTabs.includes(e) || requiresView.matches) {
if (!reverseColmns || !smallerScreen.matches) e.scrollIntoView({ behavior: 'smooth', block: "center" }); if (!reverseColumns || !smallerScreen.matches) e.scrollIntoView({ behavior: 'smooth', block: "center" });
else if (e.nextElementSibling.classList.contains('edit') && e.classList.contains('active')) else if (e.nextElementSibling.classList.contains('edit') && e.classList.contains('active'))
// e.nextElementSibling.scrollIntoView({ behavior: 'smooth', block: "end" }); // e.nextElementSibling.scrollIntoView({ behavior: 'smooth', block: "end" });
e.parentNode.scrollTop = e.offsetTop; e.parentNode.scrollTop = e.offsetTop;
@ -779,12 +801,8 @@ addEventListener('load', () => {
} else document.body.classList.add('emptyEmbed'); } else document.body.classList.add('emptyEmbed');
if (!embedCont.innerText) document.body.classList.add('emptyEmbed'); if (!embedCont.innerText) document.body.classList.add('emptyEmbed');
json = data; json = data;
if (autoUpdateURL) { if (autoUpdateURL)
// Update data param in url. urlOptions({ set: ['data', jsonToBase64(json)] })
const url = new URL(location.href);
url.searchParams.set('data', jsonToBase64(json));
history.replaceState(null, null, url.href);
}
} catch (e) { } catch (e) {
console.log(e); console.log(e);
error(e); error(e);
@ -907,16 +925,27 @@ addEventListener('load', () => {
document.querySelector('.top-btn.menu').addEventListener('click', e => { document.querySelector('.top-btn.menu').addEventListener('click', e => {
if (e.target.closest('.item.datalink')) if (e.target.closest('.item.datalink'))
prompt('Here\'s the current URL with base64 embed data:', jsonToBase64(json, true)); return prompt('Here\'s the current URL with base64 embed data:', jsonToBase64(json, true));
else if (e.target.closest('.item.auto')) {
const input = e.target.closest('.item.auto').querySelector('input'); const input = e.target.closest('.item')?.querySelector('input');
input.checked = e.target === input ? input.checked : !input.checked; if (input) input.checked = !input.checked;
if (e.target.closest('.item.auto')) {
autoUpdateURL = input.checked; autoUpdateURL = input.checked;
if (input.checked) localStorage.setItem('autoUpdateURL', true); if (input.checked) localStorage.setItem('autoUpdateURL', true);
else localStorage.removeItem('autoUpdateURL'); else localStorage.removeItem('autoUpdateURL');
update(json); update(json);
} } else if (e.target.closest('.item.reverse')) {
reverse(reverseColumns);
reverseColumns = !reverseColumns;
toggleStored('reverseColumns');
} else if (e.target.closest('.item.auto-params')) {
if (input.checked) localStorage.setItem('autoParams', true);
else localStorage.removeItem('autoParams');
autoParams = input.checked;
console.log(input?.checked, e.target.closest('.item.auto-params'))
}
e.target.closest('.top-btn').classList.toggle('active') e.target.closest('.top-btn').classList.toggle('active')
}) })

View file

@ -103,11 +103,27 @@
<path d="M4.715 6.542 3.343 7.914a3 3 0 1 0 4.243 4.243l1.828-1.829A3 3 0 0 0 8.586 5.5L8 6.086a1.002 1.002 0 0 0-.154.199 2 2 0 0 1 .861 3.337L6.88 11.45a2 2 0 1 1-2.83-2.83l.793-.792a4.018 4.018 0 0 1-.128-1.287z"/> <path d="M4.715 6.542 3.343 7.914a3 3 0 1 0 4.243 4.243l1.828-1.829A3 3 0 0 0 8.586 5.5L8 6.086a1.002 1.002 0 0 0-.154.199 2 2 0 0 1 .861 3.337L6.88 11.45a2 2 0 1 1-2.83-2.83l.793-.792a4.018 4.018 0 0 1-.128-1.287z"/>
<path d="M6.586 4.672A3 3 0 0 0 7.414 9.5l.775-.776a2 2 0 0 1-.896-3.346L9.12 3.55a2 2 0 1 1 2.83 2.83l-.793.792c.112.42.155.855.128 1.287l1.372-1.372a3 3 0 1 0-4.243-4.243L6.586 4.672z"/> <path d="M6.586 4.672A3 3 0 0 0 7.414 9.5l.775-.776a2 2 0 0 1-.896-3.346L9.12 3.55a2 2 0 1 1 2.83 2.83l-.793.792c.112.42.155.855.128 1.287l1.372-1.372a3 3 0 1 0-4.243-4.243L6.586 4.672z"/>
</svg> </svg>
<span>Get data link</span> <div>Get data link</div>
</div> </div>
<div class="item auto"> <div class="item auto">
<input type="checkbox" id="auto" name="auto" autocomplete="off"> <input type="checkbox" id="auto" name="auto" autocomplete="off">
<span>Auto-update data link in URL</span> <div>Auto-update data link in URL</div>
</div>
<div class="item reverse">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="16" height="16" x="0" y="0" viewBox="0 0 20 20" xml:space="preserve">
<g>
<g xmlns="http://www.w3.org/2000/svg" fill="#2b2a3d">
<path d="m14.6 8.6 1.4 1.4 4-4-4-4-1.4 1.4 1.6 1.6h-16.2v2h16.2z" fill="#ffffff"></path>
<path d="m5.4 11.4-1.4-1.4-4 4 4 4 1.4-1.4-1.6-1.6h16.2v-2h-16.2z" fill="#ffffff"></path>
</g>
</g>
</svg>
<div>Reverse editor and preview</div>
</div>
<div class="vs"></div>
<div class="item auto-params">
<input id="auto" name="auto" autocomplete="off" type="checkbox">
<div>Auto-update URL options</div>
</div> </div>
</div> </div>
</div> </div>