Skip to content

Commit

Permalink
fixes and library updates
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Apr 2, 2020
1 parent 1a58026 commit 338f01b
Show file tree
Hide file tree
Showing 8 changed files with 631 additions and 1,267 deletions.
14 changes: 10 additions & 4 deletions background.js
Expand Up @@ -124,11 +124,15 @@ async function postProcessImage(image) {
if (image.src.startsWith("data:image/")) {
image.dataUrl = image.src;
image.src = "inline." + image.src.substr(11, 3); // this should extract file type - png/jpg

return;
}

image.dataUrl = await fetchImage(image.src, image);
else {
try {
image.dataUrl = await fetchImage(image.src, image);
}
catch (e) {
console.log(`Cannot fetch image from ${image.src}`);
}
}
}

async function postProcessImages(resp) {
Expand Down Expand Up @@ -268,6 +272,8 @@ browser.contextMenus.onClicked.addListener(async function(info, tab) {
});

browser.runtime.onMessage.addListener(async request => {
console.log("Received", request);

if (request.name === 'openNoteInTrilium') {
const resp = await triliumServerFacade.callService('POST', 'open/' + request.noteId);

Expand Down
19 changes: 13 additions & 6 deletions content.js
Expand Up @@ -189,14 +189,21 @@ function getImages(container) {
continue;
}

const imageId = randomString(20);
const existingImage = images.find(image => image.src === img.src);

images.push({
imageId: imageId,
src: img.src
});
if (existingImage) {
img.src = existingImage.imageId;
}
else {
const imageId = randomString(20);

img.src = imageId;
images.push({
imageId: imageId,
src: img.src
});

img.src = imageId;
}
}

return images;
Expand Down
3 changes: 1 addition & 2 deletions lib/JSDOMParser.js
@@ -1,5 +1,3 @@
// https://github.com/mozilla/readability/tree/814f0a3884350b6f1adfdebb79ca3599e9806605

/*eslint-env es6:false*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
Expand Down Expand Up @@ -310,6 +308,7 @@
}
}
getElems(this);
elems._isLiveNodeList = true;
return elems;
}

Expand Down
13 changes: 7 additions & 6 deletions lib/Readability-readerable.js
@@ -1,5 +1,3 @@
// https://github.com/mozilla/readability/tree/814f0a3884350b6f1adfdebb79ca3599e9806605

/* eslint-env es6:false */
/* globals exports */
/*
Expand All @@ -26,13 +24,16 @@
var REGEXPS = {
// NOTE: These two regular expressions are duplicated in
// Readability.js. Please keep both copies in sync.
unlikelyCandidates: /-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|foot|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,
okMaybeItsACandidate: /and|article|body|column|main|shadow/i,
unlikelyCandidates: /-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i,
okMaybeItsACandidate: /and|article|body|column|content|main|shadow/i,
};

function isNodeVisible(node) {
// Have to null-check node.style to deal with SVG and MathML nodes.
return (!node.style || node.style.display != "none") && !node.hasAttribute("hidden");
// Have to null-check node.style and node.className.indexOf to deal with SVG and MathML nodes.
return (!node.style || node.style.display != "none")
&& !node.hasAttribute("hidden")
//check for "fallback-image" so that wikimedia math images are displayed
&& (!node.hasAttribute("aria-hidden") || node.getAttribute("aria-hidden") != "true" || (node.className && node.className.indexOf && node.className.indexOf("fallback-image") !== -1));
}

/**
Expand Down

0 comments on commit 338f01b

Please sign in to comment.