Advertisement
jcunews

BBCode2HTML Bookmarklet

Jul 16th, 2021 (edited)
1,378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript: /*BBCode2HTML v1.0.1*/
  2. ((b, pt, e) => {
  3.   pt = t => {
  4.     var u, h, s = t.data.replace(/\[(\/?)([a-z]+|\*)(?:=([^\]]+))?\]/gi, (s,a,b,c) => {
  5.       switch (b.toLowerCase()) {
  6.         case "b":
  7.         case "br":
  8.         case "center":
  9.         case "code":
  10.         case "i":
  11.         case "quote":
  12.         case "s":
  13.         case "u":
  14.           h = true;
  15.           return `<${a}${b}>`;
  16.         case "color":
  17.         case "size":
  18.           h = true;
  19.           if (a) {
  20.             return '</font>'
  21.           } else return `<font ${b}="${c}">`;
  22.         case "img":
  23.           h = true;
  24.           if (a) {
  25.             return '" />'
  26.           } else return '<img src="';
  27.         case "list":
  28.           h = true;
  29.           if (a) {
  30.             u = false;
  31.             return '</ul>'
  32.           } else {
  33.             u = true;
  34.             return '<ul>'
  35.           }
  36.         case "*":
  37.           if (u && !a && !c) return h = '<li>';
  38.           return s;
  39.         case "url":
  40.           h = true;
  41.           if (a) {
  42.             return '</a>'
  43.           } else return `<a href="${c}">`;
  44.         default: return s;
  45.       }
  46.     });
  47.     if (h) {
  48.       e.innerHTML = s;
  49.       s = t.nextSibling; u = t.parentNode;
  50.       u.removeChild(t);
  51.       while (e.firstChild) u.insertBefore(e.firstChild, s)
  52.     }
  53.   };
  54.   e = document.createElement("DIV");
  55.   (function pe(e, i, n) {
  56.     for (i = e.childNodes.length - 1, n = e.childNodes[i]; i >= 0; i--) {
  57.       switch (n.nodeType) {
  58.         case Node.ELEMENT_NODE: pe(n); break;
  59.         case Node.TEXT_NODE: pt(n)
  60.       }
  61.     }
  62.   })(b)
  63. })(document.body)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement