1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +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;
}
const QString readyState = frame->evaluateJavaScript(QSL("document.readyState")).toString();
frame->addToJavaScriptWindowObject(QSL("_qz_greasemonkey"), m_jsObject);
foreach (GM_Script* script, m_startScripts) {
@ -219,9 +221,15 @@ void GM_Manager::frameLoadStart()
foreach (GM_Script* script, m_endScripts) {
if (script->match(urlString)) {
const QString jscript = QString(QSL("window.addEventListener(\"DOMContentLoaded\","
"function(e) { \n%1\n }, true);")).arg(m_bootstrap + script->script());
frame->evaluateJavaScript(jscript);
// If DOMContentLoaded already fired
if (readyState == QL1S("complete")) {
frame->evaluateJavaScript(m_bootstrap + script->script());
}
else {
const QString jscript = QString(QSL("window.addEventListener(\"DOMContentLoaded\","
"function(e) { \n%1\n }, true);")).arg(m_bootstrap + script->script());
frame->evaluateJavaScript(jscript);
}
}
}
}

View File

@ -41,7 +41,7 @@ PluginSpec GM_Plugin::pluginSpec()
spec.name = "GreaseMonkey";
spec.info = "Userscripts for QupZilla";
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.icon = QPixmap(":gm/data/icon.png");
spec.hasSettings = true;