// ==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