Skip to content

Instantly share code, notes, and snippets.

@sonota88
Created January 29, 2011 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sonota88/801914 to your computer and use it in GitHub Desktop.
Save sonota88/801914 to your computer and use it in GitHub Desktop.
Greasemonkey script which detect patterns in html source.
// ==UserScript==
// @name detect-patterns
// @namespace anbt
// @include *
// ==/UserScript==
(function(){
if (window != unsafeWindow.top) { return; }
var patterns = [
"vevent"
, "vcalendar"
, "rel='license'"
, 'rel="license"'
, "hreview"
, "hentry"
, "creativecommons.org"
, "commons"
, "http://ogp.me/ns#"
];
var doc = document;
function createElement(parent, tagName, attributes, styles, innerHTML){
var e = doc.createElement(tagName);
if(attributes){
for(var key in attributes){
e.setAttribute(key, attributes[key]); }}
if(styles){
for(var key in styles){
e.style[key] = styles[key]; }}
if(innerHTML){
e.innerHTML = innerHTML; }
if(parent){
parent.appendChild(e); }
return e;
}
// javascript - How do I do OuterHTML in firefox? - Stack Overflow
// http://stackoverflow.com/questions/1700870/how-do-i-do-outerhtml-in-firefox
function outerHTML(n){
var div = doc.createElement('div'), h;
div.appendChild( n.cloneNode(true) );
h = div.innerHTML;
div = null;
return h;
}
////////////////////////////////
// Main
function detect(target, pattern){
if( ! target.match(pattern) ){
return;
}
createElement(
container
, "p"
, {}
, { background: "#c00"
, color: "#fff"
, padding: "1ex"
, margin: "1ex"
, zIndex: "1000"
, fontWeight: "bold"
}
, pattern.toString()
);
}
var container = createElement(
doc.body
, "div"
, {}
, { position: "fixed"
, right: "0", top: "0"
, color: "#fff"
, padding: "0"
, zIndex: "1000"
, background: "#fff"
, opacity: "0.8"
}
);
container.addEventListener(
"click"
, function(e){
e.target.style.display = "none";
}
, false
);
var html = doc.getElementsByTagName("html")[0];
var target = outerHTML(html);
for(var a=0, len=patterns.length; a<len; a++){
detect(target, patterns[a]);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment