Skip to content

Commit d2b688b

Browse files
committed
New version with better error messages
1 parent 6193038 commit d2b688b

File tree

5 files changed

+921
-970
lines changed

5 files changed

+921
-970
lines changed

content_script.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616
((browser) => {
17-
1817
let DEBUG = false;
1918

2019
const log = (...args) => {
@@ -75,7 +74,7 @@
7574
1: 'INVALID_SELECTION: ❌ The selected text is too short or does not contain enough valid words. Please choose a longer or more specific phrase.',
7675
2: 'AMBIGUOUS:❌ The selected text appears multiple times on this page and no unique link could be created. Try selecting a different text segment.',
7776
3: 'TIMEOUT: ⏳ The process took too long. This may be due to a large page size or slow browser performance. Try selecting a different text segment.',
78-
4: 'EXECUTION_FAILED: ⚠️ An unexpected error occurred while generating the link.
77+
4: 'EXECUTION_FAILED: ⚠️ An unexpected error occurred while generating the link.',
7978
};
8079

8180
window.queueMicrotask(() => {

fragment-generation-utils.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,26 @@ const makeTextNodeWalker = range => {
265265
return walker;
266266
};
267267

268+
/**
269+
* Helper function to check if the element has attribute `hidden="until-found"`.
270+
* @param {Element} node - the element to evaluate
271+
* @return {Boolean} - true if the element has attribute `hidden="until-found"`
272+
*/
273+
const isHiddenUntilFound = elt => {
274+
if (elt.hidden === 'until-found') {
275+
return true;
276+
}
277+
// Workaround for WebKit. See https://bugs.webkit.org/show_bug.cgi?id=238266
278+
const attributes = elt.attributes;
279+
if (attributes && attributes['hidden']) {
280+
const value = attributes['hidden'].value;
281+
if (value === 'until-found') {
282+
return true;
283+
}
284+
}
285+
return false;
286+
};
287+
268288
/**
269289
* Helper function to calculate the visibility of a Node based on its CSS
270290
* computed style. This function does not take into account the visibility of
@@ -283,6 +303,9 @@ const isNodeVisible = node => {
283303
let elt = node;
284304
while (elt != null && !(elt instanceof HTMLElement)) elt = elt.parentNode;
285305
if (elt != null) {
306+
if (isHiddenUntilFound(elt)) {
307+
return true;
308+
}
286309
const nodeStyle = window.getComputedStyle(elt);
287310
// If the node is not rendered, just skip it.
288311
if (nodeStyle.visibility === 'hidden' || nodeStyle.display === 'none' || parseInt(nodeStyle.height, 10) === 0 || parseInt(nodeStyle.width, 10) === 0 || parseInt(nodeStyle.opacity, 10) === 0) {

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "__MSG_extension_name__",
33
"short_name": "__MSG_extension_short_name__",
4-
"version": "2.5.0",
4+
"version": "2.5.1",
55
"description": "__MSG_extension_description__",
66
"background": {
77
"service_worker": "service_worker.js",

0 commit comments

Comments
 (0)