Skip to content

Commit

Permalink
v1.10.4 - Fix ad detection. Handle svg/aria trickery
Browse files Browse the repository at this point in the history
  • Loading branch information
mgziminsky committed Sep 21, 2022
1 parent 5b46dd7 commit 91e0270
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.10.4
- Fix ad detection. Handle svg/aria trickery.

v1.10.3
- Fix mention completion popup - closes #62

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "__MSG_extensionName__",
"version": "1.10.3",
"version": "1.10.4",
"description": "__MSG_extensionDescription__",
"default_locale": "en",
"icons": { "128": "src/icon.png" },
Expand Down
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ app.init().then(async () => {
};

for (const e of selectAllWithBase(node, selector)) {
const elementText = visibleText(e);
const elementText = ariaText(e) || useText(e) || visibleText(e);

const match = getMatch(elementText);
if (match) {
Expand Down
3 changes: 3 additions & 0 deletions src/hide_rules/sponsored/selectors
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
._3nlk
[aria-label]
[aria-labelledby]
a[role=link]
a>span:only-of-type
div[role=button]
div>a:first-child
div>a[onmousedown]
h3>*
use
3 changes: 3 additions & 0 deletions src/hide_rules/suggested/selectors
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[aria-label]
[aria-labelledby]
h3
span[dir]
use
18 changes: 18 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@ function normalizeString(str) {
return Array.from(str.trim().toLowerCase()).sort().join("");
}

/** @param {HTMLElement} elem */
function ariaText(elem) {
const labels = elem.getAttribute('aria-labelledby')?.split(' ')
.map(id => document.getElementById(id))
.filter(e => e);

const text = [...new Set(labels || [])].map(e => e.textContent).join(' ');
return text ? text : elem.getAttribute('aria-label');
}

/** @param {SVGUseElement} elem */
function useText(elem) {
if (elem.tagName.toUpperCase() != 'USE')
return;

return document.querySelector(elem.href.baseVal)?.textContent;
}

/** @param {HTMLElement} elem */
function visibleText(elem) {
let text = elem.dataset.content ?? "";
Expand Down

0 comments on commit 91e0270

Please sign in to comment.