1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-03-20 20:55:18 +02:00

Clipper: Fixes #1526: Local files can be clipped again

This commit is contained in:
Laurent Cozic 2019-06-11 01:09:48 +01:00
parent 7af0dcd19a
commit d6218f35fe
2 changed files with 22 additions and 9 deletions

View File

@ -23,11 +23,12 @@ window.joplinEnv = function() {
return env_; return env_;
} }
async function browserCaptureVisibleTabs(windowId, options) { async function browserCaptureVisibleTabs(windowId) {
if (browserSupportsPromises_) return browser_.tabs.captureVisibleTab(windowId, { format: 'jpeg' }); const options = { format: 'jpeg' };
if (browserSupportsPromises_) return browser_.tabs.captureVisibleTab(windowId, options);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
browser_.tabs.captureVisibleTab(windowId, { format: 'jpeg' }, (image) => { browser_.tabs.captureVisibleTab(windowId, options, (image) => {
resolve(image); resolve(image);
}); });
}); });
@ -56,7 +57,7 @@ browser_.runtime.onMessage.addListener(async (command) => {
const zoom = await browserGetZoom(); const zoom = await browserGetZoom();
const imageDataUrl = await browserCaptureVisibleTabs(null, { format: 'jpeg' }); const imageDataUrl = await browserCaptureVisibleTabs(null);
content = Object.assign({}, command.content); content = Object.assign({}, command.content);
content.image_data_url = imageDataUrl; content.image_data_url = imageDataUrl;

View File

@ -19,7 +19,7 @@
const protocol = url.toLowerCase().split(':')[0]; const protocol = url.toLowerCase().split(':')[0];
if (['http', 'https', 'file'].indexOf(protocol) >= 0) return url; if (['http', 'https', 'file'].indexOf(protocol) >= 0) return url;
if (url.indexOf('//')) { if (url.indexOf('//') === 0) {
return location.protocol + url; return location.protocol + url;
} else if (url[0] === '/') { } else if (url[0] === '/') {
return location.protocol + '//' + location.host + url; return location.protocol + '//' + location.host + url;
@ -34,8 +34,20 @@
return document.title.trim(); return document.title.trim();
} }
function pageLocationOrigin() {
// location.origin normally returns the protocol + domain + port (eg. https://example.com:8080)
// but for file:// protocol this is browser dependant and in particular Firefox returns "null"
// in this case.
if (location.protocol === 'file:') {
return 'file://';
} else {
return location.origin;
}
}
function baseUrl() { function baseUrl() {
let output = location.origin + location.pathname; let output = pageLocationOrigin() + location.pathname;
if (output[output.length - 1] !== '/') { if (output[output.length - 1] !== '/') {
output = output.split('/'); output = output.split('/');
output.pop(); output.pop();
@ -123,7 +135,7 @@
title: title, title: title,
html: html, html: html,
base_url: baseUrl(), base_url: baseUrl(),
url: location.origin + location.pathname + location.search, url: pageLocationOrigin() + location.pathname + location.search,
parent_id: command.parent_id, parent_id: command.parent_id,
tags: command.tags || '', tags: command.tags || '',
image_sizes: imageSizes, image_sizes: imageSizes,
@ -265,7 +277,7 @@
const content = { const content = {
title: pageTitle(), title: pageTitle(),
crop_rect: selectionArea, crop_rect: selectionArea,
url: location.origin + location.pathname, url: pageLocationOrigin() + location.pathname,
parent_id: command.parent_id, parent_id: command.parent_id,
tags: command.tags, tags: command.tags,
}; };
@ -286,7 +298,7 @@
} else if (command.name === "pageUrl") { } else if (command.name === "pageUrl") {
let url = location.origin + location.pathname + location.search; let url = pageLocationOrigin() + location.pathname + location.search;
return clippedContentResponse(pageTitle(), url, getImageSizes(document)); return clippedContentResponse(pageTitle(), url, getImageSizes(document));
} else { } else {