1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-24 04:36:34 +01:00

GreaseMonkey: Fix scripts sometimes not running in frames

Check for document.readyState and if it is "complete", run
the script immediately instead of adding event listener for
DOMContentLoaded that already fired
This commit is contained in:
David Rosca 2014-09-17 09:14:04 +02:00
parent cf43bc3269
commit 795bb04acc
2 changed files with 12 additions and 4 deletions

View File

@ -209,6 +209,8 @@ void GM_Manager::frameLoadStart()
return; return;
} }
const QString readyState = frame->evaluateJavaScript(QSL("document.readyState")).toString();
frame->addToJavaScriptWindowObject(QSL("_qz_greasemonkey"), m_jsObject); frame->addToJavaScriptWindowObject(QSL("_qz_greasemonkey"), m_jsObject);
foreach (GM_Script* script, m_startScripts) { foreach (GM_Script* script, m_startScripts) {
@ -219,11 +221,17 @@ void GM_Manager::frameLoadStart()
foreach (GM_Script* script, m_endScripts) { foreach (GM_Script* script, m_endScripts) {
if (script->match(urlString)) { if (script->match(urlString)) {
// If DOMContentLoaded already fired
if (readyState == QL1S("complete")) {
frame->evaluateJavaScript(m_bootstrap + script->script());
}
else {
const QString jscript = QString(QSL("window.addEventListener(\"DOMContentLoaded\"," const QString jscript = QString(QSL("window.addEventListener(\"DOMContentLoaded\","
"function(e) { \n%1\n }, true);")).arg(m_bootstrap + script->script()); "function(e) { \n%1\n }, true);")).arg(m_bootstrap + script->script());
frame->evaluateJavaScript(jscript); frame->evaluateJavaScript(jscript);
} }
} }
}
} }
void GM_Manager::frameCreated(QWebFrame *frame) void GM_Manager::frameCreated(QWebFrame *frame)

View File

@ -41,7 +41,7 @@ PluginSpec GM_Plugin::pluginSpec()
spec.name = "GreaseMonkey"; spec.name = "GreaseMonkey";
spec.info = "Userscripts for QupZilla"; spec.info = "Userscripts for QupZilla";
spec.description = "Provides support for userscripts (www.userscripts.org)"; spec.description = "Provides support for userscripts (www.userscripts.org)";
spec.version = "0.5.1"; spec.version = "0.5.2";
spec.author = "David Rosca <nowrep@gmail.com>"; spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":gm/data/icon.png"); spec.icon = QPixmap(":gm/data/icon.png");
spec.hasSettings = true; spec.hasSettings = true;