var storageManager;
var storage;
function showCannotCaptureWarning(node) {
hideSpinner(node);
openDialog("cannotCaptureWarningTemplate").then(function(response) {
if (response == "ok") {
// nothing
}
});
showError("Error: " + errorResponse);
}
function showSpinner(node) {
$(node).find("iron-icon").after(" {
window.close();
}).catch(function() {
showCannotCaptureWarning(that);
});
sendGA('popup', 'selectedArea');
});
$("#visibleArea, #justInstalledGrabVisibleArea").click(function() {
var that = this;
showSpinner(that);
grabVisiblePart().then(() => {
window.close();
}).catch(function() {
showCannotCaptureWarning(that);
});
sendGA('popup', 'visibleArea');
});
$("#entirePage").click(function() {
var that = this;
showSpinner(that);
grabEntirePage().then(() => {
window.close();
}).catch(function(errorResponse) {
hideSpinner(that);
openDialog("entirePageIssueDialogTemplate").then(function(response) {
if (response == "ok") {
// nothing
} else {
$("#visibleArea").click();
}
});
showError("Error: " + errorResponse);
});
sendGA('popup', 'entirePage');
});
$("#entireScreen").click(function() {
$(".instructions").slideUp();
if (navigator.userAgent.toLowerCase().indexOf('mac') != -1) {
openDialog("entireScreenMacInstructionsTemplate").then(function(response) {});
} else if (navigator.userAgent.toLowerCase().indexOf('cros') != -1) {
openDialog("entireScreenCrOSInstructionsTemplate").then(function(response) {});
} else {
var $dialog = initTemplate("entireScreenWindowsInstructionsTemplate");
openDialog($dialog).then(function(response) {});
}
sendGA('popup', 'entireScreen');
});
$("#openFile").click(function() {
sendGA('popup', 'openFile');
chrome.tabs.create({url:"openFile.html"});
window.close();
});
$("#openAreaFromClipboard").click(function() {
sendGA('popup', 'openAreaFromClipboard');
openFromClipboard(true).catch(function(response) {
if (response.permissionNotGranted) {
showError("You must grant this minimal permission if you want this extension to grab your image from the clipboard!");
}
});
});
$("#openFromClipboard").click(function() {
sendGA('popup', 'openFromClipboard');
openFromClipboard().catch(function(response) {
if (response.permissionNotGranted) {
showError("You must grant this minimal permission if you want this extension to grab your image from the clipboard!");
}
});
});
// Delay some
setTimeout(function() {
var $optionsMenu = initTemplate("optionsMenuItemsTemplate");
initMessages("#options-menu *");
$(".contribute").click(function() {
chrome.tabs.create({url: 'donate.html?fromPopup'});
window.close();
});
$(".discoverMyApps").click(function() {
chrome.tabs.create({url:"https://jasonsavard.com?ref=SSOptionsMenu"});
window.close();
});
$(".feedback").click(function() {
chrome.tabs.create({url:"https://jasonsavard.com/forum/categories/explain-and-send-screenshots?ref=SSOptionsMenu"});
window.close();
});
$(".changelog").click(function() {
chrome.tabs.create({url:"https://jasonsavard.com/wiki/Explain_and_Send_Screenshots_changelog?ref=SSOptionsMenu"});
window.close();
});
$(".options").click(function() {
chrome.tabs.create({url:"options.html"});
window.close();
});
$(".aboutMe").click(function() {
chrome.tabs.create({url:"https://jasonsavard.com/about?ref=SSOptionsMenu"});
window.close();
});
$(".help").click(function() {
chrome.tabs.create({url:"https://jasonsavard.com/wiki/Explain_and_Send_Screenshots"});
window.close();
});
}, 400);
$(".close").click(function() {
window.close();
});
function processClipboardItem(item) {
return new Promise(function(resolve, reject) {
if (item.kind == "file") {
var fileName = item.name;
var fileType = item.type;
console.log("mimetype", JSON.stringify(item)); // will give you the mime types
var blob = item.getAsFile();
var reader = new FileReader();
reader.onload = function(event) {
//uploadImage(fileName, fileType, event.target.result, $contentEditable);
resolve({fileName:fileName, fileType:fileType, dataUrl:event.target.result});
};
reader.readAsDataURL(blob);
} else if (item.kind == "string") {
// when i paste text, type=text/plain
// when i copy/paste from paint it's a file with type=image/png
// when i right click and "Copy image" type=text/html
if (item.type == "text/html") {
item.getAsString(function(s) {
// returns this:
console.log("getasstring:", item, s);
var $div = $("");
$div.append(s);
var dataUrl = $div.find("img").attr("src");
if (dataUrl && dataUrl.indexOf("data:") == 0) {
console.log("data: found");
resolve({dataUrl:dataUrl});
} else {
resolve({couldNotProcessReason:"Can't process url: " + s});
}
});
} else if (item.type == "text/plain") {
item.getAsString(function(s) {
if (s.indexOf("http") == 0) {
resolve({urlWasCopied:true, url:s});
} else {
resolve({couldNotProcessReason:"Could not parse this text/plain: " + s});
}
});
} else {
resolve({couldNotProcessReason:"Could not determine item.type: " + item.type});
}
} else {
resolve({couldNotProcessReason:"Could not determine item.kind: " + item.kind});
}
});
}
$("body").on("paste", function(e) {
console.log("paste");
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
var promises = [];
for (var a=0; a {
bg.screenShotData = promiseResponse.dataUrl;
chrome.tabs.create({url: "snapshot.html"});
});
} else {
openEditor(promiseResponse.dataUrl);
}
success = true;
return true;
}
});
if (!success && !urlWasCopied) {
showError("No images in clipboard!");
}
}).catch(function(errorResponse) {
showError(errorResponse);
});
});
});