AdguardTeam / ExtendedCss

A TypeScript library for non-standard element selecting — :contains(), :matches-css(), etc., and applying CSS styles with extended properties.
GNU General Public License v3.0
65 stars 9 forks source link

Add matching of elements with randomized attributes #90

Closed Alex-302 closed 4 years ago

Alex-302 commented 5 years ago

Randomized attributes are used on Yandex and Mail Ru sites. For example:

data-qh9fwcftda="Клик по баннеру,banner_240x400 - rb 1491"

<div class="lop85y260d r6lx9bmeo9 cbw5d7bijr yspzjys54h ym6trxs0lob pjohbq41cdb viewbox__slide_side_show" data-q9zbjp4jms="SpringsReload.Page" data-kvdvxkh1w2r="1491" data-qh9fwcftda="Клик по баннеру,banner_240x400 - rb 1491" data-ef828zlqmj="9">

In one case we used something like that document.querySelectorAll("div").forEach(n => {if (Array.from(n.attributes).find(t => t.value.startsWith("Клик по баннеру"))) n.remove();}); with MutationObserver.

slavaleleka commented 4 years ago

some websites (for example Google) can use localized aria-label, so I suggest that final syntax might be like example.org#?#body > div:attr-contains(/ad|реклама/)

One more thing I've thought about is skipping such element attributes as 'class' and 'id'

ameshkov commented 4 years ago

It should be something like this: :attr-matches(/attrnameregex/, /attrvalueregex/)