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 if ( href.match( /\/\/(www|m)\.youtube\.com\/watch/ ) ||
70 href.match( /\/\/vimeo\.com\/(.+\/)?([\d]+)$/ ) ||
71 href.match( /\/\/(www\.)?dailymotion\.com\/video\/.+$/ ) ||
72 href.match( /\/\/soundcloud\.com\/.+$/ ) ||
73 href.match( /\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/ ) ||
74 href.match( /\/\/vine\.co\/v\/[^\/]+/ ) ) {
76 add( '_embeds[]', href );
79 metas = head.getElementsByTagName( 'meta' ) || [];
81 for ( var m = 0; m < metas.length; m++ ) {
87 q_name = q.getAttribute( 'name' ),
88 q_prop = q.getAttribute( 'property' ),
89 q_cont = q.getAttribute( 'content' );
93 add( '_meta[' + q_name + ']', q_cont );
94 } else if ( q_prop ) {
95 add( '_meta[' + q_prop + ']', q_cont );
100 links = head.getElementsByTagName( 'link' ) || [];
102 for ( var y = 0; y < links.length; y++ ) {
108 g_rel = g.getAttribute( 'rel' );
110 if ( g_rel === 'canonical' || g_rel === 'icon' || g_rel === 'shortlink' ) {
111 add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) );
115 if ( document.body.getElementsByClassName ) {
116 content = document.body.getElementsByClassName( 'hfeed' )[0];
119 content = document.getElementById( 'content' ) || content || document.body;
120 images = content.getElementsByTagName( 'img' ) || [];
122 for ( var n = 0; n < images.length; n++ ) {
129 // If we know the image width and/or height, check them now and drop the "uninteresting" images.
130 if ( img.src.indexOf( 'avatar' ) > -1 || img.className.indexOf( 'avatar' ) > -1 ||
131 ( img.width && img.width < 256 ) || ( img.height && img.height < 128 ) ) {
136 add( '_images[]', img.src );
139 iframes = document.body.getElementsByTagName( 'iframe' ) || [];
141 for ( var p = 0; p < iframes.length; p++ ) {
146 add( '_embeds[]', iframes[ p ].src );
149 if ( document.title ) {
150 add( 't', document.title );
154 add( 's', selection );
157 form.setAttribute( 'method', 'POST' );
158 form.setAttribute( 'action', pt_url );
159 form.setAttribute( 'target', target );
160 form.setAttribute( 'style', 'display: none;' );
162 window.open( 'about:blank', target, 'location,resizable,scrollbars,width=' + windowWidth + ',height=' + windowHeight );
164 document.body.appendChild( form );
166 } )( window, document, top.location.href, window.pt_url );