moped / pc.sk WysiBB editor

// ==UserScript==
// @name         pc.sk WysiBB editor
// @namespace    pretaktovanie.sk
// @version      0.7
// @description  BBCode editor pre Rychlu odpoved
// @author       moped
// @match        https://pretaktovanie.zoznam.sk/*
// @exclude      https://pretaktovanie.zoznam.sk/ucp.php*
// @grant        none

// ==/UserScript==

function addGlobalJS(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "https://cdn.wysibb.com/js/jquery.wysibb.min.js");
    script.addEventListener('load', function() {
        var script = document.createElement("script");
        script.textContent = "window.$=jQuery.noConflict(true);(" + callback.toString() + ")();";
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

function quick_quote() {
    var qid = this.hash; var user;
    var userobj = document.querySelector(qid+' .username');
    if(userobj === null) user = document.querySelector(qid+' .username-coloured').text;
    else user = document.querySelector(qid+' .username').text;
    var text = document.querySelector(qid+' .content').innerHTML;
    $('#message-box textarea').execCommand('quote',{author: user,seltext:text});
    return false;
}

function main() {

if (typeof (WBBLANG)=="undefined") {WBBLANG = {};}
WBBLANG['sk'] = CURLANG = {
	bold: "Tučné",
	italic: "Kurzíva",
	underline: "Podčiarknuté",
	strike: "Prečiarknuté",
	link: "Odkaz",
	img: "Vložiť obrázok",
	sup: "Superscript",
	sub: "Subscript",
	justifyleft: "Zarovnať vľavo",
	justifycenter: "Zarovnať na stred",
	justifyright: "Zarovnať vpravo",
	table: "Vložiť tabuľku",
	bullist: "• Nečíslovaný zoznam",
	numlist: "1. Číslovaný zoznam",
	quote: "Citácia",
	offtop: "Offtopic",
	code: "Kód",
	spoiler: "Spoiler",
	fontcolor: "Farba písma",
	fontsize: "Veľkosť písma",
	fontfamily: "Typ písma",
	fs_verysmall: "Veľmi malé",
	fs_small: "Malé",
	fs_normal: "Normálne",
	fs_big: "Veľké",
	fs_verybig: "Veľmi veľké",
	smilebox: "Vložiť smajlíka",
	video: "Vložiť video",
	removeFormat: "Vymazať formátovanie",

	modal_link_title: "Vložiť odkaz",
	modal_link_text: "Text odkazu",
	modal_link_url: "URL",
	modal_email_text: "Display email",
	modal_email_url: "Email",
	modal_link_tab1: "Vložiť URL",

	modal_img_title: "Vložiť obrázok",
	modal_img_tab1: "Vložiť URL",
	modal_img_tab2: "Upload image",
	modal_imgsrc_text: "URL obrázka",
	modal_img_btn: "Choose file",
	add_attach: "Add Attachment",

	modal_video_text: "Vlož URL videa (Youtube)",

	close: "Zatvoriť",
	save: "Uložiť",
	cancel: "Zrušiť",
	remove: "Zmazať"
};
wbbdebug=false;
    var wbbOpt = {
        buttons: "bold,italic,underline,strike,|,quote,code,|,bullist,numlist,|,img,link,video,|,fontcolor,fontsize,|,justifyleft,justifycenter,justifyright,|,removeformat,|,smilebox",
        lang: "sk",
        traceTextarea: true,
        showHotkeys: false,
        hotkeys: false,
        smileList: [
			{title:"Úsmnev", img: '<img src="/images/smilies/smile_2.gif" class="smilies" height="20px" width="20px">', bbcode:" :-) "},
            {title:"smile", img: '<img src="/images/smilies/smile.gif" class="smilies" height="24px" width="20px">', bbcode:" :) "},
            {title:"laugh", img: '<img src="/images/smilies/laugh.gif" class="smilies" height="18px" width="18px">', bbcode:" :laugh: "},
            {title:"smile2", img: '<img src="/images/smilies/smile2.gif" class="smilies" height="20px" width="20px">', bbcode:" :D "},
            {title:"Veľký úsmev", img: '<img src="/images/smilies/biggrin.gif" class="smilies" height="20px" width="20px">', bbcode:" :-D "},
            {title:"ROFL", img: '<img src="/images/smilies/lol.gif" class="smilies" height="20px" width="20px">', bbcode:" :rofl: "},
            {title:"hysterical", img: '<img src="/images/smilies/hysterical.gif" class="smilies" height="20px" width="32px">', bbcode:" :hysterical: "},
            {title:"cool", img: '<img src="/images/smilies/cool.gif" class="smilies" height="20px" width="61px">', bbcode:" :cool: "},
            {title:"wink", img: '<img src="/images/smilies/wink.gif" class="smilies" height="20px" width="20px">', bbcode:" ;) "},
            {title:"good", img: '<img src="/images/smilies/good.gif" class="smilies" height="23px" width="26px">', bbcode:" :good: "},
            {title:"confused", img: '<img src="/images/smilies/confused.gif" class="smilies" height="25px" width="18px">', bbcode:" :? "},
            {title:"sorrow", img: '<img src="/images/smilies/sorrov.gif" class="smilies" height="24px" width="20px">', bbcode:" :( "},
            {title:"sad", img: '<img src="/images/smilies/sad.gif" class="smilies" height="20px" width="20px">', bbcode:" :-( "},
            {title:"cry", img: '<img src="/images/smilies/cry.gif" class="smilies" height="20px" width="20px">', bbcode:" :smutny: "},
            {title:"soob", img: '<img src="/images/smilies/soob.gif" class="smilies" height="22px" width="31px">', bbcode:" :cry: "},
            {title:"rolleyes", img: '<img src="/images/smilies/rolleyes.gif" class="smilies" height="20px" width="20px">', bbcode:" :rolleyes: "},
            {title:"facepalm", img: '<img src="/images/smilies/facepalm.gif" class="smilies" height="19px" width="19px">', bbcode:" :facepalm: "},
            {title:"Beeee", img: '<img src="/images/smilies/bleh.gif" class="smilies" height="18px" width="18px">', bbcode:" :P "},
            {title:":P", img: '<img src="/images/smilies/smile80.gif" class="smilies" height="20px" width="20px">', bbcode:" xP "},
            {title:"!", img: '<img src="/images/smilies/excl.gif" class="smilies" height="20px" width="20px">', bbcode:" :!: "},
            {title:"?", img: '<img src="/images/smilies/question.gif" class="smilies" height="19px" width="19px">', bbcode:" :?: "},
            {title:"zlosť", img: '<img src="/images/smilies/ranting.gif" class="smilies" height="24px" width="28px">', bbcode:" :E "},
            {title:"nahnevany", img: '<img src="/images/smilies/mad.gif" class="smilies" height="20px" width="20px">', bbcode:" :x "},
            {title:"velmi nahnevany", img: '<img src="/images/smilies/furious.gif" class="smilies" height="18px" width="18px">', bbcode:" :furious2: "},
            {title:"Very mad", img: '<img src="/images/smilies/smile58.gif" class="smilies" height="37px" width="33px">', bbcode:" :furious: "},
            {title:"wallbash", img: '<img src="/images/smilies/wallbash.gif" class="smilies" height="23px" width="30px">', bbcode:" :wallbash: "},
            {title:"red", img: '<img src="/images/smilies/red.gif" class="smilies" height="25px" width="25px">', bbcode:" :red: "},
            {title:"odpadnem", img: '<img src="/images/smilies/odpadnem.gif" class="smilies" height="20px" width="20px">', bbcode:" :OO= "},
            {title:"dance", img: '<img src="/images/smilies/dance.gif" class="smilies" height="26px" width="39px">', bbcode:" :dance: "},
            {title:"yahooo", img: '<img src="/images/smilies/yahoo.gif" class="smilies" height="27px" width="42px">', bbcode:" yahooo "},
            {title:"reper", img: '<img src="/images/smilies/rep.gif" class="smilies" height="26px" width="35px">', bbcode:" :rep: "},
            {title:"music", img: '<img src="/images/smilies/music.gif" class="smilies" height="25px" width="28px">', bbcode:" :music: "},
            {title:"help", img: '<img src="/images/smilies/help.gif" class="smilies" height="25px" width="35px">', bbcode:" :help: "},
            {title:"bye", img: '<img src="/images/smilies/bye.gif" class="smilies" height="18px" width="26px">', bbcode:" :bye: "}
		],
        allButtons: {
            quote: {
                transform: {
                    '<blockquote class="uncited"><div>{SELTEXT}</div></blockquote>':'[quote]{SELTEXT}[/quote]',
                    '<blockquote><div><cite>{AUTHOR} napísal:</cite>{SELTEXT}</div></blockquote>':'[quote={AUTHOR}]{SELTEXT}[/quote]'
                }
            },
            code: {
                buttonHTML: '<span class="fa fa-code fa-fw"></span>',
                transform: {
                    '<div class="codebox"><p>Kód: <a href="#">Vybrať všetko</a></p><pre><code>{SELTEXT}</code></pre></div>':"[code]{SELTEXT}[/code]"
                }
            },
            bullist: {
                transform: {
                    '<ul>{SELTEXT}</ul>':'[list]{SELTEXT}[/list]',
                    '<li>{SELTEXT}</li>':'[*]{SELTEXT[^\[\]\*]}'
                }
            },
            numlist: {
                transform: {
                    '<ol>{SELTEXT}</ol>':'[list=1]{SELTEXT}[/list]',
                    '<li>{SELTEXT}</li>':'[*]{SELTEXT[^\[\]\*]}'
                }
            }
        }
    };
    $('#qr_postform #message-box > textarea').wysibb(wbbOpt);
}

(function() {
    'use strict';

    var qr_test = document.getElementById('qr_postform');
    if(qr_test === null) return false;

    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement("link");
    style.setAttribute("href", "https://cdn.wysibb.com/css/default/wbbtheme.css");
    style.setAttribute("rel", "stylesheet");
    head.appendChild(style);

    addGlobalStyle('\
   .modesw { width: 80px; } \
   #message-box { width: 872px; } \
   #qr_postform #message-box { margin: 0 auto 5px; } \
   .smile { width: auto!important; height: 20px!important; padding: 7px!important; } \
   .smile img { width: auto!important; max-width: 100%!important; max-height: 100%!important; } \
   .wbb-smilebox > .wbb-list { width: 275px!important; } \
   .wysibb-body { font-size: 1.083333333333333em; line-height: 1.4em; font-family: "Lucida Grande", "Trebuchet MS", Verdana, Helvetica, Arial, sans-serif;} \
   .wysibb-body img { vertical-align: text-bottom!important; } \
   .wysibb-toolbar-btn .fa-code { line-height: 26px; font-size: 1.2em; } \
   @media (max-width: 960px) { #message-box { width: auto; } } \
    ');

    addGlobalJS(main);

    var post_buttons = document.querySelectorAll('.post-buttons');
    post_buttons.forEach(function(element) {
        element.insertAdjacentHTML('beforeend', '<li><a href="#'+ element.parentNode.id +'" title="Rýchla citácia" class="quick-quote button button-icon-only"><i class="icon fa-reply fa-fw" aria-hidden="true"></i><span class="sr-only">Rýchla citácia</span></a></li>');
    });

    var quick_buttons = document.querySelectorAll(".quick-quote");
    quick_buttons.forEach(function(element) {
        element.onclick = quick_quote;
    });
})();