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-07-22 18:48:47 +00:00
|
|
|
return `<a href="/${u}"><img loading="lazy" src="/${u}/pic" class="pp20"> ${u}</a>`;
|
2022-11-18 19:16:40 +00:00
|
|
|
}
|
2023-03-18 07:00:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'group_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: 'group_mention',
|
|
|
|
raw: match[0],
|
|
|
|
text: match[0].trim().slice(1),
|
|
|
|
tokens: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
renderer(token) {
|
|
|
|
const g = token.raw;
|
2023-03-22 16:24:34 +00:00
|
|
|
return `<a href="/${g}">${g}</a>`;
|
2023-03-18 07:00:46 +00:00
|
|
|
}
|
|
|
|
},
|
2022-11-18 19:16:40 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
const reDisableBeforeUnload = /^\/submit|^\/h\/[a-zA-Z0-9_\-]{3,20}\/submit/;
|
|
|
|
|
2023-03-07 01:52:02 +00:00
|
|
|
const image_regex_extensions = document.getElementById('IMAGE_FORMATS').value.replaceAll(',', '|')
|
|
|
|
const regex_pattern = String.raw`(^|\s)(https:\/\/[\w\-.#&/=\?@%;+,:]{5,250}(\.|\?format=)(` + image_regex_extensions + String.raw`)((\?|&)[\w\-.#&/=\?@%;+,:]*)?)($|\s)`
|
|
|
|
const compiled_regex = new RegExp(regex_pattern, "g");
|
|
|
|
|
2023-04-29 20:50:47 +00:00
|
|
|
const approved_embed_hosts = document.getElementById('approved_embed_hosts').value.replace("{'", "").replace("'}", "").split("', '")
|
|
|
|
function replace_image(match, prefix, url) {
|
|
|
|
if (approved_embed_hosts.some(x => url.startsWith(`https://${x}/`)))
|
|
|
|
return `${prefix}![](${url})`
|
|
|
|
|
|
|
|
return match
|
|
|
|
}
|
2023-07-03 00:26:20 +00:00
|
|
|
|
2023-08-04 10:13:36 +00:00
|
|
|
const MODIFIERS = {
|
|
|
|
PAT: 1,
|
|
|
|
TALKING: 2,
|
|
|
|
LARGE: 3,
|
|
|
|
REVERSED: 4,
|
|
|
|
USER: 5
|
|
|
|
};
|
|
|
|
|
2022-11-18 19:16:40 +00:00
|
|
|
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>')
|
2023-03-19 13:54:18 +00:00
|
|
|
input = input.replace(/((\s|^)[0-9]+)\. /g, '$1\\. ')
|
2022-11-18 19:16:40 +00:00
|
|
|
|
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];
|
2023-08-04 10:13:36 +00:00
|
|
|
if (old.includes('marseyrandom')) continue;
|
|
|
|
if (old.includes('marseyrandom')) continue
|
|
|
|
let emoji = old.replace(/[:]/g,'').toLowerCase();
|
|
|
|
|
|
|
|
const modifiers = new Set();
|
|
|
|
const isTalkingFirst = !(emoji.endsWith('pat') && emoji.slice(0, -3).endsWith('talking'));
|
|
|
|
if(emoji.endsWith('talking') || (emoji.endsWith('pat') && emoji.slice(0, -3).endsWith('talking'))) {
|
|
|
|
modifiers.add(MODIFIERS.TALKING);
|
|
|
|
emoji = emoji.endsWith('pat') ? [emoji.slice(0, -10), emoji.slice(-3)].join('') : emoji.slice(0, -7);
|
|
|
|
}
|
|
|
|
if(emoji.endsWith('pat')) {
|
|
|
|
modifiers.add(MODIFIERS.PAT);
|
|
|
|
emoji = emoji.slice(0, -3);
|
|
|
|
}
|
|
|
|
let length = emoji.length
|
|
|
|
emoji = emoji.startsWith('@', '') ? emoji.slice(1): emoji;
|
|
|
|
if(length !== emoji.length) {
|
|
|
|
modifiers.add(MODIFIERS.USER);
|
|
|
|
length = emoji.length
|
|
|
|
}
|
|
|
|
emoji = emoji.replaceAll('!', '');
|
|
|
|
if(length !== emoji.length) {
|
|
|
|
modifiers.add(MODIFIERS.REVERSED);
|
|
|
|
length = emoji.length;
|
|
|
|
}
|
|
|
|
emoji = emoji.replaceAll('#', '');
|
|
|
|
if(length !== emoji.length) {
|
|
|
|
modifiers.add(MODIFIERS.LARGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(emoji === 'marseyunpettable') {
|
|
|
|
modifiers.delete(MODIFIERS.PAT);
|
|
|
|
if(!isTalkingFirst) {
|
|
|
|
modifiers.delete(MODIFIERS.TALKING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mirroredClass = modifiers.has(MODIFIERS.REVERSED) ? 'mirrored' : '';
|
|
|
|
const emojiClass = modifiers.has(MODIFIERS.LARGE) ? 'emoji-lg' : 'emoji';
|
|
|
|
|
|
|
|
if (modifiers.has(MODIFIERS.PAT) || modifiers.has(MODIFIERS.TALKING)) {
|
|
|
|
const talkingHtml = modifiers.has(MODIFIERS.TALKING) ? `<img loading="lazy" src="${SITE_FULL_IMAGES}/i/talking.webp">` : '';
|
|
|
|
const patHtml = modifiers.has(MODIFIERS.PAT) ? `<img loading="lazy" src="${SITE_FULL_IMAGES}/i/hand.webp">` : '';
|
|
|
|
const url = modifiers.has(MODIFIERS.USER) ? `/@${emoji}/pic` : `${SITE_FULL_IMAGES}/e/${emoji}.webp`;
|
|
|
|
const modifierHtml = isTalkingFirst ? `${talkingHtml}${patHtml}` : `${patHtml}${talkingHtml}`;
|
|
|
|
input = input.replace(old, `<span class="pat-preview ${mirroredClass}" data-bs-toggle="tooltip">${modifierHtml}<img loading="lazy" class="${emojiClass}" src="${url}"></span>`);
|
2022-11-18 19:16:40 +00:00
|
|
|
} else {
|
2023-07-22 16:24:16 +00:00
|
|
|
input = input.replace(old, `<img loading="lazy" class="${emojiClass} ${mirroredClass}" src="${SITE_FULL_IMAGES}/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, '')
|
2023-03-01 21:02:24 +00:00
|
|
|
input = input.replace(option, `<div class="custom-control mb-3"><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-11-18 19:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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, '')
|
2023-03-01 21:02:24 +00:00
|
|
|
input = input.replace(option, `<div class="custom-control mb-3"><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>`);
|
2022-11-18 19:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-29 20:50:47 +00:00
|
|
|
input = input.replace(compiled_regex, replace_image)
|
2023-03-07 01:52:02 +00:00
|
|
|
|
2022-11-18 19:16:40 +00:00
|
|
|
input = marked(input)
|
|
|
|
|
2023-02-03 03:15:30 +00:00
|
|
|
const preview = document.getElementById(t.dataset.preview)
|
2023-02-03 03:04:23 +00:00
|
|
|
|
2023-02-03 03:15:30 +00:00
|
|
|
preview.innerHTML = input
|
|
|
|
|
|
|
|
const expandable = preview.querySelectorAll('img[alt]');
|
2023-02-03 03:04:23 +00:00
|
|
|
for (const element of expandable) {
|
|
|
|
element.onclick = () => {expandImage()};
|
|
|
|
}
|
2022-11-18 19:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|