-
-
Save schlos/983f956ba1b4ec0400dd746d8e1b75ad to your computer and use it in GitHub Desktop.
Greasemonkey script which detect patterns in html source.
This file contains hidden or 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
// ==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