mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-19 18:26:34 +01:00
AdBlock: Fixed $subdocument matching.
- also improved a little blocked element's placoholders hiding
This commit is contained in:
parent
14e0040a9f
commit
435ab60e79
@ -336,7 +336,7 @@ bool AdBlockRule::matchSubdocument(const QNetworkRequest &request) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool match = originatingFrame == page->mainFrame();
|
||||
bool match = !(originatingFrame == page->mainFrame());
|
||||
|
||||
return m_subdocumentException ? !match : match;
|
||||
}
|
||||
|
@ -516,9 +516,7 @@ void WebPage::addAdBlockRule(const AdBlockRule* rule, const QUrl &url)
|
||||
void WebPage::cleanBlockedObjects()
|
||||
{
|
||||
AdBlockManager* manager = AdBlockManager::instance();
|
||||
const QString &urlScheme = url().scheme();
|
||||
|
||||
if (!manager->isEnabled() || !manager->canRunOnScheme(urlScheme)) {
|
||||
if (!manager->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -530,12 +528,17 @@ void WebPage::cleanBlockedObjects()
|
||||
continue;
|
||||
}
|
||||
|
||||
QString urlEnd;
|
||||
|
||||
int pos = urlString.lastIndexOf('/');
|
||||
if (pos < 0 || urlString.endsWith('/')) {
|
||||
continue;
|
||||
if (pos > 8) {
|
||||
urlEnd = urlString.mid(pos + 1);
|
||||
}
|
||||
|
||||
if (urlString.endsWith('/')) {
|
||||
urlEnd = urlString.left(urlString.size() - 1);
|
||||
}
|
||||
|
||||
QString urlEnd = urlString.mid(pos + 1);
|
||||
QString selector("img[src$=\"" + urlEnd + "\"], iframe[src$=\"" + urlEnd + "\"],"
|
||||
"embed[src$=\"" + urlEnd + "\"]");
|
||||
QWebElementCollection elements = docElement.findAll(selector);
|
||||
@ -544,8 +547,8 @@ void WebPage::cleanBlockedObjects()
|
||||
QString src = element.attribute("src");
|
||||
src.remove("../");
|
||||
|
||||
if (urlString.endsWith(src)) {
|
||||
element.setStyleProperty("visibility", "hidden");
|
||||
if (urlString.contains(src)) {
|
||||
element.setStyleProperty("display", "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>AdBlock Tests &A</title>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h2>AdBlock Tests</h2>
|
||||
@ -15,5 +16,23 @@ Blocking element with <b>##div.test-qz-ad</b> rule.
|
||||
If you see this text, the rule does not works!
|
||||
</div>
|
||||
|
||||
<h3>Subdocument rules</h3>
|
||||
Blocking iframe with <b>||linux.org.ru^$subdocument</b> rule.
|
||||
<iframe src="http://www.linux.org.ru" width="100" height="100"></iframe>
|
||||
|
||||
<h3>XMLHttpRequest rules</h3>
|
||||
Blocking ajax with <b>adblock.html$xmlhttprequest</b> rule.
|
||||
<div id="ajax-status">Blocked</div>
|
||||
<script>
|
||||
$.get("adblock.html", function(data) {
|
||||
$("#ajax-status").html("Loaded!");
|
||||
});
|
||||
|
||||
if (location.protocol == "file:") {
|
||||
document.write("<h3 style='color:red'>Protocol file:// cannot be blocked!</h3>");
|
||||
document.write("Please move this file to localhost");
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user