diff options
Diffstat (limited to 'src/adblock')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 30 | ||||
-rw-r--r-- | src/adblock/adblockmanager.h | 2 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 71412d5d..0a139bdc 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -148,7 +148,7 @@ void AdBlockManager::loadRules(const QStringList &rules) } -QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) +QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *page) { if (!_isAdblockEnabled) return 0; @@ -179,6 +179,20 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) kDebug() << "****ADBLOCK: BLACK RULE Matched: ***********"; kDebug() << "Filter exp: " << filter.pattern(); kDebug() << "UrlString: " << urlString; + + QWebElement document = page->mainFrame()->documentElement(); + QWebElementCollection elements = document.findAll("*"); + foreach (QWebElement el, elements) + { + if(filter.match( el.attribute("src") ) ) + { + kDebug() << "MATCHES ATTRIBUTE!!!!!"; + el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); + el.setStyleProperty(QLatin1String("width"), QLatin1String("0")); + el.setStyleProperty(QLatin1String("height"), QLatin1String("0")); + } + } + AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); return reply; } @@ -199,17 +213,21 @@ void AdBlockManager::applyHidingRules(WebPage *page) if (!_isHideAdsEnabled) return; + + QWebElement document = page->mainFrame()->documentElement(); + // HIDE RULES foreach(const QString &filter, _hideList) { - QWebElement document = page->mainFrame()->documentElement(); QWebElementCollection elements = document.findAll(filter); - foreach (QWebElement element, elements) + foreach (QWebElement el, elements) { - kDebug() << "Hide element: " << element.localName(); - element.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); - element.removeFromDocument(); + if(el.isNull()) + continue; + kDebug() << "Hide element: " << el.localName(); + el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); + el.removeFromDocument(); } } } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index c0bd2b70..9b1cc915 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -131,7 +131,7 @@ public: AdBlockManager(QObject *parent = 0); ~AdBlockManager(); - QNetworkReply *block(const QNetworkRequest &request); + QNetworkReply *block(const QNetworkRequest &request, WebPage *page); void applyHidingRules(WebPage *page); void addSubscription(const QString &title, const QString &location); |