summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-06-09 18:27:41 +0200
committerFlorian Bruhin <me@the-compiler.org>2021-06-09 18:27:41 +0200
commite328b08616d30b0133b838ed9a35ac6a011362d1 (patch)
treeaff6c5deba4cd0bf8e9a38ff8e8e19a52c0b59bd
parent83fb5fef860c7b7c6561df7af2213bcd661651b1 (diff)
downloadqutebrowser-e328b08616d30b0133b838ed9a35ac6a011362d1.tar.gz
qutebrowser-e328b08616d30b0133b838ed9a35ac6a011362d1.zip
Add output to :greasemonkey-reload
-rw-r--r--doc/changelog.asciidoc2
-rw-r--r--doc/help/commands.asciidoc3
-rw-r--r--qutebrowser/browser/greasemonkey.py20
3 files changed, 20 insertions, 5 deletions
diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc
index 02d388517..46c6c283a 100644
--- a/doc/changelog.asciidoc
+++ b/doc/changelog.asciidoc
@@ -29,6 +29,8 @@ Changed
~~~~~~~
- The `fonts.web.*` settings now support URL patterns.
+- The `:greasemonkey-reload` command now shows a list of loaded scripts and has
+ a new `--quiet` switch to suppress that message.
[[v2.2.3]]
v2.2.3 (2021-06-01)
diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc
index d8a6e761c..f570a3ffd 100644
--- a/doc/help/commands.asciidoc
+++ b/doc/help/commands.asciidoc
@@ -577,7 +577,7 @@ Toggle fullscreen mode.
[[greasemonkey-reload]]
=== greasemonkey-reload
-Syntax: +:greasemonkey-reload [*--force*]+
+Syntax: +:greasemonkey-reload [*--force*] [*--quiet*]+
Re-read Greasemonkey scripts from disk.
@@ -586,6 +586,7 @@ The scripts are read from a 'greasemonkey' subdirectory in qutebrowser's data or
==== optional arguments
* +*-f*+, +*--force*+: For any scripts that have required dependencies, re-download them.
+* +*-q*+, +*--quiet*+: Suppress message after loading scripts.
[[help]]
=== help
diff --git a/qutebrowser/browser/greasemonkey.py b/qutebrowser/browser/greasemonkey.py
index c1574aed1..2ec6c9400 100644
--- a/qutebrowser/browser/greasemonkey.py
+++ b/qutebrowser/browser/greasemonkey.py
@@ -32,7 +32,7 @@ from typing import cast, List, Sequence
from PyQt5.QtCore import pyqtSignal, QObject, QUrl
from qutebrowser.utils import (log, standarddir, jinja, objreg, utils,
- javascript, urlmatch, version, usertypes)
+ javascript, urlmatch, version, usertypes, message)
from qutebrowser.api import cmdutils
from qutebrowser.browser import downloads
from qutebrowser.misc import objects
@@ -266,7 +266,7 @@ class GreasemonkeyManager(QObject):
self.load_scripts()
- def load_scripts(self, *, force=False):
+ def load_scripts(self, *, force: bool = False) -> List[GreasemonkeyScript]:
"""Re-read Greasemonkey scripts from disk.
The scripts are read from a 'greasemonkey' subdirectory in
@@ -275,14 +275,19 @@ class GreasemonkeyManager(QObject):
Args:
force: For any scripts that have required dependencies,
re-download them.
+
+ Return:
+ A list of loaded scripts.
"""
self._run_start = []
self._run_end = []
self._run_idle = []
+ scripts = []
for scripts_dir in _scripts_dirs():
scripts_dir = os.path.abspath(scripts_dir)
log.greasemonkey.debug("Reading scripts from: {}".format(scripts_dir))
+
for script_filename in glob.glob(os.path.join(scripts_dir, '*.js')):
if not os.path.isfile(script_filename):
continue
@@ -293,7 +298,10 @@ class GreasemonkeyManager(QObject):
if not script.name:
script.name = script_filename
self.add_script(script, force)
+ scripts.append(script)
+
self.scripts_reloaded.emit()
+ return sorted(scripts, key=lambda script: script.name)
def add_script(self, script, force=False):
"""Add a GreasemonkeyScript to this manager.
@@ -426,7 +434,7 @@ class GreasemonkeyManager(QObject):
@cmdutils.register()
-def greasemonkey_reload(force=False):
+def greasemonkey_reload(force: bool = False, quiet: bool = False) -> None:
"""Re-read Greasemonkey scripts from disk.
The scripts are read from a 'greasemonkey' subdirectory in
@@ -435,8 +443,12 @@ def greasemonkey_reload(force=False):
Args:
force: For any scripts that have required dependencies,
re-download them.
+ quiet: Suppress message after loading scripts.
"""
- gm_manager.load_scripts(force=force)
+ scripts = gm_manager.load_scripts(force=force)
+ names = '\n'.join(script.name for script in scripts)
+ if not quiet:
+ message.info(f"Loaded scripts:\n\n{names}")
def init():