MarseyWorld/files/assets/js/marked.js

128 lines
50 KiB
JavaScript
Raw Normal View History

2022-07-16 21:00:02 +00:00
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).marked=t()}(this,(function(){"use strict";function e(e,t){for(var u=0;u<t.length;u++){var n=t[u];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var u=0,n=new Array(t);u<t;u++)n[u]=e[u];return n}function u(e,u){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,u){if(e){if("string"==typeof e)return t(e,u);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,u):void 0}}(e))||u&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var n={exports:{}};function r(){return{baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}n.exports={defaults:{baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1},getDefaults:r,changeDefaults:function(e){n.exports.defaults=e}};var i=/[&<>"']/,s=/[&<>"']/g,l=/[<>"']|&(?!#?\w+;)/,a=/[<>"']|&(?!#?\w+;)/g,o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},D=function(e){return o[e]};var c=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function h(e){return e.replace(c,(function(e,t){return"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""}))}var p=/(^|[^\[])\^/g;var f=/[^\w:]/g,g=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;var F={},A=/^[^:]+:\/*[^/]*$/,d=/^([^:]+:)[\s\S]*$/,C=/^([^:]+:\/*[^/]*)[\s\S]*$/;function k(e,t){F[" "+e]||(A.test(e)?F[" "+e]=e+"/":F[" "+e]=E(e,"/",!0));var u=-1===(e=F[" "+e]).indexOf(":");return"//"===t.substring(0,2)?u?t:e.replace(d,"$1")+t:"/"===t.charAt(0)?u?t:e.replace(C,"$1")+t:e+t}function E(e,t,u){var n=e.length;if(0===n)return"";for(var r=0;r<n;){var i=e.charAt(n-r-1);if(i!==t||u){if(i===t||!u)break;r++}else r++}return e.substr(0,n-r)}var x=function(e,t){if(t){if(i.test(e))return e.replace(s,D)}else if(l.test(e))return e.replace(a,D);return e},m=h,b=function(e,t){e=e.source||e,t=t||"";var u={replace:function(t,n){return n=(n=n.source||n).replace(p,"$1"),e=e.replace(t,n),u},getRegex:function(){return new RegExp(e,t)}};return u},B=function(e,t,u){if(e){var n;try{n=decodeURIComponent(h(u)).replace(f,"").toLowerCase()}catch(e){return null}if(0===n.indexOf("javascript:")||0===n.indexOf("vbscript:")||0===n.indexOf("data:"))return null}t&&!g.test(u)&&(u=k(t,u));try{u=encodeURI(u).replace(/%25/g,"%")}catch(e){return null}return u},w={exec:function(){}},v=function(e){for(var t,u,n=1;n<arguments.length;n++)for(u in t=arguments[n])Object.prototype.hasOwnProperty.call(t,u)&&(e[u]=t[u]);return e},y=function(e,t){var u=e.replace(/\|/g,(function(e,t,u){for(var n=!1,r=t;--r>=0&&"\\"===u[r];)n=!n;return n?"|":" |"})).split(/ \|/),n=0;if(u[0].trim()||u.shift(),u[u.length-1].trim()||u.pop(),u.length>t)u.splice(t);else for(;u.length<t;)u.push("");for(;n<u.length;n++)u[n]=u[n].trim().replace(/\\\|/g,"|");return u},_=E,z=function(e,t){if(-1===e.indexOf(t[1]))return-1;for(var u=e.length,n=0,r=0;r<u;r++)if("\\"===e[r])r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&--n<0)return r;return-1},$=function(e){e&&e.sanitize
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 `<a href="/${u}"><img src="/${u}/pic" class="pp20"> ${u}</a>`;
}
}
]
});
const reDisableBeforeUnload = /^\/submit|^\/h\/[a-zA-Z0-9_\-]{3,20}\/submit/;
function markdown(t) {
let input = t.value;
2022-07-16 21:00:02 +00:00
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>')
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, `<span class="pat-preview ${mirroredClass}" data-bs-toggle="tooltip"><img src="/i/hand.webp"><img class="${emojiClass}" src="${url}"></span>`);
} else {
input = input.replace(old, `<img class="${emojiClass} ${mirroredClass}" src="/e/${emoji}.webp">`);
}
}
}
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 += `<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>`;
}
}
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 += `<div class="custom-control"><input type="radio" name="choice" class="custom-control-input" id="choice-${i}"><label class="custom-control-label" for="choice-${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
2022-07-16 21:00:02 +00:00
}
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;
}