BBCodes for MAL

Add BBCode to MAL Forum posts

Stan na 10-03-2015. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name           BBCodes for MAL
// @namespace      No Page
// @description    Add BBCode to MAL Forum posts
// @author         Al_eXs
// @include        *myanimelist.net/forum/?topicid=*
// @include        *myanimelist.net/forum/?action=message&msgid=*
// @include        *myanimelist.net/forum/?action=message&topic_id=*
// @include        *myanimelist.net/mymessages.php?go=send*
// @include        *myanimelist.net/editprofile.php*
// @include        *myanimelist.net/myblog.php*
// @include        *myanimelist.net/forum/?action=post*
// @include        *myanimelist.net/forum/index.php?action=post&boardid=*
// @include        *myanimelist.net/clubs.php?cid=*
// @include        *myanimelist.net/profile/*
// @include        *myanimelist.net/modules.php?go=report&type=forummessage&id=*
// @include        *myanimelist.net/mymessages.php?toname=*
// @include        *myanimelist.net/comtocom.php?id1=*
// @include        *myanimelist.net/comments.php?id=*
// @exclude        *myanimelist.net/editprofile.php?go=stylepref&do=cssadv&id=*
// @version        1.0.16
// ==/UserScript==

function addtag(obj, tag) {

    beforeText = obj.value.substring(0, obj.selectionStart);
    selectedText = obj.value.substring(obj.selectionStart, obj.selectionEnd);
    afterText = obj.value.substring(obj.selectionEnd, obj.value.length);
    newText = null;

    switch(tag) {

        case "bold":
            tagOpen = "[b]";
            tagClose = "[/b]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "strike":
            tagOpen = "[s]";
            tagClose = "[/s]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "italic":
            tagOpen = "[i]";
            tagClose = "[/i]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "underline":
            tagOpen = "[u]";
            tagClose = "[/u]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "code":
            tagOpen = "[code]";
            tagClose = "[/code]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "centre":
            tagOpen = "[center]";
            tagClose = "[/center]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "right":
            tagOpen = "[right]";
            tagClose = "[/right]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "spoiler":
            tagOpen = "[spoiler]";
            tagClose = "[/spoiler]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "url":
            urlOrDesc = prompt("Enter URL or URL description", "");

            if (urlOrDesc == null) {
                break;
            }

            url0 = urlOrDesc.substring(0,7);

            if ((url0 == "http://") || (url0 == "https:/")) {
                tagOpen = "[url=" + urlOrDesc + "]";
                tagClose = "[/url]";
            } else {
                tagOpen = "[url=";
                tagClose = "]" + urlOrDesc + "[/url]";
            }

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "image":
            imgURL = prompt("Enter image URL", "");

            if (imgURL == null) {
                break;
            }

            tagOpen = "[img]";
            tagClose = "[/img]";

            newText = beforeText + tagOpen + imgURL + tagClose + afterText;
            break;

        case "size":
            txtSize = document.getElementById("Size");

            if (txtSize == "Size") {
                break;
            }

            if (txtSize.value == "enter") {
                txtSizeName = prompt("Enter the size (from 0 to 999, 100 is default)", "");
            } else {
                txtSizeName = txtSize.value;
            }

            if (txtSizeName == null) {
                break;
            }

            tagOpen = "[size=" + String(txtSizeName) + "]";
            tagClose = "[/size]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "profile":
            profile = prompt("Enter profile name", "");
            
            if (profile == null) {
                break;
            }

            tagOpen = "[profile=" + profile + "]";
            tagClose = "[/profile]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "youtube":
            yt = prompt("Enter complete youtube url", "");
            
            if (yt == null) {
                break;
            }

            yt0 = yt.replace("https://","http://");
            yt1 = yt0.replace("http://www.youtube.com/watch?v=","");
            yt2 = yt1.substring(0,11);

            tagOpen = "[yt]";
            tagClose = "[/yt]";

            newText = beforeText + tagOpen + yt2 + tagClose + afterText;
            break;

        case "colour":
            colour = document.getElementById("Colour");

            if (colour == "Select") {
                break;
            }

            if (colour.value == "enter") {
                colourName = prompt("Enter the colour name or hex value (e.g. #abc123)", "");
            } else {
                colourName = colour.value;
            }

            if (colourName == null) {
                break;
            }

            tagOpen = "[color=" + String(colourName) + "]";
            tagClose = "[/color]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "quote=":
            quote = prompt("Enter quoted person name", "");
            
            if (quote == null) {
                break;
            }

            tagOpen = "[quote=" + quote + "]";
            tagClose = "[/quote]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "quote":
            tagOpen = "[quote]";
            tagClose = "[/quote]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "list":
            tagOpen = "[list][*]";
            tagClose = "[/list]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "list=1":
            tagOpen = "[list=1][*]";
            tagClose = "[/list]";

            newText = beforeText + tagOpen + selectedText + tagClose + afterText;
            break;

        case "[*]":
            tagOpen = "[*]";
            tagClose = "";

            newText = beforeText + tagOpen + selectedText + afterText;
            break;
    }

    if (newText != null) {
        caretStart = obj.selectionStart;
        caretEnd = obj.selectionEnd;
        if (selectedText.length == 0) {
            caretEnd -= tagClose.length;
        }
        caretEnd += newText.length - obj.value.length;
        caretStart = caretEnd;
        obj.value = newText;
        obj.setSelectionRange(caretStart, caretEnd);
    }
    obj.focus();
}

function xpath(query, object) {
    if(!object) var object = document;
    return document.evaluate(query, object, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
}

function getXpathSnap(){
    var path = xpath("//textarea[@class='textarea']");
    if(path.snapshotLength == 0) {
        path = xpath("//textarea[@class='inputtext']");
        return (path.snapshotLength > 0) ?  path.snapshotItem(0) : false;
    }
    for (var j = 0; j < path.snapshotLength; j++) {
        if (path.snapshotItem(j).previousElementSibling == null) {
            return path.snapshotItem(j);
        }
    }
    return false;
}

var xpathSnap = getXpathSnap();

var allReplies = xpath("//a[@title='Reply to this comment']");
for (var i = 0; i < allReplies.snapshotLength; i++) {
    (function(ind){allReplies.snapshotItem(ind).addEventListener("click", function(){
        xpathSnap = getXpathSnap();
        createButtons();
        var replyButton = xpath("//input[contains(@onclick, 'submitReplyComment')]").snapshotItem(ind);

        var replied;
        function replyTimer() {
            var repeatCount = 0;
            return setInterval(function(){
                addCodeToEdits();
                repeatCount += 1;
                if (repeatCount >= 6) {
                    //replyButton.removeEventListener("click", editsTimer);
                    //replyButton.addEventListener("click", editsTimer, false);
                    clearInterval(replied);
                    //repeatCount = 0;
                    //replied = replyTimer();
                }
            }, 500);
        }

        replyButton.addEventListener("click", function() {
            replied = replyTimer();
        }, false);  //Modern browsers
    }, true);})(i)
}

addCodeToEdits();

function addCodeToEdits() {
    var allEdits = xpath("//a[@title='Edit Comment']");
    var toEdit;
    for (var i = 0; i < allEdits.snapshotLength; i++) {
        (function(ind) {
            allEdits.snapshotItem(ind).removeEventListener("click", function() {toEdit = editTimer();});
            allEdits.snapshotItem(ind).addEventListener("click", function() {toEdit = editTimer();}, true);
        })(i);
    }
    function editTimer() {
        var repeatCount = 0;
        return setInterval(function() {
            xpathSnap = getXpathSnap();
            createButtons();
            repeatCount += 1;
            if (repeatCount >= 6) {
                clearInterval(toEdit);
            }
        }, 400);
    }
}

createButtons();

function createButtons() {
    if(xpathSnap){
        var div1 = document.createElement("div");
        div1.style="margin: 0px; margin-top:10px; margin-bottom:5px";
        div1.align ="Left";
        div1.id = "myBBcode";
        div1.innerHTML = " ";
        div1.style.display = "block";

        xpathSnap.parentNode.insertBefore(div1, xpathSnap);

        var post = document.createElement("input");
        post.type = "button";
        post.value = "Bold";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'bold');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Italic";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'italic');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Strike";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'strike');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Underline";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'underline');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Code";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'code');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Centre";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'centre');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Right";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'right');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "URL";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'url');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Spoiler";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'spoiler');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "IMG";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'image');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Youtube";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'youtube');}, false);
        div1.appendChild(post);
    var post = document.createElement("BROKEN");
        post.type = "button";
        post.value = "Profile";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'profile');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Quote=";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'quote=');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "Quote";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'quote');}, false);
        div1.appendChild(post);
    var postSize = document.createElement("select");
        postSize.id = "Size";
        //postSize.value = "Size";
        var opt = document.createElement("option");
        opt.value = "Size";
        opt.appendChild(document.createTextNode('Size'));
        postSize.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "50";
        opt.appendChild(document.createTextNode('Small'));
        postSize.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "100";
        opt.appendChild(document.createTextNode('Normal'));
        postSize.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "300";
        opt.appendChild(document.createTextNode('Medium'));
        postSize.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "600";
        opt.appendChild(document.createTextNode('Big'));
        postSize.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "900";
        opt.appendChild(document.createTextNode('Ultra Big'));
        postSize.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "enter";
        opt.appendChild(document.createTextNode('Enter size'));
            postSize.appendChild(opt);
    postSize.addEventListener('change', function() {addtag(document.getElementsByTagName("textarea")[0],'size'); postSize.value = 'Size'}, false);
        div1.appendChild(postSize);
    var postColour = document.createElement("select");
        postColour.id = "Colour";
        //postColour.value = "Colour";
        var opt = document.createElement("option");
        opt.value = "Select";
        opt.appendChild(document.createTextNode('Select Colour'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "grey";
        opt.appendChild(document.createTextNode('Grey'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "blue";
        opt.appendChild(document.createTextNode('Blue'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "red";
        opt.appendChild(document.createTextNode('Red'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "green";
        opt.appendChild(document.createTextNode('Green'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "yellow";
        opt.appendChild(document.createTextNode('Yellow'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "pink";
        opt.appendChild(document.createTextNode('Pink'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "navy";
        opt.appendChild(document.createTextNode('Navy'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "white";
        opt.appendChild(document.createTextNode('White'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "black";
        opt.appendChild(document.createTextNode('Black'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "orange";
        opt.appendChild(document.createTextNode('Orange'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "purple";
        opt.appendChild(document.createTextNode('Purple'));
        postColour.appendChild(opt);
        var opt = document.createElement("option");
        opt.value = "enter";
        opt.appendChild(document.createTextNode('Enter colour'));
        postColour.appendChild(opt);
        postColour.addEventListener('change', function() {addtag(document.getElementsByTagName("textarea")[0],'colour'); postColour.value = 'Select'}, false);
        div1.appendChild(postColour);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "list";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'list');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "list=1";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'list=1');}, false);
        div1.appendChild(post);
    var post = document.createElement("input");
        post.type = "button";
        post.value = "[*]";
        post.addEventListener('click', function() {addtag(document.getElementsByTagName("textarea")[0],'[*]');}, false);
        div1.appendChild(post);
    }
}