Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Commit

Permalink
GreaseMonkey: Run usercscripts in all frames on page
Browse files Browse the repository at this point in the history
  • Loading branch information
nowrep committed Jul 29, 2013
1 parent 7a75153 commit 567d6c7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tools/qztools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ QString QzTools::escape(const QString &string)
}

#if defined(QZ_WS_X11) && !defined(NO_X11)
void *QzTools::X11Display(const QWidget* widget)
void* QzTools::X11Display(const QWidget* widget)
{
Q_UNUSED(widget)

Expand Down
43 changes: 26 additions & 17 deletions src/plugins/GreaseMonkey/gm_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,31 +196,40 @@ 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);

foreach (GM_Script* script, m_startScripts) {
if (script->match(urlString)) {
frame->evaluateJavaScript(m_bootstrap + script->script());
}
}

foreach (GM_Script* script, m_endScripts) {
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);
// 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)) {
mainFrame->evaluateJavaScript(m_bootstrap + script->script());
}
}

foreach (GM_Script* script, m_endScripts) {
if (script->match(urlString)) {
const QString &jscript = QString("window.addEventListener(\"DOMContentLoaded\","
"function(e) { \n%1\n }, false);").arg(m_bootstrap + script->script());
mainFrame->evaluateJavaScript(jscript);
}
}
frames += frame->childFrames();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/GreaseMonkey/gm_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 567d6c7

Please sign in to comment.