// ==UserScript== // @name Chat Resizer // @namespace tag://kongregate // @description Automatically resizes the chat to a specified value. // @author Ventero // @include http://www.kongregate.com/games/* // @date 15.09.2012 // require http://kong.ventero.de/updates/70040.js // @version 1.2.4 // @license MIT license // @downloadURL https://update.greasyfork.icu/scripts/17716/Chat%20Resizer.user.js // @updateURL https://update.greasyfork.icu/scripts/17716/Chat%20Resizer.meta.js // ==/UserScript== // Written by Ventero (http://www.kongregate.com/accounts/Ventero) 05/12/09 // Copyright (c) 2010-2012 Ventero, licensed under MIT/X11 license // http://www.opensource.org/licenses/mit-license.php // Default dimensions of chat var defaultWidth = 500; var defaultHeight = 600; // How much space should be left on the left/right border var spaceLeft = 200; // Set to false if game should line up with bottom of chat, not center var center = true; // Sets the height of the user list var userListHeight = 100; var dom = (typeof unsafeWindow === "undefined"?window:unsafeWindow); if(!document.getElementById("game")) return; if(!dom.holodeck){ var s = document.createElement("div"); s.setAttribute("onclick","return window"); dom = s.onclick(); } function d(c){ return document.getElementById(c); } function c(c){ return document.getElementsByClassName(c); } function $(c){ return document.querySelector(c); } function $A(c){ return [].slice.call(c); } function setWidth(width){ window._currentChatWidth = width; var gameWidth = parseInt(d("game").style.width, 10); d("maingame").style.width = (gameWidth + 3 + width) + "px"; d("maingamecontent").style.width = (gameWidth + 3 + width) + "px"; d("flashframecontent").style.width = (gameWidth + 3 + width) + "px"; d("chat_container").style.width = width + "px"; d('chat_window_spinner').style.right = width/2 - 38 + "px"; if(d('high_scores_spinner')) d('high_scores_spinner').style.right = width/2 - 38 + "px"; var ui = d("kong_game_ui"); z = ui.childNodes for(i=0;i height - 200){ l.activeDialogue().kongBotMessage("Userlist height is too large. Setting it to 100px"); listHeight = 100; } window.setTimeout(function(){GM_setValue("kong_resize_"+location.pathname, width+"/"+height+"/"+listHeight)}, 0); l.activeDialogue().kongBotMessage("Resizing chat to " + width + "px/" + height + "px/" + listHeight + "px"); setWidth(width); setHeight(height, listHeight, window._currentGameCentered); return false; }); holodeck.addChatCommand("defaultsize", function(l, n){ var m = n.match(/^\/\S+\s+(\S+)/); var o = n.match(/^\/\S+\s+(\d+)\s+(\d+)(?:\s+(\d+))?/) if(m && m[1] == "reset"){ l.activeDialogue().kongBotMessage("Resetting default size to 500/600/100"); window.setTimeout(function(){GM_deleteValue("kong_resize_default")}, 0); return false; } else if(m && m[1] == "show"){ l.activeDialogue().kongBotMessage("Current chat size: width: " + window._defaultChatWidth + "px, height: " + window._defaultChatHeight + "px, userlist-height: " + window._defaultUserlistHeight + "px."); return false; } else if(!o){ l.activeDialogue().kongBotMessage("Syntax /defaultsize width height userlist-height. userlist-height is optional. Example: /defaultsize 500 500 100"); } var width = parseInt(o[1], 10); var height = parseInt(o[2], 10); var listHeight = parseInt(o[3]||100, 10); if(width < 300){ l.activeDialogue().kongBotMessage("Minimum width is 300. Setting width to 300px."); width = 300; } if(listHeight > height){ l.activeDialogue().kongBotMessage("Userlist height is too large. Setting it to 100px"); listHeight = 100; } window.setTimeout(function(){GM_setValue("kong_resize_default", width+"/"+height+"/"+listHeight)}, 0); l.activeDialogue().kongBotMessage("Set default values to width: " + width + "px, height: " + height + "px, userlist-height: " + listHeight + "px."); return false; }); holodeck.addChatCommand("centergame", function(l, n){ var center = !window._currentGameCentered; if(center){ l.activeDialogue().kongBotMessage("Now centering the game"); } else { l.activeDialogue().kongBotMessage("Now aligning the game to the chat's bottom"); } window.setTimeout(function(){GM_setValue("kong_resize_center", center?1:0)}, 0); centerGame(center); return false; }); } var getString = "", centerVal = -1, defaults = ""; getString = GM_getValue("kong_resize_"+location.pathname, ""); centerVal = GM_getValue("kong_resize_center", -1); defaults = GM_getValue("kong_resize_default", ""); if(defaults){ var splitArr = defaults.split("/"); defaultWidth = parseInt(splitArr[0], 10)||defaultWidth; defaultHeight = parseInt(splitArr[1], 10)||defaultHeight; userListHeight = parseInt(splitArr[2], 10)||userListHeight; } window._defaultChatWidth = defaultWidth; window._defaultChatHeight = defaultHeight; window._defaultUserlistHeight = userListHeight; var x = defaultWidth, y = defaultHeight, l = userListHeight, cg = center, override = false; if(centerVal != -1){ cg = (centerVal == 1); } if(getString){ var splitArr = getString.split("/"); x = parseInt(splitArr[0], 10)||defaultWidth; y = parseInt(splitArr[1], 10)||defaultHeight; l = parseInt(splitArr[2], 10)||userListHeight; override = true; } var gameWidth = parseInt(d('game').style.width, 10); var gameHeight = parseInt(d('game').style.height, 10); if(x > minimumWidth){ if(override || gameWidth + x < screen.width - spaceLeft){ // enough place to resize to specified width setWidth(x); }else{ // resize as far as possible var chatWidth = screen.width - gameWidth - spaceLeft; if(chatWidth > minimumWidth) setWidth(chatWidth); } } if(y > minimumHeight && y > gameHeight){ setHeight(y, l, cg); } else { setHeight(gameHeight, l, cg); } } initalize_chat_resize();