diff --git a/README.md b/README.md index 0fba66d..a6c3b44 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Params that end with `=` in the list below need a value, those that don't will a Parameter Description --------- ----------- 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. reverse Reverse the preview and editors position. 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: 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 >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. diff --git a/assets/js/script.js b/assets/js/script.js index 29a1ab7..a3e6dd0 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -2,22 +2,24 @@ // 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 (!window.options) + options = {}; var params = new URL(location).searchParams, hasParam = param => params.get(param) !== null, - dataSpecified = params.get('data'), - botName = params.get('username'), - botIcon = params.get('avatar'), - guiTabs = params.get('guitabs'), - useJsonEditor = params.get('editor') === 'json', - botVerified = hasParam('verified'), - reverseColumns = hasParam('reverse'), - noUser = hasParam('nouser'), - onlyEmbed = hasParam('embed'), + dataSpecified = options.dataSpecified || params.get('data'), + username = params.get('username') || options.username, + avatar = params.get('avatar') || options.avatar, + guiTabs = params.get('guitabs') || options.guiTabs, + useJsonEditor = params.get('editor') === 'json' || options.useJsonEditor, + verified = hasParam('verified') || options.botVerified, + reverseColumns = hasParam('reverse') || options.reverseColumns, + noUser = hasParam('nouser') || options.noUser, + 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, - 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); @@ -140,9 +142,9 @@ addEventListener('DOMContentLoaded', () => { if (noUser) document.body.classList.add('no-user'); else { - if (botName) document.querySelector('.username').textContent = botName; - if (botIcon) document.querySelector('.avatar').src = botIcon; - if (botVerified) document.querySelector('.msgEmbed > .contents').classList.add('verified'); + if (username) document.querySelector('.username').textContent = username; + if (avatar) document.querySelector('.avatar').src = avatar; + if (verified) document.querySelector('.msgEmbed > .contents').classList.add('verified'); } if (reverseColumns || localStorage.getItem('reverseColumns')) reverse(); @@ -245,9 +247,10 @@ addEventListener('DOMContentLoaded', () => { .replace(/__(.+?)__/g, '$1') .replace(/\*(.+?)\*/g, '$1') .replace(/_(.+?)_/g, '$1') - // Replace >>> and > with block quotes. > is HTML code for > - .replace(/^(?: *>>> +([\s\S]*))|^(?: *>(?!>>) +([^\n]*)(\n *>(?!>>) +([^\n]*))*\n?)/mg, (m, b, c) => - `
${b || c}
`) + // Replace >>> and > with block-quotes. > is HTML code for > + .replace(/^(?: *>>> ([\s\S]*))|(?:^ *>(?!>>) +.+\n)+(?:^ *>(?!>>) .+\n?)+|^(?: *>(?!>>) ([^\n]*))(\n?)/mg, (all, match1, match2, newLine) => { + return `
${match1 || match2 || newLine ? match1 || match2 : all.replace(/^ *> /gm, '')}
`; + }) /** Mentions */ .replace(/<#\d+>/g, () => `channel`) diff --git a/builder.config.js b/builder.config.js new file mode 100644 index 0000000..a6f9993 --- /dev/null +++ b/builder.config.js @@ -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 👋'); +} \ No newline at end of file diff --git a/index.html b/index.html index aac3376..b74a240 100644 --- a/index.html +++ b/index.html @@ -33,6 +33,7 @@ +