diff options
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 30 |
1 files changed, 24 insertions, 6 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(); } } } |