Sometimes, in some topics, it happens that a significant proportion of excluded sites is in a certain domain zone. Or several.

And there is absolutely no point in disassembling these zones into good and bad — it is more logical to exclude the entire domain zone.

For such cases, you can use the following script:

var domain_zones = [
    '.porn',
    '.sex',
    '.xxx',
    '.game'
]; // list of domain zones to be excluded

function main() {
    for (var = 0; i < domain_zones.length; i++) {
        var placementSelector = AdsApp.display().placements()
            .withCondition('PlacementUrl CONTAINS "' + domain_zones[i] + '"')
            .withCondition("CampaignStatus != REMOVED");
        var placementIterator = placementSelector.get();
        while (placementIterator.hasNext()) {
            var placement = placementIterator.next();
            var placementUrl = placement.getUrl();
            var campaign = placement.getCampaign();
            var excludeOperation = campaign.display()
                .newPlacementBuilder()
                .withUrl(placementUrl)
                .exclude();
            if (excludeOperation.isSuccessful()) {
                Logger.log(placementUrl + ' - excluded');
            } else  {
                Logger.log(placementUrl + ' - Failed to exclude');
            }
        }
    }
}