1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Clipper: Take zoom into account when clipping screenshot

This commit is contained in:
Laurent Cozic 2018-06-01 16:12:49 +01:00
parent b3ca30b8b6
commit d8ad42b04a
2 changed files with 33 additions and 12 deletions

View File

@ -32,6 +32,16 @@ async function browserCaptureVisibleTabs(windowId, options) {
});
}
async function browserGetZoom(tabId) {
if (browserSupportsPromises_) return browser_.tabs.getZoom(tabId);
return new Promise((resolve, reject) => {
browser_.tabs.getZoom(tabId, (zoom) => {
resolve(zoom);
});
});
}
browser_.runtime.onInstalled.addListener(function(details) {
if (details && details.temporary) {
// In Firefox - https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/onInstalled
@ -51,20 +61,29 @@ browser_.runtime.onInstalled.addListener(function(details) {
}
});
browser_.runtime.onMessage.addListener((command) => {
browser_.runtime.onMessage.addListener(async (command) => {
if (command.name === 'screenshotArea') {
browserCaptureVisibleTabs(null, { format: 'jpeg' }).then((imageDataUrl) => {
content = Object.assign({}, command.content);
content.image_data_url = imageDataUrl;
fetch(command.api_base_url + "/notes", {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(content)
});
const zoom = await browserGetZoom();
const imageDataUrl = await browserCaptureVisibleTabs(null, { format: 'jpeg' });
content = Object.assign({}, command.content);
content.image_data_url = imageDataUrl;
const newArea = Object.assign({}, command.content.crop_rect);
newArea.x *= zoom;
newArea.y *= zoom;
newArea.width *= zoom;
newArea.height *= zoom;
content.crop_rect = newArea;
fetch(command.api_base_url + "/notes", {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(content)
});
}
});

View File

@ -199,6 +199,8 @@
document.body.removeChild(selection);
document.body.removeChild(messageComp);
console.info('jopext: selectionArea:', selectionArea);
if (!selectionArea || !selectionArea.width || !selectionArea.height) return;
// Need to wait a bit before taking the screenshot to make sure