Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/
dist/
.project
18 changes: 16 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ browser.contextMenus.create({
contexts: ["selection"]
});

/*
browser.contextMenus.create({
id: "trilium-save-cropped-screenshot",
title: "Clip screenshot to Trilium",
contexts: ["page"]
});
*/

browser.contextMenus.create({
id: "trilium-save-cropped-screenshot",
Expand All @@ -96,6 +98,12 @@ browser.contextMenus.create({
contexts: ["page"]
});

browser.contextMenus.create({
id: "trilium-save-page-without-image",
title: "Save whole page without image to Trilium",
contexts: ["page"]
});

browser.contextMenus.create({
id: "trilium-save-link",
title: "Save link to Trilium",
Expand Down Expand Up @@ -263,8 +271,8 @@ async function saveImage(srcUrl, pageUrl) {
toast("Image has been saved to Trilium.", resp.noteId);
}

async function saveWholePage() {
const payload = await sendMessageToActiveTab({name: 'trilium-save-page'});
async function saveWholePage(withImage = true) {
const payload = await sendMessageToActiveTab({name: 'trilium-save-page', withImage: withImage});

await postProcessImages(payload);

Expand Down Expand Up @@ -380,6 +388,9 @@ browser.contextMenus.onClicked.addListener(async function(info, tab) {
else if (info.menuItemId === 'trilium-save-page') {
await saveWholePage();
}
else if (info.menuItemId === 'trilium-save-page-without-image') {
await saveWholePage(false);
}
else {
console.log("Unrecognized menuItemId", info.menuItemId);
}
Expand Down Expand Up @@ -432,6 +443,9 @@ browser.runtime.onMessage.addListener(async request => {
else if (request.name === 'save-whole-page') {
return await saveWholePage();
}
else if (request.name === 'save-whole-page-without-image') {
return await saveWholePage(false);
}
else if (request.name === 'save-link-with-note') {
return await saveLinkWithNote(request.title, request.content);
}
Expand Down
20 changes: 19 additions & 1 deletion content.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ function getImages(container) {
return images;
}

function removeImages(container) {
const images = [];

for (const img of container.getElementsByTagName('img')) {
if (!img.src) {
continue;
}

images.push(img);
}

for (const img of images) {
img.remove();
}

return [];
}

function createLink(clickAction, text, color = "lightskyblue") {
const link = document.createElement('a');
link.href = "javascript:";
Expand Down Expand Up @@ -292,7 +310,7 @@ async function prepareMessageResponse(message) {

makeLinksAbsolute(body);

const images = getImages(body);
const images = message.withImage ? getImages(body) : removeImages(body);

return {
title: title,
Expand Down
1 change: 1 addition & 0 deletions popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h3>Trilium Web Clipper</h3>
<button class="button full needs-connection" id="save-cropped-screenshot-button">Crop screen shot</button>
<button class="button full needs-connection" id="save-whole-screenshot-button">Save whole screen shot</button>
<button class="button full needs-connection" id="save-whole-page-button">Save whole page</button>
<button class="button full needs-connection" id="save-whole-page-without-image-button">Save whole page without image</button>
<button class="button full needs-connection" id="save-link-with-note-button">Save link with a note</button>
<button class="button full needs-connection" id="save-tabs-button">Save window's tabs as a list</button>

Expand Down
3 changes: 3 additions & 0 deletions popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const $showOptionsButton = $("#show-options-button");
const $saveCroppedScreenShotButton = $("#save-cropped-screenshot-button");
const $saveWholeScreenShotButton = $("#save-whole-screenshot-button");
const $saveWholePageButton = $("#save-whole-page-button");
const $saveWholePageWithoutImageButton = $("#save-whole-page-without-image-button");
const $saveTabsButton = $("#save-tabs-button");

$showOptionsButton.on("click", () => browser.runtime.openOptionsPage());
Expand All @@ -31,6 +32,8 @@ $saveWholeScreenShotButton.on("click", () => {

$saveWholePageButton.on("click", () => sendMessage({name: 'save-whole-page'}));

$saveWholePageWithoutImageButton.on("click", () => sendMessage({name: 'save-whole-page-without-image'}));

$saveTabsButton.on("click", () => sendMessage({name: 'save-tabs'}));

const $saveLinkWithNoteWrapper = $("#save-link-with-note-wrapper");
Expand Down