mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
AdBlock: Changes to element blocking rules are now instant.
- instead of need to reload settings / restart browser
This commit is contained in:
parent
2dc0785aff
commit
d8e0556d3e
|
@ -211,16 +211,20 @@ void AdBlockManager::load()
|
||||||
AdBlockSubscription* subscription = new AdBlockSubscription(title, this);
|
AdBlockSubscription* subscription = new AdBlockSubscription(title, this);
|
||||||
subscription->setUrl(url);
|
subscription->setUrl(url);
|
||||||
subscription->setFilePath(absolutePath);
|
subscription->setFilePath(absolutePath);
|
||||||
|
connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
|
||||||
|
|
||||||
m_subscriptions.append(subscription);
|
m_subscriptions.append(subscription);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepend EasyList
|
// Prepend EasyList
|
||||||
AdBlockSubscription* easyList = new AdBlockEasyList(this);
|
AdBlockSubscription* easyList = new AdBlockEasyList(this);
|
||||||
m_subscriptions.prepend(easyList);
|
m_subscriptions.prepend(easyList);
|
||||||
|
connect(easyList, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
|
||||||
|
|
||||||
// Append CustomList
|
// Append CustomList
|
||||||
AdBlockSubscription* customList = new AdBlockCustomList(this);
|
AdBlockCustomList* customList = new AdBlockCustomList(this);
|
||||||
m_subscriptions.append(customList);
|
m_subscriptions.append(customList);
|
||||||
|
connect(customList, SIGNAL(subscriptionEdited()), mApp, SLOT(reloadUserStyleSheet()));
|
||||||
|
|
||||||
// Load all subscriptions
|
// Load all subscriptions
|
||||||
foreach(AdBlockSubscription * subscription, m_subscriptions) {
|
foreach(AdBlockSubscription * subscription, m_subscriptions) {
|
||||||
|
@ -286,6 +290,10 @@ bool AdBlockManager::canBeBlocked(const QUrl &url) const
|
||||||
|
|
||||||
QString AdBlockManager::elementHidingRules() const
|
QString AdBlockManager::elementHidingRules() const
|
||||||
{
|
{
|
||||||
|
if (!m_enabled) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
QString rules;
|
QString rules;
|
||||||
|
|
||||||
foreach(AdBlockSubscription * subscription, m_subscriptions) {
|
foreach(AdBlockSubscription * subscription, m_subscriptions) {
|
||||||
|
|
|
@ -260,6 +260,10 @@ bool AdBlockRule::urlMatch(const QUrl &url) const
|
||||||
|
|
||||||
bool AdBlockRule::matchDomain(const QString &domain) const
|
bool AdBlockRule::matchDomain(const QString &domain) const
|
||||||
{
|
{
|
||||||
|
if (!m_enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_domainRestricted) {
|
if (!m_domainRestricted) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,6 +270,11 @@ const AdBlockRule* AdBlockSubscription::enableRule(int offset)
|
||||||
rule->setEnabled(true);
|
rule->setEnabled(true);
|
||||||
AdBlockManager::instance()->removeDisabledRule(rule->filter());
|
AdBlockManager::instance()->removeDisabledRule(rule->filter());
|
||||||
|
|
||||||
|
if (rule->isCssRule()) {
|
||||||
|
populateCache();
|
||||||
|
mApp->reloadUserStyleSheet();
|
||||||
|
}
|
||||||
|
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +288,11 @@ const AdBlockRule* AdBlockSubscription::disableRule(int offset)
|
||||||
rule->setEnabled(false);
|
rule->setEnabled(false);
|
||||||
AdBlockManager::instance()->addDisabledRule(rule->filter());
|
AdBlockManager::instance()->addDisabledRule(rule->filter());
|
||||||
|
|
||||||
|
if (rule->isCssRule()) {
|
||||||
|
populateCache();
|
||||||
|
mApp->reloadUserStyleSheet();
|
||||||
|
}
|
||||||
|
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,6 +439,8 @@ int AdBlockCustomList::addRule(const AdBlockRule &rule)
|
||||||
m_rules.append(rule);
|
m_rules.append(rule);
|
||||||
populateCache();
|
populateCache();
|
||||||
|
|
||||||
|
emit subscriptionEdited();
|
||||||
|
|
||||||
return m_rules.count() - 1;
|
return m_rules.count() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,6 +455,8 @@ bool AdBlockCustomList::removeRule(int offset)
|
||||||
m_rules.removeAt(offset);
|
m_rules.removeAt(offset);
|
||||||
populateCache();
|
populateCache();
|
||||||
|
|
||||||
|
emit subscriptionEdited();
|
||||||
|
|
||||||
AdBlockManager::instance()->removeDisabledRule(filter);
|
AdBlockManager::instance()->removeDisabledRule(filter);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -457,5 +471,7 @@ const AdBlockRule* AdBlockCustomList::replaceRule(const AdBlockRule &rule, int o
|
||||||
m_rules[offset] = rule;
|
m_rules[offset] = rule;
|
||||||
populateCache();
|
populateCache();
|
||||||
|
|
||||||
|
emit subscriptionEdited();
|
||||||
|
|
||||||
return &m_rules[offset];
|
return &m_rules[offset];
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,9 @@ public:
|
||||||
int addRule(const AdBlockRule &rule);
|
int addRule(const AdBlockRule &rule);
|
||||||
bool removeRule(int offset);
|
bool removeRule(int offset);
|
||||||
const AdBlockRule* replaceRule(const AdBlockRule &rule, int offset);
|
const AdBlockRule* replaceRule(const AdBlockRule &rule, int offset);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void subscriptionEdited();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKSUBSCRIPTION_H
|
#endif // ADBLOCKSUBSCRIPTION_H
|
||||||
|
|
|
@ -756,21 +756,28 @@ void MainApplication::startPrivateBrowsing()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainApplication::reloadUserStyleSheet()
|
||||||
|
{
|
||||||
|
Settings settings;
|
||||||
|
settings.beginGroup("Web-Browser-Settings");
|
||||||
|
m_websettings->setUserStyleSheetUrl(userStyleSheet(settings.value("userStyleSheet", "").toString()));
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
QUrl MainApplication::userStyleSheet(const QString &filePath) const
|
QUrl MainApplication::userStyleSheet(const QString &filePath) const
|
||||||
{
|
{
|
||||||
QString userStyle;
|
QString userStyle = AdBlockManager::instance()->elementHidingRules() + "{ display:none !important;}";
|
||||||
|
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
if (!filePath.isEmpty() && file.open(QFile::ReadOnly)) {
|
if (!filePath.isEmpty() && file.open(QFile::ReadOnly)) {
|
||||||
userStyle = file.readAll();
|
QString fileData = file.readAll();
|
||||||
userStyle.remove('\n');
|
fileData.remove('\n');
|
||||||
|
userStyle.append(fileData);
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
userStyle.append(AdBlockManager::instance()->elementHidingRules() + "{ display:none !important;}");
|
const QString &encodedStyle = userStyle.toAscii().toBase64();
|
||||||
|
const QString &dataString = QString("data:text/css;charset=utf-8;base64,%1").arg(encodedStyle);
|
||||||
QString encodedStyle = userStyle.toAscii().toBase64();
|
|
||||||
QString dataString = QString("data:text/css;charset=utf-8;base64,%1").arg(encodedStyle);
|
|
||||||
|
|
||||||
return QUrl(dataString);
|
return QUrl(dataString);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ public slots:
|
||||||
void addNewTab(const QUrl &url = QUrl());
|
void addNewTab(const QUrl &url = QUrl());
|
||||||
|
|
||||||
void startPrivateBrowsing();
|
void startPrivateBrowsing();
|
||||||
|
void reloadUserStyleSheet();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void message(Qz::AppMessageType mes, bool state);
|
void message(Qz::AppMessageType mes, bool state);
|
||||||
|
|
|
@ -3,9 +3,17 @@
|
||||||
<title>AdBlock Tests &A</title>
|
<title>AdBlock Tests &A</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>Popup Block Tests</h2>
|
<h2>AdBlock Tests</h2>
|
||||||
<a href="javascript:window.open('http://www.google.com/aclk?sa=l&adurl=http://www.edreams.com/', '_blank', 'width=600,height=600,statusbar=no,toolbar=no')">Open Popup window (will be blocked)</a>
|
<h3>Popup Blocking</h3>
|
||||||
<br/>
|
<p>
|
||||||
<br/>
|
<a href="javascript:window.open('http://www.google.com/aclk?sa=l&adurl=http://www.edreams.com/', '_blank', 'width=600,height=600,statusbar=no,toolbar=no')">Open Popup window (will be blocked)</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h3>Element hiding</h3>
|
||||||
|
Blocking element with <b>##div.test-qz-ad</b> rule.
|
||||||
|
<div class="test-qz-ad" style="font-weight: bold; color: darkred;">
|
||||||
|
If you see this text, the rule does not works!
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user