mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
AdBlock: Better and faster hiding placeholders of blocked elements
- also Ctrl+C in AdBlock tree now copies url filter into clipboard
This commit is contained in:
parent
2b7b28db37
commit
138ffdfe93
12
CHANGELOG
12
CHANGELOG
@ -1,6 +1,9 @@
|
|||||||
Version 1.3.0
|
Version 1.3.0
|
||||||
* not released yet
|
* not released yet
|
||||||
* added animated tab previews
|
* new Ukrainian translation
|
||||||
|
* can now open .xhtml files from open file dialog
|
||||||
|
* added animated tab previews with option to turn animations off
|
||||||
|
* possibility to change icon of bookmarks
|
||||||
* ssl manager now can import own certificate
|
* ssl manager now can import own certificate
|
||||||
* clear recent history now remembers last checked options
|
* clear recent history now remembers last checked options
|
||||||
* new urlbar completion widget can now show also entries from bookmarks
|
* new urlbar completion widget can now show also entries from bookmarks
|
||||||
@ -8,13 +11,18 @@ Version 1.3.0
|
|||||||
* support for 3rd party subscriptions in AdBlock
|
* support for 3rd party subscriptions in AdBlock
|
||||||
* improved performance of AdBlock rules matching
|
* improved performance of AdBlock rules matching
|
||||||
* possibility to add subscriptions with loading abp: links
|
* possibility to add subscriptions with loading abp: links
|
||||||
|
* private browsing is now opened in new window and new process
|
||||||
* improved AdBlock dialog distinguish rule types with colors
|
* improved AdBlock dialog distinguish rule types with colors
|
||||||
* popup windows now have loading animation in urlbar
|
* popup windows now have loading animation in urlbar
|
||||||
* new gif for loading animation (spinner)
|
* new gif for loading animation (spinner)
|
||||||
* possibility to add RSS feed into external reader
|
* possibility to add RSS feed into external reader
|
||||||
* option to specify preferred behaviour when opening new tab
|
* option to specify preferred behaviour when opening new tab
|
||||||
* inverting preferred new tab behaviour with shift modifier (eg. shift+middle click on link)
|
* inverting preferred new tab behaviour with shift modifier (eg. shift+middle click on link)
|
||||||
* X11: middle clicking on add tab button will open new tab with global mouse selection's contents
|
* better support for Content-Disposition header (downloads)
|
||||||
|
* Linux: middle clicking on add tab button will open new tab with global mouse selection's contents
|
||||||
|
* Linux: generating backtrace and saving it into file upon application crash
|
||||||
|
* fixed saving passwords on some sites (parsing WebKit's data format)
|
||||||
|
* fixed "go to web address" action when newlines were in string
|
||||||
* fixed excessive ssl warnings when rejecting untrusted certificate
|
* fixed excessive ssl warnings when rejecting untrusted certificate
|
||||||
* fixed dragging the whole text from some labels
|
* fixed dragging the whole text from some labels
|
||||||
* fixed handling special characters when searching with shortcuts in urlbar
|
* fixed handling special characters when searching with shortcuts in urlbar
|
||||||
|
@ -79,8 +79,7 @@ QNetworkReply* AdBlockManager::block(const QNetworkRequest &request)
|
|||||||
const QString &urlDomain = request.url().host();
|
const QString &urlDomain = request.url().host();
|
||||||
const QString &urlScheme = request.url().scheme();
|
const QString &urlScheme = request.url().scheme();
|
||||||
|
|
||||||
if (!isEnabled() || urlScheme == "data" || urlScheme == "qrc" ||
|
if (!isEnabled() || !canRunOnScheme(urlScheme)) {
|
||||||
urlScheme == "file" || urlScheme == "qupzilla" || urlScheme == "abp") {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,6 +264,11 @@ bool AdBlockManager::isEnabled()
|
|||||||
return m_enabled;
|
return m_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AdBlockManager::canRunOnScheme(const QString &scheme) const
|
||||||
|
{
|
||||||
|
return !(scheme == "file" || scheme == "qrc" || scheme == "qupzilla" || scheme == "data" || scheme == "abp");
|
||||||
|
}
|
||||||
|
|
||||||
QString AdBlockManager::elementHidingRules() const
|
QString AdBlockManager::elementHidingRules() const
|
||||||
{
|
{
|
||||||
QString rules;
|
QString rules;
|
||||||
|
@ -43,6 +43,7 @@ public:
|
|||||||
void save();
|
void save();
|
||||||
|
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
|
bool canRunOnScheme(const QString &scheme) const;
|
||||||
|
|
||||||
QString elementHidingRules() const;
|
QString elementHidingRules() const;
|
||||||
QString elementHidingRulesForDomain(const QString &domain) const;
|
QString elementHidingRulesForDomain(const QString &domain) const;
|
||||||
|
@ -362,7 +362,7 @@ void AdBlockRule::parseFilter()
|
|||||||
parseDomains(option.mid(7), '|');
|
parseDomains(option.mid(7), '|');
|
||||||
++handledOptions;
|
++handledOptions;
|
||||||
}
|
}
|
||||||
else if (option.endsWith("match-case")) {
|
else if (option == "match-case") {
|
||||||
m_caseSensitivity = Qt::CaseSensitive;
|
m_caseSensitivity = Qt::CaseSensitive;
|
||||||
++handledOptions;
|
++handledOptions;
|
||||||
}
|
}
|
||||||
@ -386,6 +386,10 @@ void AdBlockRule::parseFilter()
|
|||||||
m_xmlhttprequestException = option.startsWith('~');
|
m_xmlhttprequestException = option.startsWith('~');
|
||||||
++handledOptions;
|
++handledOptions;
|
||||||
}
|
}
|
||||||
|
else if (option == "collapse") {
|
||||||
|
// Hiding placeholders of blocked elements
|
||||||
|
++handledOptions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't handle all options, it's safer to just disable this rule
|
// If we don't handle all options, it's safer to just disable this rule
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QApplication>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
|
||||||
AdBlockTreeWidget::AdBlockTreeWidget(AdBlockSubscription* subscription, QWidget* parent)
|
AdBlockTreeWidget::AdBlockTreeWidget(AdBlockSubscription* subscription, QWidget* parent)
|
||||||
@ -120,6 +122,16 @@ void AdBlockTreeWidget::itemChanged(QTreeWidgetItem* item)
|
|||||||
m_itemChangingBlock = false;
|
m_itemChangingBlock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AdBlockTreeWidget::copyFilter()
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* item = currentItem();
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QApplication::clipboard()->setText(item->text(0));
|
||||||
|
}
|
||||||
|
|
||||||
void AdBlockTreeWidget::addRule()
|
void AdBlockTreeWidget::addRule()
|
||||||
{
|
{
|
||||||
if (!m_subscription->canEditRules()) {
|
if (!m_subscription->canEditRules()) {
|
||||||
@ -203,6 +215,10 @@ void AdBlockTreeWidget::adjustItemFeatures(QTreeWidgetItem* item, const AdBlockR
|
|||||||
|
|
||||||
void AdBlockTreeWidget::keyPressEvent(QKeyEvent* event)
|
void AdBlockTreeWidget::keyPressEvent(QKeyEvent* event)
|
||||||
{
|
{
|
||||||
|
if (event->key() == Qt::Key_C && event->modifiers() & Qt::ControlModifier) {
|
||||||
|
copyFilter();
|
||||||
|
}
|
||||||
|
|
||||||
if (event->key() == Qt::Key_Delete) {
|
if (event->key() == Qt::Key_Delete) {
|
||||||
removeRule();
|
removeRule();
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ public slots:
|
|||||||
private slots:
|
private slots:
|
||||||
void contextMenuRequested(const QPoint &pos);
|
void contextMenuRequested(const QPoint &pos);
|
||||||
void itemChanged(QTreeWidgetItem* item);
|
void itemChanged(QTreeWidgetItem* item);
|
||||||
|
void copyFilter();
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
void subscriptionUpdated();
|
void subscriptionUpdated();
|
||||||
|
@ -507,54 +507,47 @@ void WebPage::addAdBlockRule(const AdBlockRule* rule, const QUrl &url)
|
|||||||
|
|
||||||
void WebPage::cleanBlockedObjects()
|
void WebPage::cleanBlockedObjects()
|
||||||
{
|
{
|
||||||
if (!AdBlockManager::instance()->isEnabled()) {
|
AdBlockManager* manager = AdBlockManager::instance();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't run on local schemes
|
|
||||||
const QString &urlScheme = url().scheme();
|
const QString &urlScheme = url().scheme();
|
||||||
if (urlScheme == "data" || urlScheme == "qrc" || urlScheme == "file" ||
|
|
||||||
urlScheme == "qupzilla" || urlScheme == "abp") {
|
if (!manager->isEnabled() || !manager->canRunOnScheme(urlScheme)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList findingStrings;
|
|
||||||
|
|
||||||
foreach(const AdBlockedEntry & entry, m_adBlockedEntries) {
|
|
||||||
if (entry.url.toString().endsWith(".js")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
findingStrings.append(entry.url.toString());
|
|
||||||
const QUrl &mainFrameUrl = url();
|
|
||||||
|
|
||||||
if (entry.url.scheme() == mainFrameUrl.scheme() && entry.url.host() == mainFrameUrl.host()) {
|
|
||||||
//May be relative url
|
|
||||||
QString relativeUrl = qz_makeRelativeUrl(mainFrameUrl, entry.url).toString();
|
|
||||||
findingStrings.append(relativeUrl);
|
|
||||||
if (relativeUrl.startsWith('/')) {
|
|
||||||
findingStrings.append(relativeUrl.right(relativeUrl.size() - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const QWebElement &docElement = mainFrame()->documentElement();
|
const QWebElement &docElement = mainFrame()->documentElement();
|
||||||
QWebElementCollection elements;
|
|
||||||
|
|
||||||
foreach(const QString & s, findingStrings) {
|
foreach(const AdBlockedEntry & entry, m_adBlockedEntries) {
|
||||||
elements.append(docElement.findAll("*[src=\"" + s + "\"]"));
|
const QString &urlString = entry.url.toString();
|
||||||
|
if (urlString.endsWith(".js") || urlString.endsWith(".css")) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pos = urlString.lastIndexOf('/');
|
||||||
|
if (pos < 0 || urlString.endsWith('/')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString urlEnd = urlString.mid(pos + 1);
|
||||||
|
QString selector("img[src$=\"" + urlEnd + "\"], iframe[src$=\"" + urlEnd + "\"],"
|
||||||
|
"embed[src$=\"" + urlEnd + "\"]");
|
||||||
|
QWebElementCollection elements = docElement.findAll(selector);
|
||||||
|
|
||||||
foreach(QWebElement element, elements) {
|
foreach(QWebElement element, elements) {
|
||||||
|
QString src = element.attribute("src");
|
||||||
|
src.remove("../");
|
||||||
|
|
||||||
|
if (urlString.endsWith(src)) {
|
||||||
element.setStyleProperty("visibility", "hidden");
|
element.setStyleProperty("visibility", "hidden");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Apply domain-specific element hiding rules
|
// Apply domain-specific element hiding rules
|
||||||
QString elementHiding = AdBlockManager::instance()->elementHidingRulesForDomain(url().host());
|
QString elementHiding = AdBlockManager::instance()->elementHidingRulesForDomain(url().host());
|
||||||
elementHiding.append("{display: none !important;}\n</style>");
|
elementHiding.append("{display: none !important;}\n</style>");
|
||||||
|
|
||||||
QWebElement headElement = docElement.findFirst("body");
|
QWebElement bodyElement = docElement.findFirst("body");
|
||||||
headElement.appendInside("<style type=\"text/css\">\n/* AdBlock for QupZilla */\n" + elementHiding);
|
bodyElement.appendInside("<style type=\"text/css\">\n/* AdBlock for QupZilla */\n" + elementHiding);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WebPage::userAgentForUrl(const QUrl &url) const
|
QString WebPage::userAgentForUrl(const QUrl &url) const
|
||||||
|
Loading…
Reference in New Issue
Block a user