"Fossies" - the Fresh Open Source Software Archive

Member "eric6-20.8/eric/eric6/WebBrowser/AdBlock/AdBlockPage.py" (1 Jan 2020, 1336 Bytes) of package /linux/misc/eric6-20.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "AdBlockPage.py" see the Fossies "Dox" file reference documentation.

    1 # -*- coding: utf-8 -*-
    2 
    3 # Copyright (c) 2009 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
    4 #
    5 
    6 """
    7 Module implementing a class to apply AdBlock rules to a web page.
    8 """
    9 
   10 
   11 from PyQt5.QtCore import QObject
   12 
   13 from ..Tools import Scripts
   14 from ..WebBrowserPage import WebBrowserPage
   15 
   16 
   17 class AdBlockPage(QObject):
   18     """
   19     Class to apply AdBlock rules to a web page.
   20     """
   21     def hideBlockedPageEntries(self, page):
   22         """
   23         Public method to apply AdBlock rules to a web page.
   24         
   25         @param page reference to the web page (HelpWebPage)
   26         """
   27         if page is None:
   28             return
   29         
   30         from WebBrowser.WebBrowserWindow import WebBrowserWindow
   31         manager = WebBrowserWindow.adBlockManager()
   32         if not manager.isEnabled():
   33             return
   34         
   35         # apply global element hiding rules
   36         elementHiding = manager.elementHidingRules(page.url())
   37         if elementHiding:
   38             script = Scripts.setCss(elementHiding)
   39             page.runJavaScript(script, WebBrowserPage.SafeJsWorld)
   40         
   41         # apply domain specific element hiding rules
   42         elementHiding = manager.elementHidingRulesForDomain(page.url())
   43         if elementHiding:
   44             script = Scripts.setCss(elementHiding)
   45             page.runJavaScript(script, WebBrowserPage.SafeJsWorld)