// ==UserScript==
// @name Mangadex PreviewPost
// @description Preview new forum/comment posts and edits on MangaDex.
// @namespace https://github.com/Brandon-Beck
// @version 0.0.4
// @grant unsafeWindow
// @grant GM.getValue
// @grant GM.setValue
// @grant GM_getValue
// @grant GM_setValue
// @require https://gitcdn.xyz/repo/Brandon-Beck/Mangadex-Userscripts/a480c30b64fba63fad4e161cdae01e093bce1e4c/common.js
// @require https://gitcdn.xyz/repo/Brandon-Beck/Mangadex-Userscripts/21ec54406809722c425c39a0f5b6aad59fb3d88d/uncommon.js
// @require https://gitcdn.xyz/repo/Brandon-Beck/Mangadex-Userscripts/0d46bb0b3fa43f11ea904945e7baef7c6e2a6a5b/settings-ui.js
// @match https://mangadex.org/*
// @author Brandon Beck
// @icon https://mangadex.org/images/misc/default_brand.png
// @license MIT
// @downloadURL none
// ==/UserScript==
//
//
class BBCode {
/* Taken from https://github.com/DasRed/js-bbcode-parser
* Distributed under MIT license
*/
/**
* @param {Object} codes
* @param {Object} [options]
*/
constructor(codes, options) {
this.codes = [];
options = options || {};
// copy options
for (let optionName in options) {
if (optionName === 'events') {
continue;
}
this[optionName] = options[optionName];
}
this.setCodes(codes);
}
/**
* parse
*
* @param {String} text
* @returns {String}
*/
parse(text) {
return this.codes.reduce((text, code) => text.replace(code.regexp, code.replacement), text);
}
/**
* add bb codes
*
* @param {String} regex
* @param {String} replacement
* @returns {BBCode}
*/
add(regex, replacement) {
this.codes.push({
regexp: new RegExp(regex, 'igm'),
replacement: replacement
});
return this;
}
/**
* set bb codes
*
* @param {Object} codes
* @returns {BBCode}
*/
setCodes(codes) {
this.codes = Object.keys(codes).map(function (regex) {
const replacement = codes[regex];
return {
regexp: new RegExp(regex, 'igm'),
replacement: replacement
};
}, this);
return this;
}
}
// create the Default
const bbCodeParser = new BBCode({
'\n': '
',
'\\[b\\](.*?)\\[/b\\]': '$1',
'\\[i\\](.*?)\\[/i\\]': '$1',
'\\[u\\](.*?)\\[/u\\]': '$1',
'\\[s\\](.*?)\\[/s\\]': '$1',
'\\[h1\\](.*?)\\[/h1\\]': '
$1
', '\\[center\\](.*?)\\[/center\\]': '$1
', '\\[left\\](.*?)\\[/left\\]': '$1
', '\\[right\\](.*?)\\[/right\\]': '$1
', '\\[img\\](.*?)\\[/img\\]': '