Add option to silence errors

This commit is contained in:
Glitchii 2022-03-07 13:18:50 +00:00
parent 0c0e5966a1
commit 3693b4d947
2 changed files with 30 additions and 18 deletions

View file

@ -36,12 +36,18 @@ nouser Display embed or message content with no username or avatar.
embed Display only the embed, no editor.
guitabs= Specify what gui tabs to display comma seperated.
Example: `guitabs=author` or `guitabs=image,footer`
placeholders Silences some warrnings, e.g. warrnings about missing url protocols or incorrect footer timestamps.
With this param, automatic insertion of the 'http' protocol for urls written without a protocol is also disabled.
This param is useful when your bot allows having placeholders in place of a URL eg. `{ server.url }`
placeholders=errors This also disables automatic insertion of 'http' for urls without a protocol.
Except, warnings won't be silenced. The user will still see a warning that a url or timestamp (etc.) is incorrect for 5 seconds.
```
### 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
>## Intergretting into your website
>You are free to use this in your website. Intergretting into your websites allows sending the embed to Discord with a few changes, and using 'formmaters' eg. '{ server_name }' or '{ user_name }' etc. A (not so bad) downside would be that you'd probably have to keep up with fixes and updates.
>You are free to use this in your website. Intergretting into your websites allows sending the embed to Discord with a few changes, and using 'formatters' eg. '{ server.name }' or '{ user.name }' etc. A (not so bad) downside would be that you'd probably have to keep up with fixes and updates.
If all you want is to have an embed builder in your website with no additional features and maybe using your own bot name and avatar, etc., then you should iframe https://glitchii.github.io/embedbuilder into your website with a few of the parameters above if needed instead.

View file

@ -15,6 +15,7 @@ var params = new URL(location).searchParams,
noUser = hasParam('nouser'),
onlyEmbed = hasParam('embed'),
activeFields, colNum = 1, num = 0, validationError,
allowPlaceholders = hasParam('placeholders'),
autoUpdateURL = localStorage.getItem('autoUpdateURL'),
jsonToBase64 = (jsonCode, withURL, redirect) => {
data = btoa(escape((JSON.stringify(typeof jsonCode === 'object' ? jsonCode : json))));
@ -101,11 +102,14 @@ var params = new URL(location).searchParams,
if (dataSpecified)
json = base64ToJson();
if (allowPlaceholders)
allowPlaceholders = params.get('placeholders') === 'errors' ? 1 : 2;
addEventListener('load', () => {
if (onlyEmbed)
document.body.classList.add('only-embed');
else {
document.querySelector('.side1.noDisplay').classList.remove('noDisplay');
document.querySelector('.side1.noDisplay')?.classList.remove('noDisplay');
if (useJsonEditor)
document.body.classList.remove('gui');
}
@ -179,11 +183,12 @@ addEventListener('load', () => {
}, 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")
invalid = true, err = 'Timestamp is invalid';
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 (!/\w+:|\/\/|^\//g.exec(re[2]) && re[2].includes('.')) {
let activeInput = document.querySelector('input[class$="link" i]:focus')
if (activeInput) {
if (activeInput && !allowPlaceholders) {
lastPos = activeInput.selectionStart + 7;
activeInput.value = `http://${re[2]}`;
update(JSON.parse(str.replace(re[0], `${re[1]}http://${re[2]}"`)));
@ -191,11 +196,12 @@ addEventListener('load', () => {
return true;
}
}
if (allowPlaceholders !== 2)
invalid = true, err = (`URL should have a protocol. Did you mean <span class="inline full short">http://${makeShort(re[2], 30, 600).replace(' ', '')}</span>?`);
}
if (invalid) {
validationError = true;
return error(err);
return error(err, 5000);
}
return true;
}, innerHTML = (element, html) => {
@ -904,7 +910,7 @@ addEventListener('load', () => {
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 = !input.checked;
input.checked = e.target === input ? input.checked : !input.checked;
autoUpdateURL = input.checked;
if (input.checked) localStorage.setItem('autoUpdateURL', true);
else localStorage.removeItem('autoUpdateURL');