From 0da388f20611b823a515d8bcfa6c8757e1fb0c57 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 27 Feb 2016 17:26:25 +0100 Subject: [PATCH] GreaseMonkey: Add support for run-at: document-idle --- src/plugins/GreaseMonkey/gm_script.cpp | 22 ++++++++++++++++++++-- src/plugins/GreaseMonkey/gm_script.h | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/plugins/GreaseMonkey/gm_script.cpp b/src/plugins/GreaseMonkey/gm_script.cpp index 708948dd7..a8a0b105a 100644 --- a/src/plugins/GreaseMonkey/gm_script.cpp +++ b/src/plugins/GreaseMonkey/gm_script.cpp @@ -1,6 +1,6 @@ /* ============================================================ * GreaseMonkey plugin for QupZilla -* Copyright (C) 2012-2014 David Rosca +* Copyright (C) 2012-2016 David Rosca * * 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 @@ -141,10 +141,25 @@ QString GM_Script::fileName() const QWebEngineScript GM_Script::webScript() const { + QWebEngineScript::InjectionPoint injectionPoint; + switch (startAt()) { + case DocumentStart: + injectionPoint = QWebEngineScript::DocumentCreation; + break; + case DocumentEnd: + injectionPoint = QWebEngineScript::DocumentReady; + break; + case DocumentIdle: + injectionPoint = QWebEngineScript::Deferred; + break; + default: + Q_UNREACHABLE(); + } + QWebEngineScript script; script.setName(fullName()); - script.setInjectionPoint(startAt() == DocumentStart ? QWebEngineScript::DocumentCreation : QWebEngineScript::DocumentReady); script.setWorldId(QWebEngineScript::MainWorld); + script.setInjectionPoint(injectionPoint); script.setRunsOnSubFrames(!m_noframes); script.setSourceCode(QSL("%1\n%2\n%3").arg(m_metadata, m_manager->bootstrapScript(), m_script)); return script; @@ -274,6 +289,9 @@ void GM_Script::parseScript() else if (value == QLatin1String("document-start")) { m_startAt = DocumentStart; } + else if (value == QLatin1String("document-idle")) { + m_startAt = DocumentIdle; + } } else if (key == QLatin1String("@downloadURL") && m_downloadUrl.isEmpty()) { m_downloadUrl = QUrl(value); diff --git a/src/plugins/GreaseMonkey/gm_script.h b/src/plugins/GreaseMonkey/gm_script.h index 620b80cf0..15d9db7ec 100644 --- a/src/plugins/GreaseMonkey/gm_script.h +++ b/src/plugins/GreaseMonkey/gm_script.h @@ -1,6 +1,6 @@ /* ============================================================ * GreaseMonkey plugin for QupZilla -* Copyright (C) 2012-2014 David Rosca +* Copyright (C) 2012-2016 David Rosca * * 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 @@ -37,7 +37,7 @@ class GM_Script : public QObject public: explicit GM_Script(GM_Manager* manager, const QString &filePath); - enum StartAt { DocumentStart, DocumentEnd }; + enum StartAt { DocumentStart, DocumentEnd, DocumentIdle }; bool isValid() const; QString name() const;