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.41
// @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.41 - very minor 4 pixel changes to teh n ormal chat height
 * 0.0.4 - removed the open space on the right of the chat
 * 0.0.3 - few div size corrections
 * 0.0.2 - made the buttons not Interfere with each other
 * 0.0.1 - initial version
 */


var WMEChatResizeVersion = "0.0.41";

var WMEChatResizeVersionUpdateNotes = "WME Chat Resize has been updated to " + WMEChatResizeVersion;
WMEChatResizeVersionUpdateNotes = WMEChatResizeVersionUpdateNotes + "\r\n" + "This script adds buttons to the chat title bar and removes the space on the right of the chat.";
WMEChatResizeVersionUpdateNotes = WMEChatResizeVersionUpdateNotes + "\r\n" + "The buttons will let you hide or show the users list";
WMEChatResizeVersionUpdateNotes = WMEChatResizeVersionUpdateNotes + " " + "and will let you make the chat tall or normal heights.";
WMEChatResizeVersionUpdateNotes = WMEChatResizeVersionUpdateNotes + "\n" + "As usual let me know if there are any issues -RickZabel";

//alert the user in  WMEChatResize version updates
if (localStorage.getItem('WMEChatResizeVersion') == WMEChatResizeVersion) {
    console.log("UR Comments Version " + WMEChatResizeVersion);
} else {
    alert(WMEChatResizeVersionUpdateNotes);
    localStorage.setItem('WMEChatResizeVersion', WMEChatResizeVersion);
}



//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




/*
org chat
chat-overlay right 20px
chat-overlay bottom 24px
chat px 357px
chat-body 314px
messages px 314px
message-list 220px
users 280

NormalChat
chat 353px
chat-body 310px
messages 314
message-list 250px
users 310px

TallChat
chat height 600px
chat-body557px
messages height493px
message-list height493px
Users height550px
*/















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() {
        //add the buttons to the chat title bar
        //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-ShowUsers').style.visibility="hidden";
        
        //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";
        
        //move the chat all the way to the right 
        document.getElementById('chat-overlay').style.right="0px";
        
        
    }
    
    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";  
        
        if(WMEChatResizeHeight == "short") { //short or tall
            document.getElementById('chat').style.height="353px";
        } else {
            document.getElementById('chat').style.height="600px";
        }
        
        document.getElementById('WMEChatResize-HideUsers').style.visibility="hidden";
        document.getElementById('WMEChatResize-ShowUsers').style.visibility="visible";
        
    }
    
    
    WMEChatResize.Show = function() {
        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 {
            document.getElementById('chat').style.height="600px";
        }
        
        document.getElementById('WMEChatResize-HideUsers').style.visibility="visible";
        document.getElementById('WMEChatResize-ShowUsers').style.visibility="hidden";
        
    }
    
    WMEChatResize.ShortChat = function() {
        WMEChatResizeHeight = "short";
        
        document.getElementById('WMEChatResize-ShortChat').style.visibility="hidden";
        document.getElementById('WMEChatResize-TallChat').style.visibility="visible";
        
        //change the chat height
        document.getElementById('chat').style.height="357px"; 
        
        //change chat-body
        var divsToModify = document.getElementsByClassName("chat-body");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="314px";
        }
        //messages height
        var divsToModify = document.getElementsByClassName("messages");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="314px";
        }
        
        //message-list height
        var divsToModify = document.getElementsByClassName("message-list");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="250px";
            divsToModify[i].style.maxHeight="250px"
        }
        
        //change users height
        var divsToModify = document.getElementsByClassName("users");
        for(var i = 0; i < divsToModify.length; i++) {        
            divsToModify[i].style.height="310px";
        }
        
        document.getElementById('chat-overlay').style.bottom="24px";
        
    }
    
    
    WMEChatResize.TallChat = function() {
        WMEChatResizeHeight = "tall";
        
        document.getElementById('WMEChatResize-ShortChat').style.visibility="visible";
        
        document.getElementById('WMEChatResize-TallChat').style.visibility="hidden";
        
        //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";
        } 
        
        document.getElementById('chat-overlay').style.bottom="24px";
        
    }
    
    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();