32 using namespace MessageViewer;
40 if (!rule.contains(QLatin1String(
"##")))
43 if (rule.startsWith(QLatin1String(
"##")))
45 m_GenericRules.push_back(rule.mid(2));
49 const QStringList lst = rule.split(QLatin1String(
"##"));
50 const QString domainSpecificRule = lst[1];
52 QStringList domains = lst[0].split(QLatin1Char(
','));
53 Q_FOREACH(
const QString &domain, domains) {
54 if(domain.startsWith(QLatin1Char(
'~'))) {
55 m_DomainSpecificRulesWhitelist.insert(domain.mid(1),
60 m_DomainSpecificRules.insert(domain, domainSpecificRule);
70 Q_FOREACH(
const QString &rule, m_GenericRules) {
71 applyStringRule(document, rule);
75 QStringList whiteListedRules;
76 const QStringList subdomainList = generateSubdomainList(domain);
78 Q_FOREACH(
const QString &d, subdomainList) {
79 whiteListedRules.append(m_DomainSpecificRulesWhitelist.values(d));
83 Q_FOREACH(
const QString &d, subdomainList) {
84 QList<QString> ruleList = m_DomainSpecificRules.values(d);
85 Q_FOREACH(
const QString &rule, ruleList) {
86 if (!whiteListedRules.contains(rule))
87 applyStringRule(document, rule);
94 m_GenericRules.clear();
95 m_DomainSpecificRules.clear();
96 m_DomainSpecificRulesWhitelist.clear();
99 void AdBlockElementHiding::applyStringRule(QWebElement &document,
const QString &rule)
const
101 QWebElementCollection elements = document.findAll(rule);
103 Q_FOREACH(QWebElement el, elements)
107 kDebug() <<
"Hide element: " << el.localName();
108 el.removeFromDocument();
112 QStringList AdBlockElementHiding::generateSubdomainList(
const QString &domain)
const
114 QStringList returnList;
116 int dotPosition = domain.lastIndexOf(QLatin1Char(
'.'));
117 dotPosition = domain.lastIndexOf(QLatin1Char(
'.'), dotPosition - 1);
118 while (dotPosition != -1)
120 returnList.append(domain.mid(dotPosition + 1));
121 dotPosition = domain.lastIndexOf(QLatin1Char(
'.'), dotPosition - 1);
123 returnList.append(domain);
void apply(QWebElement &document, const QString &domain) const
bool addRule(const QString &rule)