mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-19 18:26: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:
parent
cf43bc3269
commit
795bb04acc
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user