mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-24 12:46:35 +01:00
GreaseMonkey: Remove GM_UrlMatcher
This commit is contained in:
parent
3d5f45bfc5
commit
4f5d3193ae
@ -7,7 +7,6 @@ DEPENDPATH += settings\
|
||||
SOURCES += gm_plugin.cpp \
|
||||
gm_manager.cpp \
|
||||
gm_script.cpp \
|
||||
gm_urlmatcher.cpp \
|
||||
gm_downloader.cpp \
|
||||
gm_addscriptdialog.cpp \
|
||||
gm_notification.cpp \
|
||||
@ -22,7 +21,6 @@ SOURCES += gm_plugin.cpp \
|
||||
HEADERS += gm_plugin.h \
|
||||
gm_manager.h \
|
||||
gm_script.h \
|
||||
gm_urlmatcher.h \
|
||||
gm_downloader.h \
|
||||
gm_addscriptdialog.h \
|
||||
gm_notification.h \
|
||||
|
@ -104,24 +104,12 @@ void GM_Script::setEnabled(bool enable)
|
||||
|
||||
QStringList GM_Script::include() const
|
||||
{
|
||||
QStringList list;
|
||||
|
||||
foreach (const GM_UrlMatcher &matcher, m_include) {
|
||||
list.append(matcher.pattern());
|
||||
}
|
||||
|
||||
return list;
|
||||
return m_include;
|
||||
}
|
||||
|
||||
QStringList GM_Script::exclude() const
|
||||
{
|
||||
QStringList list;
|
||||
|
||||
foreach (const GM_UrlMatcher &matcher, m_exclude) {
|
||||
list.append(matcher.pattern());
|
||||
}
|
||||
|
||||
return list;
|
||||
return m_exclude;
|
||||
}
|
||||
|
||||
QString GM_Script::script() const
|
||||
@ -160,27 +148,6 @@ QWebEngineScript GM_Script::webScript() const
|
||||
return script;
|
||||
}
|
||||
|
||||
bool GM_Script::match(const QString &urlString)
|
||||
{
|
||||
if (!isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (const GM_UrlMatcher &matcher, m_exclude) {
|
||||
if (matcher.match(urlString)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const GM_UrlMatcher &matcher, m_include) {
|
||||
if (matcher.match(urlString)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GM_Script::watchedFileChanged(const QString &file)
|
||||
{
|
||||
if (m_fileName == file) {
|
||||
@ -268,10 +235,10 @@ void GM_Script::parseScript()
|
||||
m_downloadUrl = QUrl(value);
|
||||
}
|
||||
else if (key == QLatin1String("@include") || key == QLatin1String("@match")) {
|
||||
m_include.append(GM_UrlMatcher(value));
|
||||
m_include.append(value);
|
||||
}
|
||||
else if (key == QLatin1String("@exclude") || key == QLatin1String("@exclude_match")) {
|
||||
m_exclude.append(GM_UrlMatcher(value));
|
||||
m_exclude.append(value);
|
||||
}
|
||||
else if (key == QLatin1String("@require")) {
|
||||
requireList.append(value);
|
||||
@ -296,7 +263,7 @@ void GM_Script::parseScript()
|
||||
}
|
||||
|
||||
if (m_include.isEmpty()) {
|
||||
m_include.append(GM_UrlMatcher("*"));
|
||||
m_include.append(QSL("*"));
|
||||
}
|
||||
|
||||
const QString nspace = QCryptographicHash::hash(fullName().toUtf8(), QCryptographicHash::Md4).toHex();
|
||||
|
@ -18,8 +18,6 @@
|
||||
#ifndef GM_SCRIPT_H
|
||||
#define GM_SCRIPT_H
|
||||
|
||||
#include "gm_urlmatcher.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QUrl>
|
||||
@ -27,7 +25,6 @@
|
||||
class QWebEngineScript;
|
||||
|
||||
class GM_Manager;
|
||||
class GM_UrlMatcher;
|
||||
|
||||
class DelayedFileWatcher;
|
||||
|
||||
@ -65,8 +62,6 @@ public:
|
||||
|
||||
QWebEngineScript webScript() const;
|
||||
|
||||
bool match(const QString &urlString);
|
||||
|
||||
signals:
|
||||
void scriptChanged();
|
||||
|
||||
@ -84,8 +79,8 @@ private:
|
||||
QString m_description;
|
||||
QString m_version;
|
||||
|
||||
QVector<GM_UrlMatcher> m_include;
|
||||
QVector<GM_UrlMatcher> m_exclude;
|
||||
QStringList m_include;
|
||||
QStringList m_exclude;
|
||||
|
||||
QUrl m_downloadUrl;
|
||||
QUrl m_updateUrl;
|
||||
|
@ -1,106 +0,0 @@
|
||||
/* ============================================================
|
||||
* GreaseMonkey plugin for QupZilla
|
||||
* Copyright (C) 2012-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "gm_urlmatcher.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
static bool wildcardMatch(const QString &string, const QString &pattern)
|
||||
{
|
||||
int stringSize = string.size();
|
||||
int patternSize = pattern.size();
|
||||
|
||||
bool startsWithWildcard = pattern[0] == QLatin1Char('*');
|
||||
bool endsWithWildcard = pattern[patternSize - 1] == QLatin1Char('*');
|
||||
|
||||
const QStringList parts = pattern.split(QLatin1Char('*'));
|
||||
int pos = 0;
|
||||
|
||||
if (startsWithWildcard) {
|
||||
pos = string.indexOf(parts.at(1));
|
||||
if (pos == -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const QString &part, parts) {
|
||||
pos = string.indexOf(part, pos);
|
||||
if (pos == -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!endsWithWildcard && stringSize - pos != parts.last().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GM_UrlMatcher::GM_UrlMatcher()
|
||||
: m_useRegExp(false)
|
||||
{
|
||||
}
|
||||
|
||||
GM_UrlMatcher::GM_UrlMatcher(const QString &pattern)
|
||||
: m_pattern(pattern)
|
||||
, m_useRegExp(false)
|
||||
{
|
||||
//parsePattern(m_pattern);
|
||||
}
|
||||
|
||||
QString GM_UrlMatcher::pattern() const
|
||||
{
|
||||
return m_pattern;
|
||||
}
|
||||
|
||||
bool GM_UrlMatcher::match(const QString &urlString) const
|
||||
{
|
||||
if (m_useRegExp) {
|
||||
return m_regExp.indexIn(urlString) != -1;
|
||||
}
|
||||
else {
|
||||
return wildcardMatch(urlString, m_matchString);
|
||||
}
|
||||
}
|
||||
|
||||
void GM_UrlMatcher::parsePattern(QString pattern)
|
||||
{
|
||||
if (pattern.startsWith(QLatin1Char('/')) && pattern.endsWith(QLatin1Char('/'))) {
|
||||
pattern = pattern.mid(1);
|
||||
pattern = pattern.left(pattern.size() - 1);
|
||||
|
||||
m_regExp = QzRegExp(pattern, Qt::CaseInsensitive);
|
||||
m_useRegExp = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (pattern.contains(QLatin1String(".tld"))) {
|
||||
pattern.replace(QzRegExp("(\\W)"), QLatin1String("\\\\1"))
|
||||
.replace(QzRegExp("\\*+"), QLatin1String("*"))
|
||||
.replace(QzRegExp("^\\\\\\|"), QLatin1String("^"))
|
||||
.replace(QzRegExp("\\\\\\|$"), QLatin1String("$"))
|
||||
.replace(QzRegExp("\\\\\\*"), QLatin1String(".*"))
|
||||
.replace(QLatin1String("\\.tld"), QLatin1String("\\.[a-z.]{2,6}"));
|
||||
|
||||
m_useRegExp = true;
|
||||
m_regExp = QzRegExp(pattern, Qt::CaseInsensitive);
|
||||
}
|
||||
else {
|
||||
m_matchString = pattern;
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/* ============================================================
|
||||
* GreaseMonkey plugin for QupZilla
|
||||
* Copyright (C) 2012-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef GM_URLMATCHER_H
|
||||
#define GM_URLMATCHER_H
|
||||
|
||||
#include <QString>
|
||||
#include "qzregexp.h"
|
||||
|
||||
class GM_UrlMatcher
|
||||
{
|
||||
public:
|
||||
explicit GM_UrlMatcher();
|
||||
GM_UrlMatcher(const QString &pattern);
|
||||
|
||||
QString pattern() const;
|
||||
|
||||
bool match(const QString &urlString) const;
|
||||
|
||||
private:
|
||||
void parsePattern(QString pattern);
|
||||
|
||||
QString m_pattern;
|
||||
|
||||
QString m_matchString;
|
||||
QzRegExp m_regExp;
|
||||
|
||||
bool m_useRegExp;
|
||||
};
|
||||
|
||||
// Hint to QVector to use std::realloc on item moving
|
||||
Q_DECLARE_TYPEINFO(GM_UrlMatcher, Q_MOVABLE_TYPE);
|
||||
|
||||
#endif // GM_URLMATCHER_H
|
Loading…
Reference in New Issue
Block a user