Skip to content

Instantly share code, notes, and snippets.

@marsam
Last active July 25, 2016 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marsam/82c68c5a42e6f4c97927 to your computer and use it in GitHub Desktop.
Save marsam/82c68c5a42e6f4c97927 to your computer and use it in GitHub Desktop.
tweetshot --- take screenshot to tweets
#!/usr/bin/env phantomjs
/*global phantom: false */
'use strict';
var system = require('system')
, args = system.args
, page = require('webpage').create()
;
var tweetshot = function(url, output, width, height) {
width = width || 1280;
height = height || 1024;
output = output || 'tweetshot.' + width + 'x' + height + '.png';
page.viewportSize = { width: width, height: height };
page.open(url, function(status) {
if (status !== 'success') {
console.log('Unable to load url: ' + url);
phantom.exit();
}
window.setTimeout(function() {
page.clipRect = page.evaluate(function() {
var tweet = document.querySelector('[role="main"]');
return tweet === null? {} : tweet.getBoundingClientRect();
});
console.log('Creating file: ' + output);
page.render(output);
phantom.exit();
}, 200);
});
};
if (args.length === 1) {
console.log('Usage: ' + args[0] + ' URL [output] [width] [height]');
phantom.exit();
}
tweetshot(args[1], args[2], args[3], args[4]);
// Local Variables:
// mode: js
// End:
@nyroDev
Copy link

nyroDev commented Jul 25, 2016

In the clipRect, I added this to remove replies:

replies = document.querySelector('[data-component-context="replies"]');
if (replies) {
    replies.parentNode.removeChild(replies);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment