1 ( function( window, document, href, pt_url ) {
2 var encURI = window.encodeURIComponent,
3 form = document.createElement( 'form' ),
4 head = document.getElementsByTagName( 'head' )[0],
5 target = '_press_this_app',
7 windowWidth, windowHeight, selection,
8 metas, links, content, images, iframes, img;
14 if ( href.match( /^https?:/ ) ) {
15 pt_url += '&u=' + encURI( href );
16 if ( href.match( /^https:/ ) && pt_url.match( /^http:/ ) ) {
20 top.location.href = pt_url;
24 if ( window.getSelection ) {
25 selection = window.getSelection() + '';
26 } else if ( document.getSelection ) {
27 selection = document.getSelection() + '';
28 } else if ( document.selection ) {
29 selection = document.selection.createRange().text || '';
32 pt_url += '&buster=' + ( new Date().getTime() );
35 if ( document.title ) {
36 pt_url += '&t=' + encURI( document.title.substr( 0, 256 ) );
40 pt_url += '&s=' + encURI( selection.substr( 0, 512 ) );
44 windowWidth = window.outerWidth || document.documentElement.clientWidth || 600;
45 windowHeight = window.outerHeight || document.documentElement.clientHeight || 700;
47 windowWidth = ( windowWidth < 800 || windowWidth > 5000 ) ? 600 : ( windowWidth * 0.7 );
48 windowHeight = ( windowHeight < 800 || windowHeight > 3000 ) ? 700 : ( windowHeight * 0.9 );
51 window.open( pt_url, target, 'location,resizable,scrollbars,width=' + windowWidth + ',height=' + windowHeight );
55 function add( name, value ) {
56 if ( typeof value === 'undefined' ) {
60 var input = document.createElement( 'input' );
64 input.type = 'hidden';
66 form.appendChild( input );
69 metas = head.getElementsByTagName( 'meta' ) || [];
71 for ( var m = 0; m < metas.length; m++ ) {
77 q_name = q.getAttribute( 'name' ),
78 q_prop = q.getAttribute( 'property' ),
79 q_cont = q.getAttribute( 'content' );
83 add( '_meta[' + q_name + ']', q_cont );
84 } else if ( q_prop ) {
85 add( '_meta[' + q_prop + ']', q_cont );
90 links = head.getElementsByTagName( 'link' ) || [];
92 for ( var y = 0; y < links.length; y++ ) {
98 g_rel = g.getAttribute( 'rel' );
100 if ( g_rel === 'canonical' || g_rel === 'icon' || g_rel === 'shortlink' ) {
101 add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) );
105 if ( document.body.getElementsByClassName ) {
106 content = document.body.getElementsByClassName( 'hfeed' )[0];
109 content = document.getElementById( 'content' ) || content || document.body;
110 images = content.getElementsByTagName( 'img' ) || [];
112 for ( var n = 0; n < images.length; n++ ) {
119 // If we know the image width and/or height, check them now and drop the "uninteresting" images.
120 if ( img.src.indexOf( 'avatar' ) > -1 || img.className.indexOf( 'avatar' ) > -1 ||
121 ( img.width && img.width < 256 ) || ( img.height && img.height < 128 ) ) {
126 add( '_images[]', img.src );
129 iframes = document.body.getElementsByTagName( 'iframe' ) || [];
131 for ( var p = 0; p < iframes.length; p++ ) {
136 add( '_embeds[]', iframes[ p ].src );
139 if ( document.title ) {
140 add( 't', document.title );
144 add( 's', selection );
147 form.setAttribute( 'method', 'POST' );
148 form.setAttribute( 'action', pt_url );
149 form.setAttribute( 'target', target );
150 form.setAttribute( 'style', 'display: none;' );
152 window.open( 'about:blank', target, 'location,resizable,scrollbars,width=' + windowWidth + ',height=' + windowHeight );
154 document.body.appendChild( form );
156 } )( window, document, top.location.href, window.pt_url );