Add builder.config.js, fix block-quote issue

This commit is contained in:
Glitchii 2022-03-17 18:14:27 +00:00
parent 265a23250c
commit 46dfceb2cc
4 changed files with 46 additions and 19 deletions

View file

@ -29,7 +29,7 @@ Params that end with `=` in the list below need a value, those that don't will a
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= Avatar for the bot. Either URL encode it or make this the last param.
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.
@ -47,6 +47,8 @@ placeholders=errors This also disables automatic insertion of 'http' for url
### 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
### Alternative to URL options:
Alternatively, have JavaScript config file named `builder.config.js`. In this file, define `window.options` to an object containing the params. Note that some param names and cases will be different from the URL ones. An example [builder.config.js](/builder.config.js) file is included in the repo. The config file is loaded before the [main script](/assets/js/script.js) and because it's a JS file, you can do and probably alter anything else.
>## 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 '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. >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.

View file

@ -2,22 +2,24 @@
// Want to use or contribute to this? https://github.com/Glitchii/embedbuilder // Want to use or contribute to this? https://github.com/Glitchii/embedbuilder
// If you found an issue, please report it, make a P.R, or use the discussion page. Thanks // If you found an issue, please report it, make a P.R, or use the discussion page. Thanks
if (!window.options)
options = {};
var params = new URL(location).searchParams, var params = new URL(location).searchParams,
hasParam = param => params.get(param) !== null, hasParam = param => params.get(param) !== null,
dataSpecified = params.get('data'), dataSpecified = options.dataSpecified || params.get('data'),
botName = params.get('username'), username = params.get('username') || options.username,
botIcon = params.get('avatar'), avatar = params.get('avatar') || options.avatar,
guiTabs = params.get('guitabs'), guiTabs = params.get('guitabs') || options.guiTabs,
useJsonEditor = params.get('editor') === 'json', useJsonEditor = params.get('editor') === 'json' || options.useJsonEditor,
botVerified = hasParam('verified'), verified = hasParam('verified') || options.botVerified,
reverseColumns = hasParam('reverse'), reverseColumns = hasParam('reverse') || options.reverseColumns,
noUser = hasParam('nouser'), noUser = hasParam('nouser') || options.noUser,
onlyEmbed = hasParam('embed'), onlyEmbed = hasParam('embed') || options.onlyEmbed,
allowPlaceholders = hasParam('placeholders') || options.allowPlaceholders,
autoUpdateURL = localStorage.getItem('autoUpdateURL') || options.autoUpdateURL,
autoParams = localStorage.getItem('autoParams') || hasParam('autoparams') || options.autoParams,
activeFields, colNum = 1, num = 0, validationError, activeFields, colNum = 1, num = 0, validationError,
allowPlaceholders = hasParam('placeholders'),
autoUpdateURL = localStorage.getItem('autoUpdateURL'),
autoParams = hasParam('autoparams') || localStorage.getItem('autoParams'),
toggleStored = item => { toggleStored = item => {
const found = localStorage.getItem(item); const found = localStorage.getItem(item);
if (!found) return localStorage.setItem(item, true); if (!found) return localStorage.setItem(item, true);
@ -140,9 +142,9 @@ addEventListener('DOMContentLoaded', () => {
if (noUser) if (noUser)
document.body.classList.add('no-user'); document.body.classList.add('no-user');
else { else {
if (botName) document.querySelector('.username').textContent = botName; if (username) document.querySelector('.username').textContent = username;
if (botIcon) document.querySelector('.avatar').src = botIcon; if (avatar) document.querySelector('.avatar').src = avatar;
if (botVerified) document.querySelector('.msgEmbed > .contents').classList.add('verified'); if (verified) document.querySelector('.msgEmbed > .contents').classList.add('verified');
} }
if (reverseColumns || localStorage.getItem('reverseColumns')) if (reverseColumns || localStorage.getItem('reverseColumns'))
reverse(); reverse();
@ -245,9 +247,10 @@ addEventListener('DOMContentLoaded', () => {
.replace(/__(.+?)__/g, '<u>$1</u>') .replace(/__(.+?)__/g, '<u>$1</u>')
.replace(/\*(.+?)\*/g, '<em>$1</em>') .replace(/\*(.+?)\*/g, '<em>$1</em>')
.replace(/_(.+?)_/g, '<em>$1</em>') .replace(/_(.+?)_/g, '<em>$1</em>')
// Replace >>> and > with block quotes. &#62; is HTML code for > // Replace >>> and > with block-quotes. &#62; is HTML code for >
.replace(/^(?: *&#62;&#62;&#62; +([\s\S]*))|^(?: *&#62;(?!&#62;&#62;) +([^\n]*)(\n *&#62;(?!&#62;&#62;) +([^\n]*))*\n?)/mg, (m, b, c) => .replace(/^(?: *&#62;&#62;&#62; ([\s\S]*))|(?:^ *&#62;(?!&#62;&#62;) +.+\n)+(?:^ *&#62;(?!&#62;&#62;) .+\n?)+|^(?: *&#62;(?!&#62;&#62;) ([^\n]*))(\n?)/mg, (all, match1, match2, newLine) => {
`<div class="blockquote"><div class="blockquoteDivider"></div><blockquote>${b || c}</blockquote></div>`) return `<div class="blockquote"><div class="blockquoteDivider"></div><blockquote>${match1 || match2 || newLine ? match1 || match2 : all.replace(/^ *&#62; /gm, '')}</blockquote></div>`;
})
/** Mentions */ /** Mentions */
.replace(/&#60;#\d+&#62;/g, () => `<span class="mention channel interactive">channel</span>`) .replace(/&#60;#\d+&#62;/g, () => `<span class="mention channel interactive">channel</span>`)

21
builder.config.js Normal file
View file

@ -0,0 +1,21 @@
// URL options can override the options below.
// Options set through the menu can override both.
options = {
username: "Discord Bot",
avatar: `https://cdn.discordapp.com/embed/avatars/${Math.floor(Math.random() * 6)}.png`,
verified: false,
noUser: false,
hasParam: false,
dataSpecified: false,
guiTabs: "author,description",
useJsonEditor: false,
reverseColumns: false,
onlyEmbed: false,
allowPlaceholders: false,
autoUpdateURL: false,
autoParams: false,
}
onload = () => {
// console.log('Salut 👋');
}

View file

@ -33,6 +33,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/addon/lint/lint.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/addon/lint/lint.min.js"></script>
<script src="./assets/libs/color-picker/color-picker.min.js"></script> <script src="./assets/libs/color-picker/color-picker.min.js"></script>
<link rel="stylesheet" href="./assets/libs/color-picker/color-picker.min.css"> <link rel="stylesheet" href="./assets/libs/color-picker/color-picker.min.css">
<script src="/builder.config.js"></script>
<script src="./assets/js/components.js"></script> <script src="./assets/js/components.js"></script>
<script src="./assets/js/script.js"></script> <script src="./assets/js/script.js"></script>
</head> </head>