diff --git a/Clipper/joplin-webclipper/background.js b/Clipper/joplin-webclipper/background.js index 8f5fc1f619..63636f1f10 100644 --- a/Clipper/joplin-webclipper/background.js +++ b/Clipper/joplin-webclipper/background.js @@ -8,10 +8,10 @@ if (typeof browser !== 'undefined') { } async function browserCaptureVisibleTabs(windowId, options) { - return new Promise((resolve, reject) => { - if (browserSupportsPromises_) return browser_.tabs.captureVisibleTab(null, { format: 'jpeg' }); + if (browserSupportsPromises_) return browser_.tabs.captureVisibleTab(windowId, { format: 'jpeg' }); - browser_.tabs.captureVisibleTab(null, { format: 'jpeg' }, (image) => { + return new Promise((resolve, reject) => { + browser_.tabs.captureVisibleTab(windowId, { format: 'jpeg' }, (image) => { resolve(image); }); }); @@ -23,9 +23,9 @@ chrome.runtime.onInstalled.addListener(function() { browser_.runtime.onMessage.addListener((command) => { if (command.name === 'screenshotArea') { - browserCaptureVisibleTabs(null, { format: 'jpeg' }).then((image) => { + browserCaptureVisibleTabs(null, { format: 'jpeg' }).then((imageDataUrl) => { content = Object.assign({}, command.content); - content.imageBase64 = image; + content.imageDataUrl = imageDataUrl; fetch(command.apiBaseUrl + "/notes", { method: "POST", diff --git a/Clipper/joplin-webclipper/content_scripts/index.js b/Clipper/joplin-webclipper/content_scripts/index.js index 5562d8fba9..0e43b98220 100644 --- a/Clipper/joplin-webclipper/content_scripts/index.js +++ b/Clipper/joplin-webclipper/content_scripts/index.js @@ -112,7 +112,7 @@ } else if (command.name === 'screenshot') { const overlay = document.createElement('div'); - overlay.style.opacity = '0.5'; + overlay.style.opacity = '0.4'; overlay.style.background = 'black'; overlay.style.width = '100%'; overlay.style.height = '100%'; @@ -123,9 +123,30 @@ document.body.appendChild(overlay); + const messageComp = document.createElement('div'); + + const messageCompWidth = 300; + messageComp.style.position = 'fixed' + messageComp.style.opacity = '0.9' + messageComp.style.width = messageCompWidth + 'px' + messageComp.style.maxWidth = messageCompWidth + 'px' + messageComp.style.border = '1px solid black' + messageComp.style.background = 'white' + messageComp.style.top = '10px' + messageComp.style.textAlign = 'center'; + messageComp.style.padding = '6px' + messageComp.style.left = Math.round(document.body.clientWidth / 2 - messageCompWidth / 2) + 'px' + messageComp.style.zIndex = overlay.style.zIndex + 1 + + messageComp.textContent = 'Drag and release to capture a screenshot'; + + document.body.appendChild(messageComp); + const selection = document.createElement('div'); - selection.style.opacity = '0.5'; - selection.style.background = 'blue'; + selection.style.opacity = '0.4'; + selection.style.border = '1px solid red'; + selection.style.background = 'white'; + selection.style.border = '2px solid black'; selection.style.zIndex = overlay.style.zIndex - 1; selection.style.top = 0; selection.style.left = 0; @@ -138,21 +159,21 @@ let selectionArea = {}; function updateSelection() { - selection.style.left = selectionArea.x; - selection.style.top = selectionArea.y; - selection.style.width = selectionArea.width; - selection.style.height = selectionArea.height; + selection.style.left = selectionArea.x + 'px'; + selection.style.top = selectionArea.y + 'px'; + selection.style.width = selectionArea.width + 'px'; + selection.style.height = selectionArea.height + 'px'; } function setSelectionSizeFromMouse(event) { - selectionArea.width = Math.max(1, event.pageX - draggingStartPos.x); - selectionArea.height = Math.max(1, event.pageY - draggingStartPos.y); + selectionArea.width = Math.max(1, event.clientX - draggingStartPos.x); + selectionArea.height = Math.max(1, event.clientY - draggingStartPos.y); updateSelection(); } function selection_mouseDown(event) { - selectionArea = { x: event.pageX - document.body.scrollLeft, y: event.pageY - document.body.scrollTop, width: 0, height: 0 } - draggingStartPos = { x: event.pageX, y: event.pageY }; + selectionArea = { x: event.clientX, y: event.clientY, width: 0, height: 0 } + draggingStartPos = { x: event.clientX, y: event.clientY }; isDragging = true; updateSelection(); } @@ -173,18 +194,23 @@ document.body.removeChild(overlay); document.body.removeChild(selection); + document.body.removeChild(messageComp); - const content = { - title: pageTitle(), - area: selectionArea, - url: location.origin + location.pathname, - }; + if (!selectionArea || !selectionArea.width || !selectionArea.height) return; - browser_.runtime.sendMessage({ - name: 'screenshotArea', - content: content, - apiBaseUrl: command.apiBaseUrl, - }); + setTimeout(() => { + const content = { + title: pageTitle(), + cropRect: selectionArea, + url: location.origin + location.pathname, + }; + + browser_.runtime.sendMessage({ + name: 'screenshotArea', + content: content, + apiBaseUrl: command.apiBaseUrl, + }); + }, 10); } overlay.addEventListener('mousedown', selection_mouseDown); diff --git a/Clipper/joplin-webclipper/popup/src/App.css b/Clipper/joplin-webclipper/popup/src/App.css index ab7644a6f8..4edd5aac39 100644 --- a/Clipper/joplin-webclipper/popup/src/App.css +++ b/Clipper/joplin-webclipper/popup/src/App.css @@ -77,17 +77,26 @@ margin-bottom: 10px; } -.App .Preview .Body { +.App .Preview .BodyWrapper { flex: 1; + overflow: hidden; + flex-shrink: 1; + min-width: auto; +} + +.App .Preview .Body { + /*flex: 1;*/ font-size: .5em; overflow-x: hidden; overflow-y: scroll; overflow-wrap: break-word; background-color: #ffffff; - flex-shrink: 1; - min-width: auto; - padding: 10px; - margin-bottom: 10px; + /*flex-shrink: 1;*/ + /*min-width: auto;*/ + /*padding: 10px;*/ + /*margin-bottom: 10px;*/ + width: 100%; + height: 100%; } .App .Preview .Confirm { diff --git a/Clipper/joplin-webclipper/popup/src/App.js b/Clipper/joplin-webclipper/popup/src/App.js index ac21f4f851..fb8e50c086 100644 --- a/Clipper/joplin-webclipper/popup/src/App.js +++ b/Clipper/joplin-webclipper/popup/src/App.js @@ -43,6 +43,8 @@ class AppComponent extends Component { name: 'screenshot', apiBaseUrl: 'http://127.0.0.1:9967', }); + + window.close(); } async loadContentScripts() { @@ -91,7 +93,9 @@ class AppComponent extends Component { previewComponent = (