如何根据内容创建广告代码段过滤器?

时间:2017-11-06 01:41:00

标签: jquery adblock

例如,如果我有:

<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>

我知道如果en元素的内容是Sponsored,我想删除它的伟大的曾祖父母元素。

问题是,我不知道如何通过其内容选择元素,也不知道我是否可以通过其伟大的曾孙子元素来选择元素。是否可以使用adblock?

顺便说一句,这是一个用于同一目的的jQuery选择器:$('.pagelet > * > * > * > *:contains("Sponsored")').parent().parent().parent().parent().remove();$(".pagelet:has(> *:contains('Sponsored'))").remove();

1 个答案:

答案 0 :(得分:1)

理论上你应该可以使用#?#div.pagelet:-adp-has(> *:-adp-contains('Sponsored')),但实际上它不起作用。简而言之,adblock不会通过其内容来阻止元素。