Add option to silence errors
This commit is contained in:
parent
0c0e5966a1
commit
3693b4d947
2 changed files with 30 additions and 18 deletions
30
README.md
30
README.md
|
@ -26,22 +26,28 @@ https://glitchii.github.io/embedbuilder/?data=JTdCJTIyZW1iZWQlMjIlM0ElN0IlMjJ0aX
|
||||||
## Other parameters
|
## Other parameters
|
||||||
Params that end with `=` in the list below need a value, those that don't will always be truthy when set either with or with no value.
|
Params that end with `=` in the list below need a value, those that don't will always be truthy when set either with or with no value.
|
||||||
```
|
```
|
||||||
Parameter Description
|
Parameter Description
|
||||||
--------- -----------
|
--------- -----------
|
||||||
username= Used to set the default name of the bot.
|
username= Used to set the default name of the bot.
|
||||||
avatar= If a valid URL is given, that will be the avatar or icon of the bot.
|
avatar= If a valid URL is given, that will be the avatar or icon of the bot.
|
||||||
verified Displays a verified badge on the bot tag when set to true.
|
verified Displays a verified badge on the bot tag when set to true.
|
||||||
reverse Reverse the preview and editors position.
|
reverse Reverse the preview and editors position.
|
||||||
nouser Display embed or message content with no username or avatar.
|
nouser Display embed or message content with no username or avatar.
|
||||||
embed Display only the embed, no editor.
|
embed Display only the embed, no editor.
|
||||||
guitabs= Specify what gui tabs to display comma seperated.
|
guitabs= Specify what gui tabs to display comma seperated.
|
||||||
Example: `guitabs=author` or `guitabs=image,footer`
|
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
|
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
|
>## 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.
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ var params = new URL(location).searchParams,
|
||||||
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'),
|
||||||
autoUpdateURL = localStorage.getItem('autoUpdateURL'),
|
autoUpdateURL = localStorage.getItem('autoUpdateURL'),
|
||||||
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))));
|
||||||
|
@ -101,11 +102,14 @@ var params = new URL(location).searchParams,
|
||||||
if (dataSpecified)
|
if (dataSpecified)
|
||||||
json = base64ToJson();
|
json = base64ToJson();
|
||||||
|
|
||||||
|
if (allowPlaceholders)
|
||||||
|
allowPlaceholders = params.get('placeholders') === 'errors' ? 1 : 2;
|
||||||
|
|
||||||
addEventListener('load', () => {
|
addEventListener('load', () => {
|
||||||
if (onlyEmbed)
|
if (onlyEmbed)
|
||||||
document.body.classList.add('only-embed');
|
document.body.classList.add('only-embed');
|
||||||
else {
|
else {
|
||||||
document.querySelector('.side1.noDisplay').classList.remove('noDisplay');
|
document.querySelector('.side1.noDisplay')?.classList.remove('noDisplay');
|
||||||
if (useJsonEditor)
|
if (useJsonEditor)
|
||||||
document.body.classList.remove('gui');
|
document.body.classList.remove('gui');
|
||||||
}
|
}
|
||||||
|
@ -179,11 +183,12 @@ addEventListener('load', () => {
|
||||||
}, 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")
|
||||||
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
|
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) {
|
if (activeInput && !allowPlaceholders) {
|
||||||
lastPos = activeInput.selectionStart + 7;
|
lastPos = activeInput.selectionStart + 7;
|
||||||
activeInput.value = `http://${re[2]}`;
|
activeInput.value = `http://${re[2]}`;
|
||||||
update(JSON.parse(str.replace(re[0], `${re[1]}http://${re[2]}"`)));
|
update(JSON.parse(str.replace(re[0], `${re[1]}http://${re[2]}"`)));
|
||||||
|
@ -191,11 +196,12 @@ addEventListener('load', () => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 (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) {
|
if (invalid) {
|
||||||
validationError = true;
|
validationError = true;
|
||||||
return error(err);
|
return error(err, 5000);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}, innerHTML = (element, html) => {
|
}, innerHTML = (element, html) => {
|
||||||
|
@ -904,7 +910,7 @@ addEventListener('load', () => {
|
||||||
prompt('Here\'s the current URL with base64 embed data:', jsonToBase64(json, true));
|
prompt('Here\'s the current URL with base64 embed data:', jsonToBase64(json, true));
|
||||||
else if (e.target.closest('.item.auto')) {
|
else if (e.target.closest('.item.auto')) {
|
||||||
const input = e.target.closest('.item.auto').querySelector('input');
|
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;
|
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');
|
||||||
|
|
Loading…
Add table
Reference in a new issue