Create a gist now

Instantly share code, notes, and snippets.

@lachezar /x.js
Created Sep 24, 2009

An Ubiquity command to post the current browser's view in ScreenShootMe (http://dailyffs.com/shotme/)
CmdUtils.CreateCommand({
names: ["shotit"],
arguments: [{role: "object", nountype: noun_arb_text, label: "image format"}],
description: _("Publishes the current browser snapshot on the web and puts a link to it in the clipboard."),
homepage: "http://dailyffs.com/index.php/share-screen/",
author: {name: "Lucho Yankov"},
license: "GPL",
preview: _("Publishes the current browser snapshot on the web and puts a link to it in the clipboard."),
help: _("To specify the image format just put 'jpeg' or 'png' as command's parameter, if no format is specified and the image is smaller than 1200KB it will be saved as PNG, otherwise the JPEG format will be used."),
execute: function(args) {
var window = CmdUtils.getWindow();
var canvas = CmdUtils.getHiddenWindow().document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
canvas.mozOpaque = true;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.getContext("2d").drawWindow(window, window.scrollX, window.scrollY, window.innerWidth, window.innerWidth, "rgb(255,255,255)");
var data = null;
if (/^j(pe?g)?\s*$/i.test(args.object.text)) {
data = canvas.toDataURL("image/jpeg");
} else if (/^p(ng)?\s*$/i.test(args.object.text)) {
data = canvas.toDataURL("image/png");
} else {
data = canvas.toDataURL("image/png");
if (data.length > 1600*1024) data = canvas.toDataURL("image/jpeg");
}
displayMessage(_("Sending ") + parseInt(data.length/1024+1) + "KB...", this);
MAIN_URL = "http://dailyffs.com/shotme/";
jQuery.post(MAIN_URL, "image="+data, function(key) {
if (key == "ERROR") return;
var url = MAIN_URL + "?" + key;
Utils.clipboard.text = url;
displayMessage({text: url, onclick: function(){window.open(url);}}, this);
}
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment