2022-11-18 19:16:40 +00:00
|
|
|
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;
|
2023-01-27 17:55:25 +00:00
|
|
|
return `<a href="/${u}"><img loading="lazy" src="/${u}/pic" class="pp20"> ${u}</a>`;
|
2022-11-18 19:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
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('<pre>'))
|
|
|
|
input = input.replace(/\n/g, '\n\n')
|
|
|
|
input = input.replace(/\|\|(.*?)\|\|/g, '<spoiler>$1</spoiler>')
|
|
|
|
input = input.replace(/(\n|^)>([^ >][^\n]*)/g, '$1<g>\>$2</g>')
|
|
|
|
|
2022-12-04 15:53:41 +00:00
|
|
|
const emojis = Array.from(input.matchAll(/:([a-z0-9_\-!#@]{1,36}):(?![^`]*`)/gi))
|
2022-11-18 19:16:40 +00:00
|
|
|
if(emojis != null){
|
|
|
|
for(i = 0; i < emojis.length; i++){
|
2022-12-04 15:40:32 +00:00
|
|
|
const old = emojis[i][0];
|
2022-11-18 19:16:40 +00:00
|
|
|
if (old.includes('marseyrandom')) continue
|
2023-01-01 08:43:54 +00:00
|
|
|
let emoji = old.replace(/[:!@#]/g,'').toLowerCase();
|
2022-12-04 15:40:32 +00:00
|
|
|
const mirroredClass = old.indexOf('!') == -1 ? '' : 'mirrored';
|
|
|
|
const emojiClass = old.indexOf('#') == -1 ? 'emoji' : 'emoji-lg';
|
2022-11-18 19:16:40 +00:00
|
|
|
if (emoji.endsWith('pat') && emoji != 'marseyunpettablepat') {
|
|
|
|
emoji = emoji.substr(0, emoji.length - 3);
|
2022-12-04 15:40:32 +00:00
|
|
|
const url = old.indexOf('@') != -1 ? `/@${emoji}/pic` : `/e/${emoji}.webp`;
|
2023-01-27 17:55:25 +00:00
|
|
|
input = input.replace(old, `<span class="pat-preview ${mirroredClass}" data-bs-toggle="tooltip"><img loading="lazy" src="/i/hand.webp"><img loading="lazy" class="${emojiClass}" src="${url}"></span>`);
|
2022-11-18 19:16:40 +00:00
|
|
|
} else {
|
2023-01-27 17:55:25 +00:00
|
|
|
input = input.replace(old, `<img loading="lazy" class="${emojiClass} ${mirroredClass}" src="/e/${emoji}.webp">`);
|
2022-11-18 19:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 17:12:53 +00:00
|
|
|
let options = Array.from(input.matchAll(/\$\$([^\$\n]+)\$\$(?![^`]*`)/gi))
|
2022-11-18 19:16:40 +00:00
|
|
|
if(options != null){
|
|
|
|
for(i = 0; i < options.length; i++){
|
2022-12-04 15:40:32 +00:00
|
|
|
const option = options[i][0];
|
|
|
|
const option2 = option.replace(/\$\$/g, '').replace(/\n/g, '')
|
2022-11-18 19:16:40 +00:00
|
|
|
input = input.replace(option, '');
|
|
|
|
input += `<div class="custom-control"><input type="checkbox" class="custom-control-input" id="option-${i}"><label class="custom-control-label" for="option-${i}">${option2} - <a>0 votes</a></label></div>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 17:12:53 +00:00
|
|
|
options = Array.from(input.matchAll(/&&([^&\n]+)&&(?![^`]*`)/gi))
|
2022-11-18 19:16:40 +00:00
|
|
|
if(options != null){
|
|
|
|
for(i = 0; i < options.length; i++){
|
2022-12-04 15:40:32 +00:00
|
|
|
const option = options[i][0];
|
|
|
|
const option2 = option.replace(/&&/g, '').replace(/\n/g, '')
|
2022-11-18 19:16:40 +00:00
|
|
|
input = input.replace(option, '');
|
|
|
|
input += `<div class="custom-control"><input type="radio" name="choice" class="custom-control-input" id="option-${i}"><label class="custom-control-label" for="option-${i}">${option2} - <a>0 votes</a></label></div>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
input = marked(input)
|
|
|
|
input = input.replace(/\n\n/g, '<br>')
|
|
|
|
|
|
|
|
document.getElementById(t.dataset.preview).innerHTML = input
|
|
|
|
}
|
|
|
|
|
|
|
|
function charLimit(form, text) {
|
|
|
|
|
2022-12-04 15:40:32 +00:00
|
|
|
const input = document.getElementById(form);
|
2022-11-18 19:16:40 +00:00
|
|
|
|
2022-12-04 15:40:32 +00:00
|
|
|
text = document.getElementById(text);
|
2022-11-18 19:16:40 +00:00
|
|
|
|
2022-12-04 15:40:32 +00:00
|
|
|
const length = input.value.length;
|
2022-11-18 19:16:40 +00:00
|
|
|
|
2022-12-04 15:40:32 +00:00
|
|
|
const maxLength = input.getAttribute("maxlength");
|
2022-11-18 19:16:40 +00:00
|
|
|
|
|
|
|
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;
|
2022-12-04 15:40:32 +00:00
|
|
|
}
|