summaryrefslogtreecommitdiff
path: root/src/adblock
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2013-02-24 18:25:01 +0100
committerAndrea Diamantini <adjam7@gmail.com>2013-02-24 18:25:54 +0100
commit90eab081fa7f46961cd1597a7cb98c1dc32bd0b8 (patch)
tree34ab4d91018b1cc37bb0caa0a8fd72c99703ef65 /src/adblock
parentremove consecutive duplicate word >a< (diff)
downloadrekonq-90eab081fa7f46961cd1597a7cb98c1dc32bd0b8.tar.xz
AdBlock Improvement
Hiding rules support (at least the easy ones, the most ones, against hiding id && classes) :D To test it, take a look (in example) at the url: http://simple-adblock.com/faq/testing-your-adblocker/
Diffstat (limited to 'src/adblock')
-rw-r--r--src/adblock/adblockmanager.cpp53
-rw-r--r--src/adblock/adblockmanager.h6
2 files changed, 57 insertions, 2 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index 62f8930e..51000a3b 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -34,6 +34,8 @@
// Local Includes
#include "adblocksettingwidget.h"
+#include "webpage.h"
+
// KDE Includes
#include <KIO/FileCopyJob>
#include <KStandardDirs>
@@ -115,6 +117,7 @@ void AdBlockManager::loadSettings()
_whiteList.clear();
_blackList.clear();
+
_hideList.clear();
KConfigGroup settingsGroup(_adblockConfig, "Settings");
@@ -224,7 +227,7 @@ void AdBlockManager::loadRuleString(const QString &stringRule)
const QString filter = stringRule.mid(2);
if (filter.isEmpty())
return;
-
+
_hideList << filter;
return;
}
@@ -389,3 +392,51 @@ bool AdBlockManager::isAdblockEnabledForHost(const QString &host)
{
return ! _hostWhiteList.match(host);
}
+
+
+void AdBlockManager::applyHidingRules(QWebFrame *frame)
+{
+ if (!frame)
+ return;
+
+ if (!_isAdblockEnabled)
+ return;
+
+ connect(frame, SIGNAL(loadFinished(bool)), this, SLOT(applyHidingRules(bool)));
+}
+
+
+void AdBlockManager::applyHidingRules(bool ok)
+{
+ if (!ok)
+ return;
+
+ QWebFrame *frame = qobject_cast<QWebFrame *>(sender());
+ if (!frame)
+ return;
+
+ WebPage *page = qobject_cast<WebPage *>(frame->page());
+ if (!page)
+ return;
+
+ QString mainPageHost = page->loadingUrl().host();
+ QStringList hosts = ReKonfig::whiteReferer();
+ if (hosts.contains(mainPageHost))
+ return;
+
+ QWebElement document = frame->documentElement();
+
+ // HIDE RULES
+ Q_FOREACH(const QString & filter, _hideList)
+ {
+ QWebElementCollection elements = document.findAll(filter);
+
+ Q_FOREACH(QWebElement el, elements)
+ {
+ if (el.isNull())
+ continue;
+ kDebug() << "Hide element: " << el.localName();
+ el.removeFromDocument();
+ }
+ }
+}
diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h
index 7f044f3e..3d329ad8 100644
--- a/src/adblock/adblockmanager.h
+++ b/src/adblock/adblockmanager.h
@@ -139,7 +139,7 @@
// Forward Includes
class QNetworkRequest;
-class WebPage;
+class QWebFrame;
// Definitions
typedef QList<AdBlockRule> AdBlockRuleList;
@@ -186,6 +186,9 @@ private Q_SLOTS:
void slotFinished(KJob *);
+ void applyHidingRules(QWebFrame *);
+ void applyHidingRules(bool);
+
Q_SIGNALS:
void reloadCurrentPage();
@@ -197,6 +200,7 @@ private:
AdBlockHostMatcher _hostWhiteList;
AdBlockRuleList _blackList;
AdBlockRuleList _whiteList;
+
QStringList _hideList;
KSharedConfig::Ptr _adblockConfig;