Imperia Online Tribune Chat

try to take over the world!

目前為 2016-01-14 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Imperia Online Tribune Chat
// @namespace    tar
// @version      1.1
// @description  try to take over the world!
// @author       ChoMPi
// @match        http://*.imperiaonline.org/imperia/game_v6/game/village.php*
// @require      https://cdnjs.cloudflare.com/ajax/libs/jQuery-linkify/1.1.7/jquery.linkify.min.js
// ==/UserScript==
/* jshint -W097 */
'use strict';

var isActive = false;
var chatWrapper;
var chatBox;
var chatBoxMessages;
var messageInput;
var loading;
var interval = 10000; // Time in milliseconds

function handle_mousedown(e)
{
    if ($(e.target).hasClass('message') || $(e.target).hasClass('username'))
    {
        return;
    }
    
    window.my_dragging = {};
    my_dragging.pageX0 = e.pageX;
    my_dragging.pageY0 = e.pageY;
    my_dragging.elem = chatWrapper;
    my_dragging.offset0 = $(chatWrapper).offset();
    
    function handle_dragging(e)
    {
        var left = my_dragging.offset0.left + (e.pageX - my_dragging.pageX0);
        var top = my_dragging.offset0.top + (e.pageY - my_dragging.pageY0);
        $(my_dragging.elem).offset({top: top, left: left});
    }
    
    function handle_mouseup(e)
    {
        $('body').off('mousemove', handle_dragging).off('mouseup', handle_mouseup);
    }
    
    $('body').on('mouseup', handle_mouseup).on('mousemove', handle_dragging);
}

function populateChat(data)
{
    var messages = $(data).find("#messageboxMessages").html();
    messages = messages.replace("<![CDATA[S", "").replace("]]>", "");
    messages = $(messages).find(".comment-section");
    
    messages.find(".comment").each(function(e, i)
    {
        var status = $(this).find('.table-icons');
        var user = $(this).find('.username');
        var msg = $(this).find('p > span');
        
        if (msg.length == 0)
        {
            var temp = $(this).clone();
            temp.find('.username').remove();
            temp.find('.date').remove();
            msg = $('<div class="resources-bar" style="line-height: 18px; padding: 6px; margin: 4px 0 0 0;border-bottom: 1px solid #9A8C70;"><span class="original-message">' + temp.text() + '</span></div>');
        }
        else
        {
            msg.linkify({
                target: "_blank"
            });
            //msg.html(Autolinker.link(msg.html()));
        }
        
        status.css('margin-left', '-8px');
        user.removeClass('fleft');
        msg.addClass('message');
        $(this).css('padding-bottom', '5px');
        $(this).css('margin-top', '6px');
        
        $(this).html(((status.length > 0) ? status[0].outerHTML : '') + user[0].outerHTML + ":&nbsp;" + msg[0].outerHTML);
    });
    
    loading.hide();
    chatBoxMessages.html(messages.html());
}

function pullMessages()
{
    if (!isActive)
    {
        return;
    }
    
    $.post(location.protocol + "//" + location.host + "/imperia/game_v6/game/xajax_loader.php",
    {
        xjxfun: "viewConversationMessages",
        xjxr: Date.now(),
        xjxargs: ["Sconversations", "<xjxobj><e><k>tab</k><v>N3</v></e><e><k>vexok</k><v>Btrue</v></e></xjxobj>"],
    },
    function(data){
        populateChat(data);
    }, "xml");
}

function sendMessage(event)
{
    $.post(location.protocol + "//" + location.host + "/imperia/game_v6/game/xajax_loader.php",
    {
        xjxfun: "doConversationMessagesCreate",
        xjxr: Date.now(),
        xjxargs: ["Sconversations", "<xjxobj><e><k>tab</k><v>N3</v></e><e><k>data</k><v><xjxobj><e><k>txtMsg</k><v>S<![CDATA[" + messageInput.val() + "]]></v></e><e><k>send_message</k><v>SSend</v></e></xjxobj></v></e><e><k>vexok</k><v>Btrue</v></e></xjxobj>"],
    },
    function(data){
        populateChat(data);
    }, "xml");
    
    messageInput.val("");
    
    return false;
}

function Init()
{
    $('<style type="text/css">' +
      '#chat_wrapper .comment-section::-webkit-scrollbar{ width:15px;background:rgba(111,98,66,0.4); }' +
      '#chat_wrapper .comment-section::-webkit-scrollbar-thumb{ background-color:#87795D;border:1px solid #554D3B;border-radius:4px; }' +
      '#chat_wrapper .comment-section::-webkit-scrollbar-thumb:hover{ background-color:#8F8063; }' +
      '#chat_wrapper { position:fixed;left:2px;bottom:88px;z-index:100;width:500px;height:161px;display:none;-webkit-user-select:text;-khtml-user-select:text;-moz-user-select:text;-ms-user-select:text;user-select:text; }' +
      '#chat_wrapper .comment-section { padding:1px 8px 0px 8px;margin:0;width:500px;height:140px;overflow-x:hidden;overflow-y:scroll;box-shadow:1px 1px 20px #000;border:1px solid #E8D4AC;background:#b2a07c url("../gui/bg_patern.png?v=7"); }' +
      '#chat_wrapper input { width:512px;margin-top:1px;opacity:0.7;color:#fff;background:rgba(45, 40, 29, 0.92);border:1px solid #E8D4AC;padding:2px; }' +
      '#chat_wrapper input:focus { opacity:1; }' +
      '#chat_wrapper input::-webkit-input-placeholder { color:#E8E8E8; } #chat_wrapper input:-moz-placeholder { color:#E8E8E8;opacity:1; } #chat_wrapper input::-moz-placeholder { color:#E8E8E8;opacity:  1; } #chat_wrapper input:-ms-input-placeholder { color:#E8E8E8; } #chat_wrapper input:placeholder-shown { color:#E8E8E8; }' +
      '#chat-button { position:fixed;bottom:41px;left:0px;z-index:201; }' +
      '</style>').appendTo("head");
                                                                                                    
    chatWrapper = $('<div id="chat_wrapper"></div>');
    $("body").append(chatWrapper);

    chatBox = $('<div class="comment-section"></div>');
    chatWrapper.append(chatBox);
    
    chatBoxMessages = $('<div style="padding:0;margin:0;"></div>');
    chatBoxMessages.mousedown(handle_mousedown);
    chatBox.append(chatBoxMessages);
    
    loading = $('<center style="margin-top: 70px;">Loading...</center>');
    chatBox.append(loading);
    
    var form = $('<form></form>');
    messageInput = $('<input type="text" placeholder="Send message" name="message" autocomplete="off" />');
    form.append(messageInput);
    form.on("submit", sendMessage);
    chatWrapper.append(form);
    
    chatWrapper.mousedown(function(){ chatWrapper.css("z-index", "1999"); });
    $(document).mousedown(function(event) {
        if ($(event.target).parents("#chat_wrapper").length == 0) {
            chatWrapper.css("z-index", "1000");
            messageInput.blur();
        }        
    });
    $(document).keypress(function(e) {
        if (isActive && e.which == 13) {
            if (!messageInput.is(":focus") && $(':focus').prop("tagName") != 'TEXTAREA' && $(':focus').prop("tagName") != 'INPUT') {
                messageInput.focus();
                chatWrapper.css("z-index", "1999");
            }
        }
    });
    
    var button = $('<div id="chat-button" class="ui"><div id="settings-holder" class="ui-bg" title="Tribune Chat"><div class="ui-icons help ps2"></div></div></div>');
    $('body').append(button);
    
    button.click(function()
    {
        if (isActive) {
            chatWrapper.fadeOut('fast');
            isActive = false;
        }
        else
        {
            chatWrapper.fadeIn('fast');
            isActive = true;
            pullMessages();
        }
    });
    
    setInterval(pullMessages, interval);
}

$(document).ready(function()
{
    function InitCheck()
    {
        if (!$('body').hasClass('loading'))
        {
            Init();
        }
        else
        {
            setTimeout(InitCheck, 500);
        }
    }
    InitCheck();
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址