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).

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class to apply AdBlock rules to a web page.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
4860
0a44aff88bfa Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4847
diff changeset
10 from PyQt5.QtCore import QObject
381
64ae9e09d8bc Extended the Ad-Blocker of the web browser and added capability to configure the text encoding of the web browser (needs Qt >= 4.6).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
11
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
12 from ..Tools import Scripts
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4990
diff changeset
13 from ..WebBrowserPage import WebBrowserPage
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
14
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
15
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 class AdBlockPage(QObject):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 Class to apply AdBlock rules to a web page.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1947
diff changeset
20 def hideBlockedPageEntries(self, page):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1947
diff changeset
22 Public method to apply AdBlock rules to a web page.
1947
84626f18f2c3 Simplified the code a little bit by deleting the checks for the existance of QWebElement because Qt 4.7 is the minimum requirement.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
23
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1947
diff changeset
24 @param page reference to the web page (HelpWebPage)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
26 if page is None:
1947
84626f18f2c3 Simplified the code a little bit by deleting the checks for the existance of QWebElement because Qt 4.7 is the minimum requirement.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
27 return
84626f18f2c3 Simplified the code a little bit by deleting the checks for the existance of QWebElement because Qt 4.7 is the minimum requirement.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
28
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
29 from WebBrowser.WebBrowserWindow import WebBrowserWindow
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
30 manager = WebBrowserWindow.adBlockManager()
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
31 if not manager.isEnabled():
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
32 return
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1947
diff changeset
33
4990
2bca10fcfe80 Modified the handling of user style sheets and the AdBlock hiding rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4860
diff changeset
34 # apply global element hiding rules
2bca10fcfe80 Modified the handling of user style sheets and the AdBlock hiding rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4860
diff changeset
35 elementHiding = manager.elementHidingRules(page.url())
2bca10fcfe80 Modified the handling of user style sheets and the AdBlock hiding rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4860
diff changeset
36 if elementHiding:
2bca10fcfe80 Modified the handling of user style sheets and the AdBlock hiding rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4860
diff changeset
37 script = Scripts.setCss(elementHiding)
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4990
diff changeset
38 page.runJavaScript(script, WebBrowserPage.SafeJsWorld)
4990
2bca10fcfe80 Modified the handling of user style sheets and the AdBlock hiding rules.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4860
diff changeset
39
1960
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1947
diff changeset
40 # apply domain specific element hiding rules
d8c45fe8a1b9 Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1947
diff changeset
41 elementHiding = manager.elementHidingRulesForDomain(page.url())
4847
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
42 if elementHiding:
a1a8eac81b54 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
43 script = Scripts.setCss(elementHiding)
5001
08eaee907686 Prepared the QWebEingine based web browser for the new runJavaScript() method as of Qt 5.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4990
diff changeset
44 page.runJavaScript(script, WebBrowserPage.SafeJsWorld)

eric ide

mercurial