Skip to content

Instantly share code, notes, and snippets.

@rbriank rbriank/gist:10371
Created Sep 12, 2008

Embed
What would you like to do?
CmdUtils.CreateCommand({
name: "comments",
author: {name: "Brian Kierstead", email: "briankierstead@gmail.com"},
description: "Reveal comments in the code.",
execute:function() {
doc = context.focusedWindow.document
if(!doc)
return;
ss = addStyleSheet(doc);
if(ss)
addStyles(ss);
bodyNodes = doc.body.childNodes;
for(var i=0; i < bodyNodes.length; i++){
if(bodyNodes[i].nodeType==8){
var div = context.focusedWindow.document.createElement( "div" );
div.innerHTML = '<a class="info" href="#" onclick="javascript:return false;">'
+ '<image src="http://en.wikipedia.org/skins-1.5/monobook/external.png" border="0" />'
+ '<span>' + bodyNodes[i].nodeValue + '</span></a>';
try{
bodyNodes[i].parentNode.removeChild(bodyNodes[i]);
bodyNodes[i].parentNode.insertBefore(div, bodyNodes[i]);
}
catch(err){
// this will break if node insertion is not allowed the parent
// but what to do?
}
}
}
}
});
function addStyleSheet(doc){
// add one if there are none
if(!doc.styleSheets[0]){
ss = doc.createElement("style");
ss.type="text/css";
ss.media="all";
doc.getElementsByTagName("head")[0].appendChild(ss);
}
return doc.styleSheets[0];
}
function addStyles(ss)
{
// add the rules
ss.insertRule('a.info{'
+ 'position:relative;'
+ 'z-index:24;'
+ 'color:#000;'
+ 'font-weight: normal;}',0);
ss.insertRule('*+html a.info{'
+ 'padding-right: 3px;}', 0);
ss.insertRule('a.info:hover{z-index:25;}',0);
ss.insertRule('a.info span{display: none}',0);
ss.insertRule('a.info:hover span{'
+ 'display: block;'
+ 'font-size: 11px;'
+ 'position: absolute;'
+ 'font-weight: normal;'
+ 'top:2em;'
+ 'right:-1em;'
+ 'width: 23em;'
+ 'padding: 5px;'
+ 'max-width: 23em;'
+ 'word-wrap: break-word;'
+ 'border:1px solid #d5d7ca;'
+ 'background-color:#FCFCFA;'
+ 'color:#326175;'
+ 'text-align: left;'
+ 'z-index:25;'
+ 'white-space: pre-wrap;}', 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.