Last active
January 1, 2016 22:29
-
-
Save NickBeeuwsaert/8210243 to your computer and use it in GitHub Desktop.
Converts HTML comments into multiline comments for fun and yeah
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){var d=function(a,c){for(style in c)c.hasOwnProperty(style)&&(a.style[style.replace(/-(.)/g,function(a,c){return c.toUpperCase()})]=c[style])};(function(a){var c=document.createElement("div");d(c,{border:"1px solid hsl(240, 80%, 70%)",background:"hsla(240, 50%, 90%,0.5)",top:"0",left:"0",width:"0",height:"0",display:"none","pointer-events":"none",position:"absolute","z-index":"1000",transition:"width 0.5s, height 0.5s, top 0.5s, left 0.5s"});document.body.appendChild(c);var b=function(a){a= a.target;if(a!=c){for(var b=a,e=b.offsetLeft,f=b.offsetTop;b=b.offsetParent;)e+=b.offsetLeft,f+=b.offsetTop;d(c,{top:f+"px",left:e+"px",display:"block",width:a.offsetWidth-2+"px",height:a.offsetHeight-2+"px"})}},g=function(d){d.preventDefault();d.stopPropagation();a(d.target);document.removeEventListener("mouseover",b);document.removeEventListener("mousedown",g);c.parentNode.removeChild(c);return!1};document.addEventListener("mouseover",b);document.addEventListener("mousedown",g)})(function(a){var c= [];a=[].slice.apply(a.childNodes);for(var b=0;b<a.length;b++)1==a[b].nodeType&&a.push.apply(a,a[b].childNodes),8==a[b].nodeType&&c.push(a[b]);console.log(c);for(a=0;a<c.length;a++)b=document.createElement("span"),d(b,{color:"green","font-style":"red"}),b.appendChild(document.createTextNode("/*")),b.appendChild(document.createTextNode(c[a].data)),b.appendChild(document.createTextNode("*/")),c[a].parentNode.insertBefore(b,c[a])})})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var css = function(e, styles){ | |
for(style in styles){ | |
if(styles.hasOwnProperty(style)) | |
e.style[style.replace(/-(.)/g, function(a,b){return b.toUpperCase();})] = styles[style]; | |
} | |
}; | |
var pos = function(e){ | |
var pos = {"left": e.offsetLeft, "top": e.offsetTop}; | |
while(e = e.offsetParent){pos.left += e.offsetLeft; pos.top+=e.offsetTop;}; | |
return pos; | |
}; | |
var findAllNodesByType = function(parent, type){ | |
var found = []; | |
var nodes = [].slice.apply(parent.childNodes); | |
for(var i = 0; i < nodes.length; i++){ | |
if(nodes[i].nodeType == 1)//its an element | |
nodes.push.apply(nodes, nodes[i].childNodes); | |
if(nodes[i].nodeType == type) | |
found.push(nodes[i]); | |
} | |
return found; | |
}; | |
function selectElement(callback){ | |
var selectorDiv = document.createElement("div"); | |
css(selectorDiv, | |
{"border": "1px solid hsl(240, 80%, 70%)", | |
"background": "hsla(240, 50%, 90%,0.5)", | |
"top":"0", | |
"left":"0", | |
"width":"0", | |
"height": "0", | |
"display": "none", | |
"pointer-events":"none", | |
"position":"absolute", | |
"z-index": "1000", | |
"transition": "width 0.5s, height 0.5s, top 0.5s, left 0.5s"}); | |
document.body.appendChild(selectorDiv); | |
var mouseoverhandler = function(e){ | |
var target = e.target; | |
if(target == selectorDiv) return; | |
var p = pos(target); | |
css(selectorDiv, | |
{"top":p.top+"px", | |
"left":p.left+"px", | |
"display": "block", | |
"width":(target.offsetWidth-2)+"px", | |
"height":(target.offsetHeight-2)+"px"}); | |
}; | |
var mousedownhandler = function(e){ | |
e.preventDefault(); | |
e.stopPropagation(); | |
callback(e.target); | |
document.removeEventListener("mouseover", mouseoverhandler); | |
document.removeEventListener("mousedown", mousedownhandler); | |
selectorDiv.parentNode.removeChild(selectorDiv); | |
return false; | |
}; | |
document.addEventListener("mouseover", mouseoverhandler); | |
document.addEventListener("mousedown", mousedownhandler); | |
}; | |
selectElement(function(e){ | |
var comments = findAllNodesByType(e, 8); | |
console.log(comments); | |
for(var i = 0; i < comments.length; i++){ | |
var node = document.createElement("span"); | |
css(node, {"color":"green", | |
"font-style": "red"}); | |
node.appendChild(document.createTextNode("/*")); | |
node.appendChild(document.createTextNode(comments[i].data)); | |
node.appendChild(document.createTextNode("*/")); | |
comments[i].parentNode.insertBefore(node, comments[i]); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment