// ==UserScript== // @name Chat Control Panel // @namespace kol.interface.unfinished // @description Adds a small panel to the top of the chat window with a list of macros, allowing you to fire chat macros with mouse actions. // @include https://*kingdomofloathing.com/lchat.php* // @include https://*kingdomofloathing.com/mchat.php* // @grant GM_getValue // @grant GM_setValue // @version 2.021 // @downloadURL https://update.greasyfork.icu/scripts/4068/Chat%20Control%20Panel.user.js // @updateURL https://update.greasyfork.icu/scripts/4068/Chat%20Control%20Panel.meta.js // ==/UserScript== //Version 2.021 // - trying to correct some spacing issues //Version 2.02 // - change to https //Version 2.01 // - add @grant, convert GM_log to console.log //Version 2.0 // - modified heavily to work with the new tabbed chat. This // changes the way the docking works, and there is now an // icon on the top right corner that toggles the appearance // of the panel instead of the bar on the right. //Version 1.0.3 // - more minor interface changes // - resizing is now granular, always shrinking or growing by // a full entry. // - the toggle bar now stays on the right of the chat control // panel so you can quickly toggle on/off without moving // the mouse. // - the control panel sticks to the top when moved very close // to the top of the chat pane. //Version 1.0.2 // - a minor aesthetic change, using partial transparency to // hide slightly less of the underlying chap panel text. //Version 1.0.1 // - fix mouse-over message for resize dragging //Version 1.0 // - changed the docking method, so you now click on a bar // on the right to dock it on the right // - added a pull bar next to the docking bar so you can // slide it anywhere in the chat pane // - the former docking tab (line) at the bottom is now a // pull tab so you can resize it to as many entries as // you want (or can fit). //Version 0.9 var height=unitHeight(5); var ccmds; var playername; var dims; function rollHandler() { var cp = document.getElementById('chatcp'); var cph = document.getElementById('chatcp_handle'); if (cp && cph) { var v = cp.getAttribute('style'); var w = cph.getAttribute('style'); if (v.match(/display\s*:\s*none/)) { cp.setAttribute('style',removeStyle(v,'display')); cph.setAttribute('style',removeStyle(w,'display')); saveDock(false); } else { cp.setAttribute('style','display:none;'+v); cph.setAttribute('style','display:none;'+w); saveDock(true); } } } function replaceOrAddStyle(s,a,v) { var r = new RegExp(a+'\\s*:','i'); var sa = s.split(';'); for (var i=0;i0)?'border-top:1px solid black;':'')+'background-image:-moz-linear-gradient(center top , white 50%, transparent 100%);z-index:7;font-size:12px;position:absolute;font-family:arial;left:2px;top:'+p+'px;'); cp.setAttribute('id','chatcp'); var t = document.createElement('table'); t.setAttribute('cellspacing','0'); for(var i=0;unitHeight(i)Name // in compact mode it's Name // so have to handle this, and also can use it to tell // whether it's in compact mode or not. var fullmode = true; while (username && username.nodeType == 1) { username = username.firstChild; fullmode = false; } if (!username) return playername; username = username.nodeValue; if (!username) return playername; username = username.toLowerCase(); playername = username; return username; } } } // code to drag the panel around var d; function dragStart(event, id) { var cp = document.getElementById('chatcp'); var cph = document.getElementById('chatcp_handle'); if (cp && cph) { var v = getStyleAttr(cp.getAttribute('style'),'width'); if (v>=0) { if (event.clientX=(dims.headerw? (dims.headert+16) : (dims.top+16)) && (d.elStartTop + y - d.cursorStartY)<(dims.height+(dims.headerw? (dims.headert+16) : (dims.top+16)))-height) { if ((d.elStartTop + y - d.cursorStartY)<=3) y = d.cursorStartY - d.elStartTop; d.cp.style.top = (d.elStartTop + y - d.cursorStartY) + "px"; if ((d.elStartTop + y - d.cursorStartY)>0) d.cp.setAttribute('style',setTopBorder(d.cp.getAttribute('style'))); else d.cp.setAttribute('style',removeTopBorder(d.cp.getAttribute('style'))); d.cph.style.top = (d.elStartTop + y - d.cursorStartY + d.baseH - 3) + "px"; savePos(d.elStartTop + y - d.cursorStartY); } event.preventDefault(); } // terminate dragging to position the panel function dragStop(event) { // Stop capturing mousemove and mouseup events. document.removeEventListener("mousemove", dragGo, true); document.removeEventListener("mouseup", dragStop, true); d = null; } // code to resize the panel function dragStartSize(event, id) { var cp = document.getElementById('chatcp'); var cph = document.getElementById('chatcp_handle'); if (cp && cph) { d = new Object(); d.cp = cp; d.cph = cph; var y = event.clientY + window.scrollY; d.baseH = getStyleAttr(cp.getAttribute('style'),'height'); d.baseO = getStyleAttr(cph.getAttribute('style'),'top'); // Save starting positions of cursor and element. d.cursorStartY = y; d.elStartLeft = parseInt(cp.style.left, 10); d.elStartTop = parseInt(cp.style.top, 10); if (isNaN(d.elStartLeft)) d.elStartLeft = 2; if (isNaN(d.elStartTop)) d.elStartTop = 2; document.addEventListener("mousemove", dragGoSize, true); document.addEventListener("mouseup", dragStopSize, true); event.preventDefault(); } } // create cp index i in table t with width w function newEntry(i,w,t) { var tr = document.createElement('tr'); tr.setAttribute('id','chatcp_index'+i); var td = document.createElement('td'); var i1 = document.createElement('input'); i1.setAttribute('type','button'); //i1.setAttribute('value','>'); //var arrow = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAMCAYAAACEJVa/AAAAmklEQVQokaXSPQ5BURCG4YcNiGhUGpah0CpFQyOswUpElCLR24VFiJ8FqCQ6Ea7CkdwILseXvN3Mm5nJkJ0mFih8UftRcsIO9XdFuQyghBUSDJB/lky+YIwZrkE0RTEt2fzAOqyVYItyjCTNMcga/0guWKIm2GKYpW/SyaCLNkbhsAf0RaSFM/aoxAiG7uPPY5ofqaLnxYM9cgOSr1GycHbzaQAAAABJRU5ErkJggg=='; //i1.setAttribute('style','font-size:9px;width:22px;'); i1.setAttribute('style','background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAMCAYAAACEJVa/AAAAmklEQVQokaXSPQ5BURCG4YcNiGhUGpah0CpFQyOswUpElCLR24VFiJ8FqCQ6Ea7CkdwILseXvN3Mm5nJkJ0mFih8UftRcsIO9XdFuQyghBUSDJB/lky+YIwZrkE0RTEt2fzAOqyVYItyjCTNMcga/0guWKIm2GKYpW/SyaCLNkbhsAf0RaSFM/aoxAiG7uPPY5ofqaLnxYM9cgOSr1GycHbzaQAAAABJRU5ErkJggg==");background-repeat: no-repeat;background-position: center;'); i1.setAttribute('cmdidx',i); i1.addEventListener('mouseup',bHandler,false); var i2 = document.createElement('input'); i2.setAttribute('type','text'); i2.setAttribute('width','128'); i2.setAttribute('value',((i>=ccmds.length)?'':ccmds[i])); i2.setAttribute('class','chatcp_text'); i2.setAttribute('style','font-size:9px;width:'+(w-22)+'px;height:13px;'); i2.setAttribute('cmdidx',i); i2.addEventListener('keyup',tHandler,true); i2.addEventListener('change',tHandler,true); td.appendChild(i1); td.appendChild(i2); tr.appendChild(td); t.appendChild(tr); } // update the interior of the panel during resizing function updateCPSize(h) { var bars = document.getElementsByClassName('chatcpbar'); for (var i=0;iunitHeight(1) && newh<(dims.height+(dims.headerw? (dims.headert+16) : (dims.top+16)))) { newh = unitHeight(heightUnit(newh)); delta = newh - d.baseH; d.cp.setAttribute('style',replaceOrAddStyle(d.cp.getAttribute('style'),'height',newh+'px')); d.cph.setAttribute('style',replaceOrAddStyle(d.cph.getAttribute('style'),'top',(d.baseO+delta)+'px')); updateCPSize(newh); } } event.preventDefault(); } // terminate dragging to resize the panel function dragStopSize(event) { // Stop capturing mousemove and mouseup events. document.removeEventListener("mousemove", dragGoSize, true); document.removeEventListener("mouseup", dragStopSize, true); d = null; } function getMaxDimensions() { var chats = document.getElementsByClassName('chatdisplay'); for (var i=0;i