// ==UserScript== // @name MsgPreview // @author Joshua Heyer // @namespace http://shog9.com/greasemonkey/scripts/ // @description Show preview "tooltips" for messages // @version 0.1.0 // @include http://*.codeproject.com/* // @include http://*.codetools.com/* // @include http://*.thecodeproject.com/* // @include http://codeproject.com/* // @include http://codetools.com/* // @include http://thecodeproject.com/* // ==/UserScript== var pane = null; var msgHeaders = XPathNodes(document, "//tr[substring-before(@id, '_h0')]", false); for (var i=0; i= 1.0 ) window.clearInterval(ani); if ( pane ) pane.style.MozOpacity = opacity; }, 100); } function HideMessagePreview(e) { if ( (!e || !isDescendant(e.relatedTarget, this)) && pane) { pane.parentNode.removeChild(pane); pane = null; } } function CreateMessagePreview(header) { var pane = document.createElement("DIV"); pane.style.left = "0px"; pane.style.top = "0px"; pane.style.width = Math.min(document.body.clientWidth, header.offsetWidth) + "px"; pane.style.border = "1px solid orange"; pane.style.position = "absolute"; pane.style.zIndex = 2; pane.style.textAlign = "left"; pane.style.padding = "2px"; pane.style.MozOpacity = 0; pane.innerHTML = '
' +GetMessageText(header.id.substring(0,header.id.length-3)) +'
' +'
' +'
'; document.body.appendChild(pane); var left = getRealPos(header, "Left") - (pane.offsetWidth-header.offsetWidth)/2; var top = getRealPos(header, "Top") + header.offsetHeight; var minLeft = document.body.scrollLeft; var minTop = document.body.scrollTop; var maxLeft = minLeft + document.body.clientWidth - pane.offsetWidth; var maxTop = minTop + document.body.clientHeight - pane.offsetHeight; if ( left < minLeft ) left = minLeft; if ( left > maxLeft ) left = maxLeft; if ( top < minTop ) top = minTop; if ( top > maxTop ) top = maxTop; pane.style.left = left + "px"; pane.style.top = top + "px"; return pane; } function GetMessageText(id) { var content = XPathNode(document, "//tr[@id='"+id+"_h1']/td/table/tbody/tr/td[2]/table/tbody/tr/td/table/tbody/tr/td"); var range = document.createRange(); range.selectNodeContents(content); var selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); var text = selection.toString(); selection.removeAllRanges(); return text; } function isDescendant(el, par) { if ( !el || !par ) return false; if ( el == par ) return true; return isDescendant(el.parentNode, par); } function XPathNode(el, xpath) { var result = document.evaluate(xpath, el, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); return (result && result.singleNodeValue ? result.singleNodeValue : null); } function XPathNodes(el, xpath, ordered) { return document.evaluate(xpath, el, null, (ordered ? XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE : XPathResult.ORDERED_NODE_SNAPSHOT_TYPE), null); } function getRealPos(i,which) { iPos = 0 while (i!=null) { iPos += i["offset" + which]; i = i.offsetParent; } return iPos }