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

Clipper: Resolves #641: Allow clipping selected part of the page

This commit is contained in:
Laurent Cozic 2018-06-28 22:01:55 +01:00
parent 0c708f766b
commit 2ded983828
2 changed files with 27 additions and 17 deletions

View File

@ -74,6 +74,17 @@
async function prepareCommandResponse(command) { async function prepareCommandResponse(command) {
console.info('Got command: ' + command.name); console.info('Got command: ' + command.name);
const clippedContentResponse = (title, html) => {
return {
name: 'clippedContent',
title: title,
html: html,
base_url: baseUrl(),
url: location.origin + location.pathname,
parent_id: command.parent_id,
};
}
if (command.name === "simplifiedPageHtml") { if (command.name === "simplifiedPageHtml") {
let article = null; let article = null;
@ -87,29 +98,20 @@
response.warning = 'Could not retrieve simplified version of page - full page has been saved instead.'; response.warning = 'Could not retrieve simplified version of page - full page has been saved instead.';
return response; return response;
} }
return clippedContentResponse(article.title, article.body);
return {
name: 'clippedContent',
html: article.body,
title: article.title,
base_url: baseUrl(),
url: location.origin + location.pathname,
parent_id: command.parent_id,
};
} else if (command.name === "completePageHtml") { } else if (command.name === "completePageHtml") {
const cleanDocument = document.body.cloneNode(true); const cleanDocument = document.body.cloneNode(true);
cleanUpElement(cleanDocument); cleanUpElement(cleanDocument);
return clippedContentResponse(pageTitle(), cleanDocument.innerHTML);
return { } else if (command.name === "selectedHtml") {
name: 'clippedContent',
html: cleanDocument.innerHTML, const range = window.getSelection().getRangeAt(0);
title: pageTitle(), const container = document.createElement('div');
base_url: baseUrl(), container.appendChild(range.cloneContents());
url: location.origin + location.pathname, return clippedContentResponse(pageTitle(), container.innerHTML);
parent_id: command.parent_id,
};
} else if (command.name === 'screenshot') { } else if (command.name === 'screenshot') {

View File

@ -41,6 +41,13 @@ class AppComponent extends Component {
}); });
} }
this.clipSelection_click = () => {
bridge().sendCommandToActiveTab({
name: 'selectedHtml',
parent_id: this.props.selectedFolderId,
});
}
this.clipScreenshot_click = async () => { this.clipScreenshot_click = async () => {
try { try {
const baseUrl = await bridge().clipperServerBaseUrl(); const baseUrl = await bridge().clipperServerBaseUrl();
@ -195,6 +202,7 @@ class AppComponent extends Component {
<ul> <ul>
<li><a className="Button" onClick={this.clipSimplified_click}>Clip simplified page</a></li> <li><a className="Button" onClick={this.clipSimplified_click}>Clip simplified page</a></li>
<li><a className="Button" onClick={this.clipComplete_click}>Clip complete page</a></li> <li><a className="Button" onClick={this.clipComplete_click}>Clip complete page</a></li>
<li><a className="Button" onClick={this.clipSelection_click}>Clip selection</a></li>
<li><a className="Button" onClick={this.clipScreenshot_click}>Clip screenshot</a></li> <li><a className="Button" onClick={this.clipScreenshot_click}>Clip screenshot</a></li>
</ul> </ul>
</div> </div>