0

For example if I have:

<div class="pagelet c_a534-97mv ego_column">
  <div class="_1-ia">
    <div class="_4-u2 _1-ib _2tyk _20os _4-u8">
      <div class="ego_section">
        <div class="_3652">
          <div class="_3653"><a href="/campaign/landing.php?placement=egot&amp;campaign_id=366925476690229&amp;extra_1=auto">Sponsored</a></div><a href="/campaign/landing.php?placement=emuca&amp;campaign_id=282141474901&amp;extra_1=auto">Create Ad</a>
          <div class="_45hc _3a3e"></div>
        </div>
        <div class="ego_unit_container">
          <div class="ego_unit" data-ego-fbid="6081250585478" id="u_ps_0_8_1">
            <div class="w_a534-9ce_" id="6081250585478-id_59ffbacea74b14444973955">
              <div class="r_a534-dohl">
                <div class="uiSelector inlineBlock emu_x uiChevronSelectorButton uiSelectorRight">
                  <div class="uiToggle wrap"><a class="uiSelectorButton uiCloseButton" href="#" role="button" title="" aria-label="Report or learn more" ajaxify="/ajax/a.php?__tn__=%2AC&amp;sig=65536&amp;hide_event=fad_hide&amp;ui=6081250585478-id_59ffbacea74b14444973955&amp;eid=AI%407e39f2a47541b21db9854192d3562791" data-gt="{&quot;type&quot;:&quot;ads_xout&quot;,&quot;data_to_log&quot;:{&quot;ad_id&quot;:6081250585478,&quot;ad_account_id&quot;:21275111,&quot;ads_page_type&quot;:7,&quot;creative_type&quot;:27,&quot;group_id&quot;:0,&quot;event&quot;:&quot;click_hide_link_dropdown&quot;}}" aria-haspopup="true" rel="toggle"></a></div>
                </div>
                <a href="https://l.facebook.com/l.php?u=https%3A%2F%2Fwww.fancycellar.com%2Fen%2Fproducts%2Fbrand%2Fskyy-6498%2Fwine-type%2Fvodka-4328%3Fsort%3Dfield_product%253Acommerce_price%253Aamount%26order%3Dasc&amp;h=ATPgA2PQcxPg-fHA71IPW2qj2ZqD8EIOrTmSj87pMZhVD0i1qPDhv4wj8r6ffFG9shGzVAobCDul2L-T_pBbwURMzVRmXyG3p_9MJoth8PESo_XvrlBfj-jfo1Y79nEXOpafCNmCEHdaULOQ&amp;enc=AZO-Rd1yM916tq-J3CfHCiKI6WH4wvhqVhXMt4xNOzSrdypez1Zs9rq1YPufpb9tUGZAlJDnTavzc5cn8cLaD3y9W-PKVmMpIjiXmBx3accvmjsGffpaCUjzxX5Cc4jAX3GfQSL9yGKtu4Eby9-uLK4mP0_xI3_Iz0_HwhFyu8hfrenibz_EKUyNuqggUD6hT_98SYZ_LWcKjSCEUlXuuD9Q&amp;s=1" target="_blank" rel="noopener nofollow" onmousedown="this.href = this.href.replace(/([\?|&amp;]sig=[^&amp;]*)/, &quot;&quot;) + &quot;&amp;sig=&quot; + Math.floor(Math.random()*65535+65536);">
                  <div class="_4pru b_a534-97lj">
                    <div class="h_a534-97l_">
                      <div class="o_a534-aizy">
                        <div class="z_a534-97lf">
                          <div class="v_a534-97m6">
                            <div class="uiScaledImageContainer" style="width:284px;height:149px;"><img class="scaledImageFitWidth img" src="https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t45.1600-4/c5.0.284.149/p284x149/21143310_6081250173078_8405501240246534144_n.png?oh=28f0c0808baf50709753dcc7b0e56180&amp;oe=5AA0A1F1&amp;__gda__=1520375584_40548e3ebdda13d278dbac203abe91a3" alt="" width="284" height="149"></div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="x_a534-97lg" title="SKYY Vodka - Infusions Cherry / Citrus / Vanilla... ">
                      <div class="c_a534-97lh"><strong>SKYY Vodka - Infusions Cherry / Citrus / Vanilla... </strong></div>
                      <div class="l_a534-97le">FancyCellar.com</div>
                    </div>
                    <div></div>
                    <div class="g_a534-97mo">
                      <div><span class="h_a534-97mp">SKYY Infusions uses natural flavor in the infusion process to provide a unique, fresh and...</span></div>
                    </div>
                  </div>
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

I know that if en element's content is Sponsored, I want to remove it's great-great-great-grandparent element.

The problem is, I don't know how to select an element by its content, nor do I know if I can select an element by its great-great-great-grandchild's element. Is it possible with adblock?

BTW, this is a jQuery selector for the same purpose: $('.pagelet > * > * > * > *:contains("Sponsored")').parent().parent().parent().parent().remove(); or $(".pagelet:has(> *:contains('Sponsored'))").remove();

Aero Wang
  • 8,382
  • 14
  • 63
  • 99
  • A quick Google search for "jQuery select element by content" yielded this: https://api.jquery.com/contains-selector/ – fubar Nov 06 '17 at 01:45
  • Possible duplicate of [jquery find element by text](https://stackoverflow.com/questions/7321896/jquery-find-element-by-text) – fubar Nov 06 '17 at 01:46
  • @fubar did you read the question carefully? This is not a question asking how to do selection on jQuery. – Aero Wang Nov 06 '17 at 01:48
  • You question stated - `The problem is, I don't know how to select an element by its content` and you have tagged it with `jQuery`. If this isn't your question, what is? – fubar Nov 06 '17 at 01:54
  • @fubar "How to create an adblock filter based on contents?" – Aero Wang Nov 06 '17 at 01:58
  • that question is very broad, and I think your question will likely get closed as such. Do you have **specfic** questions? – fubar Nov 06 '17 at 02:01
  • 1
    HOW IS THE QUESTION BROAD? Have you ever used an an adblock filter? – Aero Wang Nov 06 '17 at 02:09
  • So you think asking a community to tell you how you can build an ad blocker, from scratch, is not too broad? Something that will arguably need to identify any form of advert content, anywhere in an unknown HTML structure and then remove it without compromising the HTML structure. Hmm... let me think. Is that too broad? (facepalm) – fubar Nov 06 '17 at 02:13
  • Here you go. The [AdBlock source code](https://github.com/adblockplus/adblockpluschrome) is open source. You can learn everything you want to know. Oh and the multitude of files here are for Google Chrome only. So you'll need to check out the other repos too. But I'm sure someone could have written you a JS Fiddle gist that includes all of this functionality. – fubar Nov 06 '17 at 02:21

1 Answers1

1

In theory you should be able to use #?#div.pagelet:-adp-has(> *:-adp-contains('Sponsored')) but in reality it doesn't work. In short, adblock doesn't block elements by its contents.

James Wayne
  • 1,894
  • 14
  • 14