BBOM

A Fairly Extensible and Lightweight HTML to BBCode Parser Module

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://greasyfork.org/scripts/414992-bbom/code/BBOM.js?version=865439

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.BBOMParser=e():t.BBOMParser=e()}(window,(function(){return(()=>{"use strict";var t={635:(t,e,n)=>{function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),t}n.d(e,{default:()=>s});var c=function(){function t(e,n,r,o){var a=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],u=arguments.length>5&&void 0!==arguments[5]&&arguments[5];i(this,t),this.bbNode=e,this.bbName=n,this.bbAttr=r,this.bbChildren=o,this.bbClose=a,this.bbNewline=u}return u(t,[{key:"bbChildren",set:function(t){this._bbChildren=t},get:function(){var t=this.ignoreSymbol;switch(o(this._bbChildren)){case"string":return t&&this.bbNode[t]?[]:this._bbChildren;case"object":return this._bbChildren.filter((function(e){return!t||!e.bbNode[t]}));default:return[]}}},{key:"bbCode",get:function(){var t="",e="",n=this.bbName,r=this.bbAttr,i=this.bbChildren,a=this.bbClose,u=this.bbNewline;switch("string"==typeof n&&(t=void 0===r?"[".concat(n,"]"):"[".concat(n,"=").concat(r,"]"),!a||i instanceof Array&&!(i.length>0)||(e="[/".concat(n,"]"))),o(i)){case"string":return t+i+e+(u?"\n":"");case"object":return t+i.map((function(t){return t.bbCode})).join("")+e+(u?"\n":"");default:return t+(u?"\n":"")}}}]),t}();const s=function(){function t(e,n){i(this,t),this.dict=e,this.config=n,this.ignoreSymbol=Symbol("ignore"),c.prototype.ignoreSymbol=this.ignoreSymbol}return u(t,[{key:"parseFromNode",value:function(t){var e=t.nodeType;switch(e){case 1:case 3:var n,i=function(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}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 a,u=!0,c=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return u=t.done,t},e:function(t){c=!0,a=t},f:function(){try{u||null==n.return||n.return()}finally{if(c)throw a}}}}(this.dict);try{for(i.s();!(n=i.n()).done;){var a=n.value,u=!1,s=a.selector;switch(o(s)){case"string":1===e&&(u=t.matches(s));break;case"function":u=s(t,this)}if(u){var f=a.bbName,l=a.bbAttr,b=a.bbChildren,h=void 0===b?this.defaultChildren(t):b,d=a.bbClose,y=a.bbNewline;return"function"==typeof f&&(f=f(t,this)),"function"==typeof l&&(l=l(t,this)),"function"==typeof h&&(h=h(t,this)),"function"==typeof d&&(d=d(t,this)),"function"==typeof y&&(y=y(t.this)),new c(t,f,l,h,d,y)}}}catch(t){i.e(t)}finally{i.f()}return new c(t,void 0,void 0,this.defaultChildren(t));default:return new c(t,void 0,void 0,"")}}},{key:"defaultChildren",value:function(t){switch(t.nodeType){case 1:for(var e=[],n=t.childNodes,r=n.length,o=0;o<r;++o)e.push(this.parseFromNode(n[o]));return e;case 3:return t.textContent.replace(/\r\n?/g,"\n").replace(/[ \t]+\n/g,"\n").replace(/\n[ \t]+/g,"\n").replace(/\t/g," ").replace(/\n/g," ").replace(/ +/g," ");default:return[]}}},{key:"ignore",value:function(t){return t&&(t[this.ignoreSymbol]=!0),t}},{key:"parseFromString",value:function(t){return this.parseFromNode((new DOMParser).parseFromString("<bbom-wrapper>".concat(t,"</bbom-wrapper>"),"text/xml").childNodes[0])}}]),t}()}},e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={exports:{}};return t[r](o,o.exports,n),o.exports}return n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n(635)})().default}));