Untitled

 avatar
unknown
plain_text
2 months ago
1.4 kB
15
No Index
(function() {
    'use strict';

    // prevent duplicate injection (back button / history restore)
    if (document.getElementById("forumbuttons")) {
      return;
    }
  
    const t = document.querySelector('textarea[name="body"]');
    if (!t) return;

    const b = [
        ["B", "[b]", "[/b]"],
        ["I", "[i]", "[/i]"],
        ["U", "[u]", "[/u]"],
        ["S", "[s]", "[/s]"],
        ["URL", "[url]", "[/url]"],
        ["IMG", "[img]", "[/img]"],
        ["YOUTUBE", "[youtube]", "[/youtube]"],
        ["QUOTE", "[quote]", "[/quote]"],
        ["CODE", "[code]", "[/code]"],
        ["SPOILER", "[spoiler]", "[/spoiler]"],
        ["PRE", "[pre]", "[/pre]"]
    ];

    const c = document.createElement("div");
  	c.setAttribute("id", "forumbuttons");
    c.style.marginBottom = "10px";

    b.forEach(([l, o, cTag]) => {
        const btn = document.createElement("button");
        btn.type = "button";
        btn.textContent = l;
        btn.style.marginRight = "4px";
        btn.onclick = () => {
            const s = t.selectionStart, e = t.selectionEnd, v = t.value;
            t.value = v.substring(0, s) + o + v.substring(s, e) + cTag + v.substring(e);
            t.focus();
            t.selectionStart = t.selectionEnd = e + o.length + cTag.length;
        };
        c.appendChild(btn);
    });

    t.parentNode.insertBefore(c, t);
})();
Editor is loading...