Skip to content

Instantly share code, notes, and snippets.

@clemos
Created October 6, 2011 10:13
Show Gist options
  • Save clemos/1267050 to your computer and use it in GitHub Desktop.
Save clemos/1267050 to your computer and use it in GitHub Desktop.
Embedr - a bookmarklet script to steal embeds from other sites
<a href="javascript:s=document.createElement('SCRIPT');s.type='text/javascript';s.src='https://raw.github.com/gist/1267050/c20d7312e80a152508fb04a91f09fae8248b138c/embedr.js?'+Math.random();document.getElementsByTagName('head')[0].appendChild(s);">Embedr</a>
<ul>
<li>Grab the link to your bookmarks bar up there</li>
<li>Click on 'Embedr' bookmark when you are on a page you want to get embeds from</li>
</ul>
var n = 0;
var docs = {};
function embedr( doc ){
n++;
//if( n > 10 ) return;
var l = doc.location;
if( docs[l.href] ){
return;
}else{
docs[l.href] = true;
}
var result = function( node ){
if( node.parentNode.nodeName == "OBJECT" ){
return;
}
//console.log("found");
//console.log( node );
var clone = node.cloneNode( true );
var html = clone.outerHTML;
var re = /src=(['"])([^"']*)(['"])/i;
var matches = html.match( re );
if( matches ){
var src = matches[2];
var newSrc = src;
if( src.indexOf("/") == 0 ){
// absolute url
newSrc = l.protocol + "//" + l.host + src;
}
html = html.replace( src , newSrc );
}
// add base...
if( node.parentNode.nodeName == "EMBED" ){
var b = /base=(['"])([^"']*)(['"])/i;
if( !html.match(b) ){
//console.log(l.href);
html = html.replace( new RegExp( "<(" + node.nodeName + ")" , "i" ) , "<$1 base=\"" + l.href + "\" " );
}
}
var txt = doc.createElement("textarea");
txt.innerHTML = html;
var st = "width:" + e.width + ( ( e.width.indexOf("%") > -1 ) ? "" : "px" )+";height:" + e.height + ( ( e.height.indexOf("%") > -1 ) ? "" : "px" ) ;
txt.setAttribute("style", st );
e.parentNode.appendChild(txt);
e.setAttribute('style', "display:none");
}
var embeds = doc.getElementsByTagName("embed");
var objects = doc.getElementsByTagName("object");
var iframes = doc.getElementsByTagName("iframe");
var links = doc.getElementsByTagName("a");
for(i=0;i<embeds.length;i++ ){
var e = embeds[i];
result(e);
}
for(i=0;i<objects.length;i++ ){
var e = objects[i];
result(e);
}
for(i=0;i<iframes.length;i++ ){
var e = iframes[i];
result( e );
/*try{
var e = iframes[i];
var d = e.contentDocument;
if( d != undefined ){
embedr( d );
}
}catch(ex){
}*/
//console.log(e.outerHTML);
//console.log(e.contentDocument.location.href)
}
var woRegexp = /window\.open\(([^)]*)\)/i;
for(i=0;i<links.length;i++){
var a = links[i];
var href = a.href;
var onclick = a.getAttribute("onclick");
var wo;
if( href && ( wo = woRegexp.exec(onclick) ) ){
var rawArgs = wo[1].split(",");
if( rawArgs[0] == "this.href" ){
var txt = doc.createElement("textarea");
txt.innerHTML = "<iframe width='100%' height='200' src='"+href+"' frameborder='no' scrollbars='no'></iframe>";
txt.setAttribute("style", "height:100px" );
a.parentNode.appendChild(txt);
}
}
}
}
embedr( document );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment