1# Copyright (c) 2017-2021 Cedric Bellegarde <cedric.bellegarde@adishatz.org>
2# This program is free software: you can redistribute it and/or modify
3# it under the terms of the GNU General Public License as published by
4# the Free Software Foundation, either version 3 of the License, or
5# (at your option) any later version.
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10# You should have received a copy of the GNU General Public License
11# along with this program. If not, see <http://www.gnu.org/licenses/>.
12
13import json
14
15from eolie.content_blocker import ContentBlocker
16from eolie.logger import Logger
17
18
19class ImagesContentBlocker(ContentBlocker):
20    """
21        A WebKit Content Blocker for images
22    """
23
24    DEFAULT = [
25        {
26            "trigger": {
27                "url-filter": ".*",
28                "resource-type": ["image"]
29            },
30            "action": {
31                "type": "block"
32            }
33        }
34    ]
35
36    def __init__(self):
37        """
38            Init adblock helper
39        """
40        try:
41            ContentBlocker.__init__(self, "block-images")
42            rules = self.DEFAULT + self.exceptions.rules
43            bytes = json.dumps(rules).encode("utf-8")
44            self.save(bytes)
45        except Exception as e:
46            Logger.error("PopupsContentBlocker::__init__(): %s", e)
47