Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/content/snippets.js

Issue 30024560: Issue 7450 - Implement hide-if-contains-visible-text snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Properly handle visibility Created April 30, 2019, 4:07 p.m.
Right Patch Set: Updated patch for real Created May 9, 2019, 12:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | test/browser/snippets.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 if (color == "rgba(0, 0, 0, 0)") 497 if (color == "rgba(0, 0, 0, 0)")
498 return false; 498 return false;
499 if (style.getPropertyValue("background-color") == color) 499 if (style.getPropertyValue("background-color") == color)
500 return false; 500 return false;
501 501
502 return true; 502 return true;
503 } 503 }
504 504
505 /** 505 /**
506 * Check if an element is visible 506 * Check if an element is visible
507 * @param {Element} element The element to check visibility of/ 507 * @param {Element} element The element to check visibility of.
508 * @param {?CSSStyleDeclaration} style The computed style of element. If 508 * @param {?CSSStyleDeclaration} style The computed style of element. If
509 * falsey it will be queried. 509 * falsey it will be queried.
510 * @param {?Element} closest The closest parent to reach. 510 * @param {?Element} closest The closest parent to reach.
511 * @return {bool} Whether the element is visible. 511 * @return {bool} Whether the element is visible.
512 */ 512 */
513 function isVisible(element, style, closest) 513 function isVisible(element, style, closest)
514 { 514 {
515 if (!style) 515 if (!style)
516 style = window.getComputedStyle(element); 516 style = window.getComputedStyle(element);
517 517
518 if (style.getPropertyValue("display") == "none") 518 if (style.getPropertyValue("display") == "none")
519 return false; 519 return false;
520 let visibility = style.getPropertyValue("visibility"); 520 let visibility = style.getPropertyValue("visibility");
521 if (visibility == "hidden" || visibility == "collapse") 521 if (visibility == "hidden" || visibility == "collapse")
522 return false; 522 return false;
523 523
524 if (!closest || element == closest) 524 if (!closest || element == closest)
525 return true; 525 return true;
526 526
527 return isVisible(element.parentNode, null, closest); 527 let parent = element.parentElement;
a.giammarchi 2019/05/08 09:43:47 I have bad feelings about this for at least two re
hub 2019/05/08 17:03:42 I'll stop if parent is null.
a.giammarchi 2019/05/09 08:58:59 where does this happen? 'cause all I see is that y
hub 2019/05/09 12:06:26 It is actually better if I actually properly submi
528 if (!parent)
529 return true;
530
531 return isVisible(parent, null, closest);
528 } 532 }
529 533
530 /** 534 /**
531 * Returns the visible text content from an element and its descendants. 535 * Returns the visible text content from an element and its descendants.
532 * @param {Element} element The element whose visible text we want. 536 * @param {Element} element The element whose visible text we want.
533 * @param {Element} closest The closest parent to reach while checking 537 * @param {Element} closest The closest parent to reach while checking
534 * for visibility. 538 * for visibility.
535 * @returns {string} The text that is visible. 539 * @returns {string} The text that is visible.
536 */ 540 */
537 function getVisibleContent(element, closest) 541 function getVisibleContent(element, closest)
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 1020
1017 args[0] = url.href; 1021 args[0] = url.href;
1018 } 1022 }
1019 1023
1020 return fetch_.apply(this, args); 1024 return fetch_.apply(this, args);
1021 }; 1025 };
1022 } 1026 }
1023 1027
1024 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter, 1028 exports["strip-fetch-query-parameter"] = makeInjector(stripFetchQueryParameter,
1025 toRegExp, regexEscape); 1029 toRegExp, regexEscape);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld