[webkit-help] Content Hiding in Safari 9

Brent Montrose brent.montrose at gmail.com
Tue Jun 16 16:34:29 PDT 2015


Hello,

Thanks for the quick reply to my earlier email ("A few questions about
Content Blocking Extensions in Safari 9").

I have another question regarding content hiding and the use of the
"if-domain" option in the "trigger" field.  I would like some
clarification regarding the usage of the "if-domain" and the
"unless-domain" options.

Below is some sample code which successfully hides a few ads on slashdot.org.

     var rules = [];
      //general rule 1
      rules.push({
        "action": {
            "selector": ".adwrap",
            "type": "css-display-none"
        },
        "trigger": {
            "url-filter": ".*"
        }
      });
      //general rule 2
      rules.push({
        "action": {
            "selector": "div[id^=\"div-gpt-ad-\"]",
            "type": "css-display-none"
        },
        "trigger": {
            "url-filter": ".*"
        }
      });
      //site specific rule 3
      rules.push({
        "action": {
          "selector": "#banner-wrap",
          "type": "css-display-none"
        },
        "trigger": {
          "url-filter": ".*",
         // "if-domain": ["slashdot.org"]
         }
      });
      safari.extension.setContentBlocker(rules);

The above code works, and successfully hides the ads.  However, if the
"if-domain" line is uncommented in site specific rule 3 above, the ads
are displayed.  Is there a way to write the above three rules so that
the ads on slashdot.org are hidden?  In other words, I would like:
- all three rules applied to slashdot.org
- rule 1 and 2 applied to any other site / domain
- only rule 3 applied to slashdot.org

Is there a way to write the rules to do this?  If so, how?

Thanks in advance for your help.


More information about the webkit-help mailing list