WME Chat Resize

Adds resize buttons to the chat window

当前为 2014-11-02 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name 			WME Chat Resize
// @description 	Adds resize buttons to the chat window
// @namespace		[email protected]
// @grant			none
// @grant			GM_info
// @version			0.0.2
// @match			https://editor-beta.waze.com/*editor/*
// @match			https://www.waze.com/*editor/*
// @author			Rick Zabel '2014
// @license			MIT/BSD/X11
// ==/UserScript==


/* Changelog
 * 0.0.2 - made the buttons not Interfere with each other
 * 0.0.1 - initial version
 */

//setup some global vars to be used in the functions 
//currently i plan on lettings the chat default to normal on page load
window.WMEChatResizeHeight = "short"; //short or tall
window.WMEChatResizeUsers  = "shown";  //shown  or hidden


function WMEChatResize_bootstrap()
{
    var bGreasemonkeyServiceDefined = false;
    
    try {
        var ver = window.navigator.appVersion.match(/Chrome\/(.*?) /)[1];
    } catch(err) {
        var ver = null;
    }
    if (null !== ver) {
        var itschrome = true;
        ///ver = "27.0.1438.7"; // last old working version
        // example: 32.0.1700.107
        // [0] - major versin
        // [2] - minor version
        ver = ver.split(".");
        ver[0] = parseInt(ver[0]);
        ver[2] = parseInt(ver[2]);
        if (ver[0] > 27) {
            var newmethod = true;
        } else if (ver[0] == 27) {
            if (ver[2] <= 1438) {
                var newmethod = false;
            } else {
                var newmethod = true;
            }
        } else {
            var newmethod = false;	
        }
    } else {
        var itschrome = false;
        var newmethod = false;
    }
    
    try
    {
        if ("object" === typeof Components.interfaces.gmIGreasemonkeyService)  // Firefox tells that "Components" is deprecated
        {
            bGreasemonkeyServiceDefined = true;
        }
    }	catch (err) { };
    
    try
    {
        if  ("object" === typeof GM_info) 
        {
            bGreasemonkeyServiceDefined = true;
        }
    }	catch (err) { };   
    
    
    if ( "undefined" === typeof unsafeWindow  ||  ! bGreasemonkeyServiceDefined)
    {
        try {
            unsafeWindow    = ( function ()
                               {
                                   var dummyElem   = document.createElement('p');
                                   dummyElem.setAttribute ('onclick', 'return window;');
                                   return dummyElem.onclick ();
                               } ) ();
        } 
        catch (err)
        {
            //Ignore.
        }
    }
    
    /* FIX IT !!!! */
    var itschrome = true;
    var newmethod = true;
    var bGreasemonkeyServiceDefined = false;
    
    //And check again for new chrome, and no tamper(grease)monkey
    if ( itschrome && newmethod &&  !bGreasemonkeyServiceDefined)
    {
        //use "dirty" but effective method with injection to document
        var DLscript = document.createElement("script");
        DLscript.textContent ='unsafeWindow=window; \n'+ // need this for compatibility
            WMEChatResize_init.toString()+' \n'+
            'WMEChatResize_init();';
        DLscript.setAttribute("type", "application/javascript");
        document.body.appendChild(DLscript);    
        document.body.removeChild(DLscript); 
    } else {
        /* begin running the code! */
        WMEChatResize_init();
        ///setTimeout(WMEChatResize_init,200);
    }  
}



function WMEChatResize_init() {
    
    WMEChatResize =  { 
        last: new Array(),
        isLast: false,
        isLSsupported: false,
        zoom: false
    };
    
    WMEChatResize.init = function() {
        
        //hide/show user list
        
        var b = $('<button id="WMEChatResize-HideUsers" class="WMEChatResize" style="position:absolute;Right:50px;color:#CC0000" title="Hide Users" type="button">></button>');
        b.click (WMEChatResize.Hide);
        var c = $('<button id="WMEChatResize-ShowUsers" class="WMEChatResize" style="position:absolute;Right:50px;color:#CC0000" title="Show Users" type="button"><</button>');
        c.click (WMEChatResize.Show);
        
        $("#chat .header").append(b);
        $("#chat .header").append(c);
        //document.getElementById('WMEChatResize-HideUsers').style.visibility="hidden";
        //document.getElementById('WMEChatResize-HideUsers').style.visibility="visible";
        
        document.getElementById('WMEChatResize-ShowUsers').style.visibility="hidden";
        //document.getElementById('WMEChatResize-ShowUsers').style.visibility="visible";   
        
        
        //tall / short chat
        var d = $('<button id="WMEChatResize-ShortChat" class="WMEChatResize" style="position:absolute;Right:80px;color:#CC0000" title="Short Chat" type="button">v</button>');
        d.click (WMEChatResize.ShortChat);
        var f = $('<button id="WMEChatResize-TallChat" class="WMEChatResize" style="position:absolute;Right:80px;color:#CC0000" title="Tall Chat" type="button">^</button>');
        f.click (WMEChatResize.TallChat);
        
        $("#chat .header").append(d);
        $("#chat .header").append(f);    
        
        document.getElementById('WMEChatResize-ShortChat').style.visibility="hidden";
        //document.getElementById('WMEChatResize-ShortChat').style.visibility="visible";
        
        //document.getElementById('WMEChatResize-TallChat').style.visibility="hidden";
        //document.getElementById('WMEChatResize-TallChat').style.visibility="visible";
        
    }
    
    WMEChatResize.Hide = function() {
        var divsToHide = document.getElementsByClassName("users");
        for(var i = 0; i < divsToHide.length; i++) {        
            divsToHide[i].style.visibility="hidden";
        }
        document.getElementById('chat').style.width="350px";  
        
        
        //alert(WMEChatResizeHeight);
        
        if(WMEChatResizeHeight == "short") { //short or tall
            document.getElementById('chat').style.height="353px";
        } else {
            //if(WMEChatResizeUsers  == "shown") {;  //shown  or hidden
            document.getElementById('chat').style.height="600px";
        }
        
        document.getElementById('WMEChatResize-HideUsers').style.visibility="hidden";
        //document.getElementById('WMEChatResize-HideUsers').style.visibility="visible";
        
        //document.getElementById('WMEChatResize-ShowUsers').style.visibility="hidden";
        document.getElementById('WMEChatResize-ShowUsers').style.visibility="visible";
        
        
        
        
        /* 
        var divsToHide = document.getElementsByClassName("chat");
        for(var i = 0; i < divsToHide.length; i++) {        
            divsToHide[i].style.width="318px";
            //497 * 353
        }
        //width: 275px !important;
        */
    }
    
    
    WMEChatResize.Show = function() {
         //alert(WMEChatResizeHeight);
        
        //alert("show");
        var divsToHide = document.getElementsByClassName("users");
        for(var i = 0; i < divsToHide.length; i++) {      
            divsToHide[i].style.visibility="visible";
        }
        
        document.getElementById('chat').style.width="497px";
        
        if(WMEChatResizeHeight == "short") { //short or tall
            document.getElementById('chat').style.height="353px";
        } else {
            //if(WMEChatResizeUsers  == "shown") {;  //shown  or hidden
            document.getElementById('chat').style.height="600px";
        }
        
        //document.getElementById('WMEChatResize-HideUsers').style.visibility="hidden";
        document.getElementById('WMEChatResize-HideUsers').style.visibility="visible";
        
        document.getElementById('WMEChatResize-ShowUsers').style.visibility="hidden";
        //document.getElementById('WMEChatResize-ShowUsers').style.visibility="visible";
        /*
        var divsToHide = document.getElementsByClassName("chat");
        for(var i = 0; i < divsToHide.length; i++) {        
            divsToHide[i].style.width="497px";
            //318 * 220
        }
        //width: 275px !important; 
        */
    }
    
    WMEChatResize.ShortChat = function() {
        WMEChatResizeHeight = "short";
        
        document.getElementById('WMEChatResize-ShortChat').style.visibility="hidden";
        //document.getElementById('WMEChatResize-ShortChat').style.visibility="visible";
        
        //document.getElementById('WMEChatResize-TallChat').style.visibility="hidden";
        document.getElementById('WMEChatResize-TallChat').style.visibility="visible";
        
        //change the chat heigh
        document.getElementById('chat').style.height="353px"; 
        
        //change chat-body
        var divsToModify = document.getElementsByClassName("chat-body");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="310px";
        }
        
        //message-list height
        var divsToModify = document.getElementsByClassName("message-list");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="300px";
            divsToModify[i].style.maxHeight="300px"
        }
        
        
        //change users height
        var divsToModify = document.getElementsByClassName("users");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="310px";
        }
        
        
        
    }
    
    
    WMEChatResize.TallChat = function() {
        WMEChatResizeHeight = "tall";
        
        //document.getElementById('WMEChatResize-ShortChat').style.visibility="hidden";
        document.getElementById('WMEChatResize-ShortChat').style.visibility="visible";
        
        document.getElementById('WMEChatResize-TallChat').style.visibility="hidden";
        //document.getElementById('WMEChatResize-TallChat').style.visibility="visible";
        
        
        //change the chat height
        document.getElementById('chat').style.height="600px"; 
        
        //change chat-body
        var divsToModify = document.getElementsByClassName("chat-body");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="557px";
        }
        
        //messages height
        var divsToModify = document.getElementsByClassName("messages");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="493px";
        }
        
        //message-list height
        var divsToModify = document.getElementsByClassName("message-list");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="493px";
            divsToModify[i].style.maxHeight="493px"
        }
        
        //change users height
        var divsToModify = document.getElementsByClassName("users");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="550px";
            divsToModify[i].style.maxHeight="550px";
            
        } 
        
        
        
    }
    
    
    
    
    
    WMEChatResize.startcode = function () {
        // Check if WME is loaded, if not, waiting a moment and checks again. if yes init WMEChatResize
        try {
            if ("undefined" != typeof unsafeWindow.W.model.chat.rooms._events.listeners.add[0].obj.userPresenters[unsafeWindow.Waze.model.loginManager.user.id] ) {
                console.log("WMEChatResize ready to jump :)");
                WMEChatResize.init()
            } else {
                setTimeout(WMEChatResize.startcode, 200);
            }
        } catch(err) {
            setTimeout(WMEChatResize.startcode, 200);
        }
    }
    ///setTimeout(WMEChatResize.startcode, 5000);
    WMEChatResize.startcode();
}

WMEChatResize_bootstrap();