Dreadcast Chat Enhancer

Améliore le chat de Dreadcast.

当前为 2016-07-29 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Dreadcast Chat Enhancer
// @namespace    https://greasyfork.org/scripts/21359-dreadcast-chat-enhancer/
// @version      1.3.3
// @description  Améliore le chat de Dreadcast.
// @author       MockingJay
// @match        http://www.dreadcast.net/Main
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @grant        GM_listValues
// ==/UserScript==

//Lit les variables dans GM à la demande. A utiliser pour chaque déclaration de variable qui est copiée en mémoire.
//initValue: Valeur par défaut de la variable, qu'on lui donne à la déclaration et qu'elle garde si pas d'équivalent en mémoire. localVarName: Valeur GM locale.
function initLocalMemory(defaultValue, localVarName) {
    if (GM_getValue(localVarName) === undefined) {
        GM_setValue(localVarName, defaultValue);
        return defaultValue;
    } else {
        return GM_getValue(localVarName);
    }
}

function rgb2hex(orig){
    var rgb = orig.replace(/\s/g,'').match(/^rgba?\((\d+),(\d+),(\d+)/i);
    return (rgb && rgb.length === 4) ? "#" +
        ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
        ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
        ("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : orig;
}

$(document).ready(function() {

    //Fix sale pour Jaqen ♥
    $("body").css({
        "overflow-x": 'hidden'
    });

    //**********************************************
    // DECLARATION DES VARIABLES
    //**********************************************

    //CONSTANTES
    var W_ZONE_CHAT = 317; //Largeur de base des différents éléments du chat.
    var W_MSG = 290;
    var W_CHATCONTENT = 308; //Valeur pas d'origine, mais nécessaire pour le script.
    var W_CHAT = 328;
    var W_ONGLETS_CHAT = 254;
    var W_CHATFORM = 288;

    var DEFAULT_CHAT_COLOR = rgb2hex($("#zone_chat .zone_infos").css("color"));

    var DEFAULT_ZONE_DROITE_BG = $("#zone_droite").css("background"); //Permet de restituer le fond d'origine (ou de skin) de la zone droite lorsque le chat est à sa largeur initiale.
    var DEFAULT_SCRIPT_ZONE_DROITE_BG = 'http://i.imgur.com/kPzRqS2.png';
    var DEFAULT_SCRIPT_ZONE_CHAT_BG = 'http://i.imgur.com/0J3wOK0.png';

    //Initialisation variables de préférences
    var autoScroll = initLocalMemory(false, "DCCE_autoScroll");
    var scrollBar = initLocalMemory(true, "DCCE_scrollBar");
    var typePredict = initLocalMemory(true, "DCCE_typePredict");
    var chatExtend = initLocalMemory(0, "DCCE_chatExtend");

    var scriptZoneDroiteBG = initLocalMemory(DEFAULT_SCRIPT_ZONE_DROITE_BG, "DCCE_scriptZoneDroiteBG");
    var scriptZoneChatBG = initLocalMemory(DEFAULT_SCRIPT_ZONE_CHAT_BG, "DCCE_scriptZoneChatBG");

    //**********************************************
    // DECLARATION DES FONCTIONS, MISE EN PLACE DU CSS
    //**********************************************

    $("#chatContent").css({
        "overflow-x": 'hidden',
        "overflow-y": 'scroll',
        height: '313px', //width traitée dans setChatCSS
    });

    //Applique la barre de défilement en fonction des préférences, et règle la largeur des lignes dans le chat.
    function setChatContentScroll() {
        if(scrollBar) {
            $("#chatContent").css({"padding-right": '0px'});
            $("#zone_chat .zone_infos .msg").css({width: (W_MSG + chatExtend) + 'px'});
            $("#zone_chat").css({width: (W_ZONE_CHAT + 5 + chatExtend) + 'px'}); //Assure d'avoir le fond derrière la scrollbar lorsque le chat est étendu.
        }
        else {
            $("#chatContent").css({"padding-right": '15px'});
            $("#zone_chat .zone_infos .msg").css({width: (W_MSG + 7 + chatExtend) + 'px'}); //Optimise la largeur prise par le texte, vu que la barre n'y est plus (+7)
            $("#zone_chat").css({width: (W_ZONE_CHAT + chatExtend) + 'px'});
        }
    }


    var $dcce_background = $('<div id="dcce_background"></div>').prependTo($("#zone_page")).css({left: '907px', top: '142px', height: '461px'});

    function setZoneChatBackground() {
        if(chatExtend > 0) {
            $dcce_background.css({background: 'url("' + scriptZoneChatBG + '")',
                                  "background-size": '100% 100%',
                                  width: (W_ZONE_CHAT + 13 + chatExtend) + 'px'});
            $("#zone_droite").css({background: 'url("' + scriptZoneDroiteBG + '")'});
        } else {
            $dcce_background.css({background: 'none'});
            $("#zone_droite").css({background: DEFAULT_ZONE_DROITE_BG});
        }
    }

    function setChatCSS() {
        setChatContentScroll(); //Comprend déjà #ZONE_CHAT et .MSG
        setZoneChatBackground();
        //Fixer les largeurs restantes
        $("#chatContent").width(W_CHATCONTENT + chatExtend);
        $("#zone_chat .zone_infos .chat").width(W_CHAT + chatExtend);
        $("#zone_chat #onglets_chat").width(W_ONGLETS_CHAT + chatExtend);
        $("#chatForm").width(W_CHATFORM + chatExtend);
    }

    setChatCSS(); //Appliquer à l'initialisation.

    //Initialisation du bouton d'alerte, utilisé quand l'autoScroll est désactivé.
    var $newMessageAlert = $('<div />').appendTo($('#zone_chat'));
    $newMessageAlert.text("⚠ Nouveau message! ⚠");
    $newMessageAlert.css({
        display: 'none',
        top: '45px',
        "text-align": 'center',
        cursor: 'pointer',
        background: '#fff',
        border: '1px solid #fff',
        color: '#0296bb',
        "margin-top": '2px',
        "-webkit-box-shadow": '0 0 4px 2px #329bc2',
    });
    $newMessageAlert.attr('onmouseover', 'this.style.backgroundColor=\"#0b9bcb\";this.style.color=\"#FFFFFF\";');
    $newMessageAlert.attr('onmouseout', 'this.style.backgroundColor=\"#FFFFFF\";this.style.color=\"#0296bb\";');

    //Initialisation bandeau latéral
    var $toggleAutoScroll = $('<li id="toggleAutoScroll" class="couleur5" ></li>'+'<li class="separator"></li>').prependTo($('#bandeau ul.menus'));
    if(autoScroll) {
        $("#toggleAutoScroll").text("AS on");
    } else {
        $("#toggleAutoScroll").text("AS off");
    }
    $("#toggleAutoScroll").css({
        cursor: 'pointer',
    });
    $("#toggleAutoScroll").attr('onmouseover', 'this.style.color=\"#0073d5\";');
    $("#toggleAutoScroll").attr('onmouseout', 'this.style.color=\"#999\";');
    //Changer l'autoscroll au clic sur le bandeau latéral.
    $("#toggleAutoScroll").click(function(){
        if(autoScroll) {
            autoScroll = false;
            $("#toggleAutoScroll").text("AS off");
        } else {
            autoScroll = true;
            $("#toggleAutoScroll").text("AS on");
        }
        GM_setValue("DCCE_autoScroll", autoScroll);
    });

    //Fait défiler le chat jusqu'en bas.
    function scrollChat(){
        $('#chatContent').stop().animate({
            scrollTop: $('#chatContent')[0].scrollHeight
        }, 800);
        $newMessageAlert.stop().fadeOut(500);
    }


    function chatChangeColor(id) {

    }


    //**********************************************
    //INTERFACE DE CONFIGURATION UTILISATEUR
    //**********************************************
    var $databox = $('#zone_dataBox');
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //Constructeur de fenêtre de configuration
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    var DCCE_ConfigurationWindow = function () {
        var window_width = '560px';
        var window_height = '450px';
        var $config_window = $('<div id="dcce_configwindow" onclick="engine.switchDataBox(this)"/>');
        $config_window.draggable();
        $config_window.addClass('dataBox focused ui-draggable');
        $config_window.css({
            width: window_width,
            "margin-left": '-185px',
            display: 'block',
            position: 'absolute',
            "z-index": '2',
        });
        for (var i = 1; i <= 8; i++) {
            $('<div class="dbfond' + i + '" />').appendTo($config_window);
        }
        var $config_head = $('<div class="head ui-draggable-handle" ondblclick="$(\'#dcce_configwindow\').toggleClass(\'reduced\');" />').appendTo($config_window);
        $('<div title="Fermer la fenêtre (Q)" class="info1 link close" onclick="engine.closeDataBox($(this).parent().parent().attr(\'id\'));" />').appendTo($config_head);
        $('<div title="Reduire/Agrandir la fenêtre" class="info1 link reduce" onclick="$(\'#dcce_configwindow\').toggleClass(\'reduced\');" />').appendTo($config_head);
        $('<div class="title">Configuration DC Enhanced Chat</div>').appendTo($config_head);
        $('<div class="dbloader" />').appendTo($config_window);
        var $config_content = $('<div class="content" style="height:' + window_height + '; overflow: auto"/>').appendTo($config_window);
        //----------------------------------------
        //Widgets internes
        //----------------------------------------
        var $config_interface = $('<div />').appendTo($config_content);
        $config_interface.css({
            "margin-left": '3px',
            "font-variant": 'small-caps',
            color: '#fff',
            height: '100%',
            width: '98%',
        });
        //----------------------------------------
        //Configuration du défilement, auto-scroll
        //----------------------------------------
        var $autoconfig = $('<div />').appendTo($config_interface);
        var $autoconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($autoconfig);
        $autoconfig_title.text('Options de défilement du texte');
        $autoconfig_title.css({
            "margin-bottom": '5px',
            "border-bottom": '1px solid',
            display: 'block',
            "font-size": '17px',
            "-webkit-margin-before": '0.83em',
            "-webkit-margin-after": '0.83em',
            "-webkit-margin-start": '0px',
            "-webkit-margin-end": '0px',
            "font-weight": 'bold',
            position: 'relative',
        });
        var $autoconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
        $autoconfig_container.text('Défilement automatique : ');
        $autoconfig_container.css({
            display: 'inline-block',
            "margin-bottom": '15px',
        });
        var $autoconfig_radio_activate = $('<input type="radio" name="typeAutoRadio" value="false">Activer</input>').appendTo($autoconfig_container);
        $autoconfig_radio_activate.css({
            margin: '0 5px',
        });
        $autoconfig_radio_activate.attr('checked', autoScroll);
        $autoconfig_radio_activate.change(function(){
            autoScroll = true;
            GM_setValue("DCCE_autoScroll", autoScroll);
            $("#toggleAutoScroll").text("AS on");
        });
        var $autoconfig_radio_deactivate = $('<input type="radio" name="typeAutoRadio" value="true">Désactiver</input>').appendTo($autoconfig_container);
        $autoconfig_radio_deactivate.css({
            margin: '0px 5px 0 25px',
            "padding-left": '20px',
        });
        $autoconfig_radio_deactivate.attr('checked', !autoScroll);
        $autoconfig_radio_deactivate.change(function(){
            autoScroll = false;
            GM_setValue("DCCE_autoScroll", autoScroll);
            $("#toggleAutoScroll").text("AS off");
        });
        //----------------------------------------
        //Configuration de l'affichage de la barre de défilement
        //----------------------------------------
        var $scrconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
        $scrconfig_container.text('Barre de défilement : ');
        $scrconfig_container.css({
            display: 'inline-block',
            "margin-bottom": '15px',
        });
        var $scrconfig_radio_activate = $('<input type="radio" name="typeScrRadio" value="false">Afficher</input>').appendTo($scrconfig_container);
        $scrconfig_radio_activate.css({
            margin: '0 5px',
        });
        $scrconfig_radio_activate.attr('checked', scrollBar);
        $scrconfig_radio_activate.change(function(){
            scrollBar = true;
            GM_setValue("DCCE_scrollBar", scrollBar);
            setChatContentScroll();
        });
        var $scrconfig_radio_deactivate = $('<input type="radio" name="typeScrRadio" value="true">Masquer</input>').appendTo($scrconfig_container);
        $scrconfig_radio_deactivate.css({
            margin: '0px 5px 0 25px',
            "padding-left": '20px',
        });
        $scrconfig_radio_deactivate.attr('checked', !scrollBar);
        $scrconfig_radio_deactivate.change(function(){
            scrollBar = false;
            GM_setValue("DCCE_scrollBar", scrollBar);
            setChatContentScroll();
        });
        //----------------------------------------
        //Configuration de l'affichage de la barre de défilement
        //----------------------------------------
        var $predconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
        $predconfig_container.text('Défiler le chat à l\'écriture : ');
        $predconfig_container.css({
            display: 'inline-block',
            "margin-bottom": '15px',
        });
        var $predconfig_radio_activate = $('<input type="radio" name="typePredRadio" value="false">Oui</input>').appendTo($predconfig_container);
        $predconfig_radio_activate.css({
            margin: '0 5px',
        });
        $predconfig_radio_activate.attr('checked', typePredict);
        $predconfig_radio_activate.change(function(){
            typePredict = true;
            GM_setValue("DCCE_typePredict", typePredict);
        });
        var $predconfig_radio_deactivate = $('<input type="radio" name="typePredRadio" value="true">Non</input>').appendTo($predconfig_container);
        $predconfig_radio_deactivate.css({
            margin: '0px 5px 0 25px',
            "padding-left": '20px',
        });
        $predconfig_radio_deactivate.attr('checked', !typePredict);
        $predconfig_radio_deactivate.change(function(){
            typePredict = false;
            GM_setValue("DCCE_typePredict", typePredict);
        });
        this.$window = $config_window;

        //----------------------------------------
        //Configuration de la largeur du chat
        //----------------------------------------
        var $xtdconfig = $('<div />').appendTo($config_interface);
        var $xtdconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($xtdconfig);
        $xtdconfig_title.text('Largeur du chat');
        $xtdconfig_title.css({
            "margin-bottom": '5px',
            "border-bottom": '1px solid',
            display: 'block',
            "font-size": '17px',
            "-webkit-margin-before": '0.83em',
            "-webkit-margin-after": '0.83em',
            "-webkit-margin-start": '0px',
            "-webkit-margin-end": '0px',
            "font-weight": 'bold',
            position: 'relative',
        });
        var $xtdconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
        //$xtdconfig_container.text('Défilement automatique : ');
        $xtdconfig_container.css({
            display: 'inline-block',
            "margin-bottom": '15px',
        });
        var $xtdconfig_range = $('<input type="range" name="typeXtdRange" value="' + chatExtend + '" min="0" max="300" step="1"></input>').appendTo($xtdconfig_container);
        $xtdconfig_range.css({
            margin: '0 5px',
            width: '500px'
        });
        $xtdconfig_range.change(function(){
            chatExtend = Number($xtdconfig_range.val());
            GM_setValue("DCCE_chatExtend", chatExtend);
            setChatCSS();
        });

        //----------------------------------------
        //Configuration des fonds de zone droite/chat customs
        //----------------------------------------
        var $bgconfig = $('<div />').appendTo($config_interface);
        var $bgconfig_title = $('<h2 class="couleur4 configTitre" />').appendTo($bgconfig);
        $bgconfig_title.text('Fonds de zone customisés (pour réinitialiser, effacer la ligne)');
        $bgconfig_title.css({
            "margin-bottom": '5px',
            "border-bottom": '1px solid',
            display: 'block',
            "font-size": '17px',
            "-webkit-margin-before": '0.83em',
            "-webkit-margin-after": '0.83em',
            "-webkit-margin-start": '0px',
            "-webkit-margin-end": '0px',
            "font-weight": 'bold',
            position: 'relative',
        });
        var $bgconfig_container = $('<div class="ligne"/>').appendTo($config_interface);
        $bgconfig_container.css({
            display: 'inline-block',
            "margin-bottom": '15px',
        });
        var $bgconfig_pzonedroite = $('<div>Fond messagerie:</div>').appendTo($bgconfig_container);
        $bgconfig_pzonedroite.css({
            margin: '0 5px',
            width: '500px'
        });
        var $bgconfig_zonedroite = $('<input type="url" name="typeBGzonedroite" value="' + scriptZoneDroiteBG + '" style="background-color: antiquewhite;"></input>').appendTo($bgconfig_container);
        $bgconfig_zonedroite.css({
            margin: '0 5px',
            width: '500px'
        });
        $bgconfig_zonedroite.keyup(function(){
            if($(this).val() === DEFAULT_SCRIPT_ZONE_DROITE_BG || $(this).val() === "") {
                GM_deleteValue("DCCE_scriptZoneDroiteBG");
                scriptZoneDroiteBG = DEFAULT_SCRIPT_ZONE_DROITE_BG;
            } else {
                scriptZoneDroiteBG = $(this).val();
                GM_setValue("DCCE_scriptZoneDroiteBG", scriptZoneDroiteBG);
            }
            setZoneChatBackground();
        });
        var $bgconfig_pzonechat = $('<div> </div><div>Fond chat:</div>').appendTo($bgconfig_container);
        $bgconfig_pzonechat.css({
            margin: '0 5px',
            width: '500px'
        });
        var $bgconfig_zonechat = $('<input type="url" name="typeBGzonechat" value="' + scriptZoneChatBG + '" style="background-color: antiquewhite;"></input>').appendTo($bgconfig_container);
        $bgconfig_zonechat.css({
            margin: '0 5px',
            width: '500px'
        });
        $bgconfig_zonechat.keyup(function(){
            if($(this).val() === DEFAULT_SCRIPT_ZONE_CHAT_BG || $(this).val() === "") {
                GM_deleteValue("DCCE_scriptZoneChatBG");
                scriptZoneChatBG = DEFAULT_SCRIPT_ZONE_CHAT_BG;
            } else {
                scriptZoneChatBG = $(this).val();
                GM_setValue("DCCE_scriptZoneChatBG", scriptZoneChatBG);
            }
            setZoneChatBackground();
        });
    };
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //FIN Constructeur de fenêtre de configuration
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    //---------------------------------------------------
    //Ajout d'un item au menu bandeau "Paramètres" de DC
    //---------------------------------------------------
    var $params_menu = $('.menus > .parametres > ul');
    var $dcce_config = $('<li />').appendTo($params_menu);
    $dcce_config.text("Configuration du Chat");
    $dcce_config.addClass('link couleur2 separator');

    $dcce_config.click(function () {
        //Fermeture des autres instances de paramétrage ouvertes
        engine.closeDataBox('dcce_configwindow');
        var $config_window = new DCCE_ConfigurationWindow();
        $databox.append($config_window.$window);
    });

    //**********************************************
    // FIN INTERFACE DE CONFIGURATION UTILISATEUR
    //**********************************************

    //**********************************************
    // DEBUT MAIN
    //**********************************************

    //SCROLLING
    scrollChat(); //Place le chat au chargement du jeu.
    $newMessageAlert.click(scrollChat); //Scroll au clic du bouton d'alerte de nouveau message.
    $(".text_chat").keydown(function(key){ //Si en préférence, scroller le chat automatiquement quand on commence à écrire.
        if(typePredict && key != 13) scrollChat(); //Ne pas le faire avec la touche entrée car déjà fait quand la ligne apparaît dans le chat.
    });
    var lastChat = $('#chatContent').text(); //Sert à comparer pour voir si le chat a changé.
    setInterval(function(){ //Scrolle ou alerte à la réception d'un message.
        if(lastChat != $('#chatContent').text()) {
            lastChat = $('#chatContent').text(); //Actualiser la copie local du chat.

            setChatContentScroll();

            if(autoScroll) {
                scrollChat();
            }
            else {
                $newMessageAlert.stop().fadeIn(500);
            }
        }
    }, 1000);

    //COLOR TAG
    $(document).on("click", "span.perso.link", function(){
        var idPerso = $(this).attr('id').slice(9);
        $(document).one("ajaxSuccess", {idPerso: idPerso}, function(e){ //Permet d'attendre le chargement de la fenêtre, one() pour éviter un duplicata.
            var idctb = '#colorTagBox_' + e.data.idPerso;
            var colorTagBox = $('<div style="margin-top: 15px; text-align: center;">' + 'Couleur chat: ' +
                                '<input type="color" id="' + idctb.slice(1) + '" value="' + DEFAULT_CHAT_COLOR + '"/>' +
                                '<input type="button" id="' + idctb.slice(1) + '_reset" value="Reset" style="background-color: buttonface; margin-left: 5px; height: 16px; font-size: 12px;"/>' +
                                '</div>').appendTo($("#ib_persoBox_" + e.data.idPerso + " .fakeToolTip"));
            if(GM_getValue("dcce_ctb_" + e.data.idPerso) !== undefined) { //Récupère et applique au bouton couleur la couleur enregistrée
                $(idctb).val((GM_getValue("dcce_ctb_" + e.data.idPerso)));
            }
            $(idctb).on("change", {idPerso: e.data.idPerso}, function(e) { //Enregistre en mémoire la nouvelle couleur
                GM_setValue("dcce_ctb_" + e.data.idPerso, $(this).val());
                chatChangeColor(e.data.idPerso);
            });
            $(idctb + "_reset").on("click", {idPerso: e.data.idPerso}, function(e) { //Reset de la couleur
                GM_deleteValue("dcce_ctb_" + e.data.idPerso);
                $(idctb).val(DEFAULT_CHAT_COLOR);
                chatChangeColor(e.data.idPerso);
            });
        });

    });
});