marked.use({ extensions: [ { name: 'mention', level: 'inline', start: function(src){ const match = src.match(/@[a-zA-Z0-9_\-]+/); return match != null ? match.index : -1; }, tokenizer: function(src) { const rule = /^@[a-zA-Z0-9_\-]+/; const match = rule.exec(src); if(match){ return { type: 'mention', raw: match[0], text: match[0].trim().slice(1), tokens: [] }; } }, renderer(token) { const u = token.raw; return ` ${u}`; } } ] }); const reDisableBeforeUnload = /^\/submit|^\/h\/[a-zA-Z0-9_\-]{3,20}\/submit/; function markdown(t) { let input = t.value; if (!reDisableBeforeUnload.test(location.pathname)) { if (!window.onbeforeunload) { window.onbeforeunload = function (e) { e = e || window.event; if (e) { e.returnValue = 'Any string'; } return 'Any string'; }; } else if (!input) { window.onbeforeunload = null } } if (!input.includes('```') && !input.includes('
')) input = input.replace(/\n/g, '\n\n') input = input.replace(/\|\|(.*?)\|\|/g, '$1 ') input = input.replace(/(\n|^)>([^ >][^\n]*)/g, '$1\>$2 ') var emojis = Array.from(input.matchAll(/:([a-z0-9_\-!#@]{1,36}):(?!\/)/gi)) if(emojis != null){ for(i = 0; i < emojis.length; i++){ var old = emojis[i][0]; if (old.includes('marseyrandom')) continue var emoji = old.replace(/[:!@#]/g,'').toLowerCase(); var mirroredClass = old.indexOf('!') == -1 ? '' : 'mirrored'; var emojiClass = old.indexOf('#') == -1 ? 'emoji' : 'emoji-lg'; if (emoji.endsWith('pat') && emoji != 'marseyunpettablepat') { emoji = emoji.substr(0, emoji.length - 3); var url = old.indexOf('@') != -1 ? `/@${emoji}/pic` : `/e/${emoji}.webp`; input = input.replace(old, ``); } else { input = input.replace(old, ``); } } } let options = Array.from(input.matchAll(/\s*\$\$([^\$\n]+)\$\$\s*/gi)) if(options != null){ for(i = 0; i < options.length; i++){ var option = options[i][0]; var option2 = option.replace(/\$\$/g, '').replace(/\n/g, '') input = input.replace(option, ''); input += ``; } } options = Array.from(input.matchAll(/\s*&&([^\$\n]+)&&\s*/gi)) if(options != null){ for(i = 0; i < options.length; i++){ var option = options[i][0]; var option2 = option.replace(/&&/g, '').replace(/\n/g, '') input = input.replace(option, ''); input += ``; } } input = marked(input) input = input.replace(/\n\n/g, '
') document.getElementById(t.dataset.preview).innerHTML = input } function charLimit(form, text) { var input = document.getElementById(form); var text = document.getElementById(text); var length = input.value.length; var maxLength = input.getAttribute("maxlength"); if (length >= maxLength) { text.style.color = "#E53E3E"; } else if (length >= maxLength * .72){ text.style.color = "#FFC107"; } else { text.style.color = "#A0AEC0"; } text.innerText = length + ' / ' + maxLength; } function remove_dialog() { window.onbeforeunload = null; }