diff --git a/README.md b/README.md
index 79375fa..0fba66d 100644
--- a/README.md
+++ b/README.md
@@ -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.
```
+Case matters, all parameters should be lowercase.
### 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
diff --git a/assets/css/index.css b/assets/css/index.css
index 11ea123..b631043 100644
--- a/assets/css/index.css
+++ b/assets/css/index.css
@@ -287,17 +287,17 @@ img[alt] {
}
.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");
- width: 1.05rem;
- height: 1.3rem;
- -o-object-fit: contain;
- object-fit: contain;
- position: relative;
- left: .125rem;
- top: 3px;
- display: inline-block;
- margin-right: .125rem;
- color: hsl(236, calc(83.3%),92.9%);
+ 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;
+ height: 1.3rem;
+ -o-object-fit: contain;
+ object-fit: contain;
+ position: relative;
+ left: .125rem;
+ top: 3px;
+ display: inline-block;
+ margin-right: .125rem;
+ color: hsl(236, calc(83.3%), 92.9%);
}
.mention.interactive:hover {
@@ -1009,7 +1009,7 @@ u {
color: #8c4949;
display: none;
width: 100%;
- z-index: 5;
+ z-index: 6;
}
.col.cm-string.cm-property::before {
@@ -1845,14 +1845,37 @@ body {
margin-bottom: 5px;
font-size: 13px;
transition: .5s ease;
+ display: flex;
+ gap: 10px;
+ text-align: center;
+ align-content: center;
}
.top-btn.menu>.box .item:hover {
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);
+} */
+
+.top-btn.menu>.box .item>* {
+ align-self: flex-end;
+ margin: 0;
+}
+
+.top-btn.menu>.box .item>input {
+ pointer-events: none;
}
.top-btn.menu.active {
diff --git a/assets/js/script.js b/assets/js/script.js
index 360b7d5..bd340d8 100644
--- a/assets/js/script.js
+++ b/assets/js/script.js
@@ -11,12 +11,20 @@ var params = new URL(location).searchParams,
guiTabs = params.get('guitabs'),
useJsonEditor = params.get('editor') === 'json',
botVerified = hasParam('verified'),
- reverseColmns = hasParam('reverse'),
+ reverseColumns = hasParam('reverse'),
noUser = hasParam('nouser'),
onlyEmbed = hasParam('embed'),
activeFields, colNum = 1, num = 0, validationError,
allowPlaceholders = hasParam('placeholders'),
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) => {
data = btoa(escape((JSON.stringify(typeof jsonCode === 'object' ? jsonCode : json))));
if (withURL) {
@@ -40,6 +48,21 @@ var params = new URL(location).searchParams,
hex = hex.replace('#', '').match(/.{1,2}/g)
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"],
jsonKeys = ["embed", "content", ...mainKeys],
json = {
@@ -105,7 +128,7 @@ if (dataSpecified)
if (allowPlaceholders)
allowPlaceholders = params.get('placeholders') === 'errors' ? 1 : 2;
-addEventListener('load', () => {
+addEventListener('DOMContentLoaded', () => {
if (onlyEmbed)
document.body.classList.add('only-embed');
else {
@@ -120,14 +143,12 @@ addEventListener('load', () => {
if (botIcon) document.querySelector('.avatar').src = botIcon;
if (botVerified) document.querySelector('.msgEmbed > .contents').classList.add('verified');
}
- if (reverseColmns) {
- const side1 = document.querySelector('.side1');
- side1.parentElement.insertBefore(side1.nextElementSibling, side1);
- document.body.classList.add('reversed');
- };
+ if (reverseColumns || localStorage.getItem('reverseColumns'))
+ reverse();
if (autoUpdateURL)
document.querySelector('.top-btn.menu .item.auto input').checked = true;
-
+ if (autoParams)
+ document.querySelector('.auto-params > input').checked = true;
document.querySelectorAll('.clickable > img')
.forEach(e => e.parentElement.addEventListener('mouseup', el => window.open(el.target.src)));
@@ -182,10 +203,11 @@ addEventListener('load', () => {
return false;
}, allGood = e => {
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) invalid = true, err = 'Timestamp is invalid';
- else if (re) { // If a URL is found without a protocol
+ if (!allowPlaceholders)
+ 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('.')) {
let activeInput = document.querySelector('input[class$="link" i]:focus')
if (activeInput && !allowPlaceholders) {
@@ -538,7 +560,7 @@ addEventListener('load', () => {
} else if (txt && !smallerScreen.matches)
txt.focus();
if (elm.classList.contains('fields')) {
- if (reverseColmns && smallerScreen.matches)
+ if (reverseColumns && smallerScreen.matches)
// return elm.nextElementSibling.scrollIntoView({ behavior: 'smooth', block: "end" });
return elm.parentNode.scrollTop = elm.offsetTop;
elm.scrollIntoView({ behavior: "smooth", block: "center" });
@@ -552,7 +574,7 @@ addEventListener('load', () => {
requiresView = matchMedia(`${smallerScreen.media}, (max-height: 845px)`);
document.querySelectorAll('.gui>.item:not(.fields)').forEach(e => e.addEventListener('click', () => {
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'))
// e.nextElementSibling.scrollIntoView({ behavior: 'smooth', block: "end" });
e.parentNode.scrollTop = e.offsetTop;
@@ -779,12 +801,8 @@ addEventListener('load', () => {
} else document.body.classList.add('emptyEmbed');
if (!embedCont.innerText) document.body.classList.add('emptyEmbed');
json = data;
- if (autoUpdateURL) {
- // Update data param in url.
- const url = new URL(location.href);
- url.searchParams.set('data', jsonToBase64(json));
- history.replaceState(null, null, url.href);
- }
+ if (autoUpdateURL)
+ urlOptions({ set: ['data', jsonToBase64(json)] })
} catch (e) {
console.log(e);
error(e);
@@ -907,16 +925,27 @@ addEventListener('load', () => {
document.querySelector('.top-btn.menu').addEventListener('click', e => {
if (e.target.closest('.item.datalink'))
- 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');
- input.checked = e.target === input ? input.checked : !input.checked;
+ return prompt('Here\'s the current URL with base64 embed data:', jsonToBase64(json, true));
+
+ const input = e.target.closest('.item')?.querySelector('input');
+ if (input) input.checked = !input.checked;
+
+ if (e.target.closest('.item.auto')) {
autoUpdateURL = input.checked;
if (input.checked) localStorage.setItem('autoUpdateURL', true);
else localStorage.removeItem('autoUpdateURL');
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')
})
diff --git a/index.html b/index.html
index c68ff6e..7c64d90 100644
--- a/index.html
+++ b/index.html
@@ -103,11 +103,27 @@