eric6/WebBrowser/AdBlock/AdBlockPage.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

# -*- coding: utf-8 -*-

# Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a class to apply AdBlock rules to a web page.
"""

from PyQt5.QtCore import QObject

from ..Tools import Scripts
from ..WebBrowserPage import WebBrowserPage


class AdBlockPage(QObject):
    """
    Class to apply AdBlock rules to a web page.
    """
    def hideBlockedPageEntries(self, page):
        """
        Public method to apply AdBlock rules to a web page.
        
        @param page reference to the web page (HelpWebPage)
        """
        if page is None:
            return
        
        from WebBrowser.WebBrowserWindow import WebBrowserWindow
        manager = WebBrowserWindow.adBlockManager()
        if not manager.isEnabled():
            return
        
        # apply global element hiding rules
        elementHiding = manager.elementHidingRules(page.url())
        if elementHiding:
            script = Scripts.setCss(elementHiding)
            page.runJavaScript(script, WebBrowserPage.SafeJsWorld)
        
        # apply domain specific element hiding rules
        elementHiding = manager.elementHidingRulesForDomain(page.url())
        if elementHiding:
            script = Scripts.setCss(elementHiding)
            page.runJavaScript(script, WebBrowserPage.SafeJsWorld)

eric ide

mercurial