1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

GreaseMonkey: Run usercscripts in all frames on page

This commit is contained in:
nowrep 2013-07-29 17:55:35 +02:00
parent 7a75153b9f
commit 567d6c74f4
4 changed files with 27 additions and 17 deletions

View File

@ -16,6 +16,7 @@ Version 1.5.0
* GreaseMonkey: added icon in statusbar
* GreaseMonkey: added support for GM_Settings
* GreaseMonkey: fixed userscripts when first loading plugin
* GreaseMonkey: run userscripts in all frames on page
* oxygen: set rounded corners for tooltips
* oxygen: workaround for transparent background of tooltips
* X11: Set correct WM_CLASS property to windows

View File

@ -196,23 +196,29 @@ void GM_Manager::showNotification(const QString &message, const QString &title)
void GM_Manager::pageLoadStart()
{
QWebFrame* frame = qobject_cast<QWebFrame*>(sender());
if (!frame) {
QWebFrame* mainFrame = qobject_cast<QWebFrame*>(sender());
if (!mainFrame) {
return;
}
const QString &urlScheme = frame->url().scheme();
const QString &urlString = frame->url().toEncoded();
const QString &urlScheme = mainFrame->url().scheme();
const QString &urlString = mainFrame->url().toEncoded();
if (!canRunOnScheme(urlScheme)) {
return;
}
frame->addToJavaScriptWindowObject("_qz_greasemonkey", m_jsObject);
// Run it in every frame
QList<QWebFrame*> frames;
frames.append(mainFrame);
while (!frames.isEmpty()) {
QWebFrame* frame = frames.takeFirst();
if (frame) {
mainFrame->addToJavaScriptWindowObject("_qz_greasemonkey", m_jsObject);
foreach (GM_Script* script, m_startScripts) {
if (script->match(urlString)) {
frame->evaluateJavaScript(m_bootstrap + script->script());
mainFrame->evaluateJavaScript(m_bootstrap + script->script());
}
}
@ -220,7 +226,10 @@ void GM_Manager::pageLoadStart()
if (script->match(urlString)) {
const QString &jscript = QString("window.addEventListener(\"DOMContentLoaded\","
"function(e) { \n%1\n }, false);").arg(m_bootstrap + script->script());
frame->evaluateJavaScript(jscript);
mainFrame->evaluateJavaScript(jscript);
}
}
frames += frame->childFrames();
}
}
}

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.4.1";
spec.version = "0.4.2";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":gm/data/icon.png");
spec.hasSettings = true;