mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
[AdBlock] Fixed hiding rules when more than 5000 rules in subscription.
Closes #873
This commit is contained in:
parent
bef40d2ca6
commit
1b617068b2
@ -348,11 +348,6 @@ QString AdBlockManager::elementHidingRules() const
|
||||
rules.append(subscription->elementHidingRules());
|
||||
}
|
||||
|
||||
// Remove last ","
|
||||
if (!rules.isEmpty()) {
|
||||
rules = rules.left(rules.size() - 1);
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
|
@ -377,7 +377,6 @@ void AdBlockRule::parseFilter()
|
||||
}
|
||||
|
||||
m_cssSelector = parsedLine.mid(pos + 2);
|
||||
m_cssSelector.remove('\\');
|
||||
|
||||
// CSS rule cannot have more options -> stop parsing
|
||||
return;
|
||||
|
@ -258,12 +258,28 @@ QString AdBlockSubscription::elementHidingRulesForDomain(const QString &domain)
|
||||
{
|
||||
QString rules;
|
||||
|
||||
int addedRulesCount = 0;
|
||||
int count = m_domainRestrictedCssRules.count();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const AdBlockRule* rule = m_domainRestrictedCssRules.at(i);
|
||||
if (rule->matchDomain(domain)) {
|
||||
rules.append(rule->cssSelector() + QLatin1Char(','));
|
||||
if (!rule->matchDomain(domain)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Q_UNLIKELY(addedRulesCount == 1000)) {
|
||||
rules.append(rule->cssSelector());
|
||||
rules.append("{display:none !important;}\n");
|
||||
addedRulesCount = 0;
|
||||
}
|
||||
else {
|
||||
rules.append(rule->cssSelector() + QLatin1Char(','));
|
||||
addedRulesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (addedRulesCount != 0) {
|
||||
rules = rules.left(rules.size() - 1);
|
||||
rules.append("{display:none !important;}\n");
|
||||
}
|
||||
|
||||
return rules;
|
||||
@ -357,6 +373,11 @@ void AdBlockSubscription::populateCache()
|
||||
m_documentRules.clear();
|
||||
m_elemhideRules.clear();
|
||||
|
||||
// Apparently, excessive amount of selectors for one CSS rule is not what WebKit likes.
|
||||
// (In my testings, 4931 is the number that makes it crash)
|
||||
// So let's split it by 1000 selectors...
|
||||
int hidingRulesCount = 0;
|
||||
|
||||
int count = m_rules.count();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const AdBlockRule* rule = m_rules.at(i);
|
||||
@ -368,8 +389,14 @@ void AdBlockSubscription::populateCache()
|
||||
if (rule->isDomainRestricted()) {
|
||||
m_domainRestrictedCssRules.append(rule);
|
||||
}
|
||||
else if (Q_UNLIKELY(hidingRulesCount == 1000)) {
|
||||
m_elementHidingRules.append(rule->cssSelector());
|
||||
m_elementHidingRules.append("{display:none !important;} ");
|
||||
hidingRulesCount = 0;
|
||||
}
|
||||
else {
|
||||
m_elementHidingRules.append(rule->cssSelector() + ",");
|
||||
m_elementHidingRules.append(rule->cssSelector() + QLatin1Char(','));
|
||||
hidingRulesCount++;
|
||||
}
|
||||
}
|
||||
else if (rule->isDocument()) {
|
||||
@ -385,6 +412,11 @@ void AdBlockSubscription::populateCache()
|
||||
m_networkBlockRules.append(rule);
|
||||
}
|
||||
}
|
||||
|
||||
if (hidingRulesCount != 0) {
|
||||
m_elementHidingRules = m_elementHidingRules.left(m_elementHidingRules.size() - 1);
|
||||
m_elementHidingRules.append("{display:none !important;} ");
|
||||
}
|
||||
}
|
||||
|
||||
AdBlockSubscription::~AdBlockSubscription()
|
||||
|
@ -1016,7 +1016,7 @@ QUrl MainApplication::userStyleSheet(const QString &filePath) const
|
||||
userStyle += QString("::selection {background: %1; color: %2;} ").arg(highlightColor, highlightedTextColor);
|
||||
#endif
|
||||
|
||||
userStyle += AdBlockManager::instance()->elementHidingRules() + "{ display:none !important;}";
|
||||
userStyle += AdBlockManager::instance()->elementHidingRules();
|
||||
|
||||
QFile file(filePath);
|
||||
if (!filePath.isEmpty() && file.open(QFile::ReadOnly)) {
|
||||
|
@ -152,7 +152,7 @@ void SourceViewer::loadSource()
|
||||
|
||||
QString html = m_frame.data()->toHtml();
|
||||
// Remove AdBlock element hiding rules
|
||||
html.remove(QzRegExp("<style type=\"text/css\">\n/\\* AdBlock for QupZilla \\*/\n.*\\{display: none !important;\\}\n</style>"));
|
||||
html.remove(QzRegExp("<style type=\"text/css\">\n/\\* AdBlock for QupZilla \\*/\n.*\\{display:none !important;\\}\n</style>"));
|
||||
m_sourceEdit->setPlainText(html);
|
||||
|
||||
// Highlight selectedHtml
|
||||
|
@ -639,7 +639,7 @@ void WebPage::cleanBlockedObjects()
|
||||
return;
|
||||
}
|
||||
|
||||
elementHiding.append(QLatin1String("{display: none !important;}\n</style>"));
|
||||
elementHiding.append(QLatin1String("\n</style>"));
|
||||
|
||||
QWebElement bodyElement = docElement.findFirst("body");
|
||||
bodyElement.appendInside("<style type=\"text/css\">\n/* AdBlock for QupZilla */\n" + elementHiding);
|
||||
|
Loading…
Reference in New Issue
Block a user