Ejemplo n.º 1
0
    def run_userscript(self, cmd, *args: {'nargs': '*'}):
        """Run an userscript given as argument.

        Args:
            cmd: The userscript to run.
            args: Arguments to pass to the userscript.
        """
        cmd = os.path.expanduser(cmd)
        env = {
            'QUTE_MODE': 'command',
        }

        idx = self._current_index()
        tabbed_browser = self._tabbed_browser()
        if idx != -1:
            env['QUTE_TITLE'] = tabbed_browser.tabText(idx)

        webview = tabbed_browser.currentWidget()
        if webview is not None and webview.hasSelection():
            env['QUTE_SELECTED_TEXT'] = webview.selectedText()
            env['QUTE_SELECTED_HTML'] = webview.selectedHtml()

        try:
            url = tabbed_browser.current_url()
        except qtutils.QtValueError:
            pass
        else:
            env['QUTE_URL'] = url.toString(QUrl.FullyEncoded)

        userscripts.run(cmd, *args, win_id=self._win_id, env=env)
Ejemplo n.º 2
0
    def run_userscript(self, cmd, *args: {'nargs': '*'}):
        """Run an userscript given as argument.

        Args:
            cmd: The userscript to run.
            args: Arguments to pass to the userscript.
        """
        cmd = os.path.expanduser(cmd)
        env = {
            'QUTE_MODE': 'command',
        }

        idx = self._current_index()
        tabbed_browser = self._tabbed_browser()
        if idx != -1:
            env['QUTE_TITLE'] = tabbed_browser.page_title(idx)

        webview = tabbed_browser.currentWidget()
        if webview is not None and webview.hasSelection():
            env['QUTE_SELECTED_TEXT'] = webview.selectedText()
            env['QUTE_SELECTED_HTML'] = webview.selectedHtml()

        try:
            url = tabbed_browser.current_url()
        except qtutils.QtValueError:
            pass
        else:
            env['QUTE_URL'] = url.toString(QUrl.FullyEncoded)

        userscripts.run(cmd, *args, win_id=self._win_id, env=env)
Ejemplo n.º 3
0
    def run_userscript(self, cmd, *args: {'nargs': '*'}):
        """Run an userscript given as argument.

        Args:
            cmd: The userscript to run.
            args: Arguments to pass to the userscript.
        """
        userscripts.run(cmd, *args, url=self._current_url())
Ejemplo n.º 4
0
    def run_userscript(self, cmd, *args: {'nargs': '*'}):
        """Run an userscript given as argument.

        Args:
            cmd: The userscript to run.
            args: Arguments to pass to the userscript.
        """
        userscripts.run(cmd, *args, url=self._current_url(),
                        win_id=self._win_id)
Ejemplo n.º 5
0
    def _call_userscript(self, url, context):
        """Call an userscript from a hint.

        Args:
            url: The URL to open as a QUrl.
            context: The HintContext to use.
        """
        cmd = context.args[0]
        args = context.args[1:]
        userscripts.run(cmd, *args, url=url, win_id=self._win_id)
Ejemplo n.º 6
0
    def _call_userscript(self, url, context):
        """Call an userscript from a hint.

        Args:
            url: The URL to open as a QUrl.
            context: The HintContext to use.
        """
        cmd = context.args[0]
        args = context.args[1:]
        userscripts.run(cmd, *args, url=url, win_id=self._win_id)
Ejemplo n.º 7
0
    def _call_userscript(self, elem, context):
        """Call a userscript from a hint.

        Args:
            elem: The QWebElement to use in the userscript.
            context: The HintContext to use.
        """
        cmd = context.args[0]
        args = context.args[1:]
        frame = context.mainframe
        env = {"QUTE_MODE": "hints", "QUTE_SELECTED_TEXT": str(elem), "QUTE_SELECTED_HTML": elem.toOuterXml()}
        url = self._resolve_url(elem, context.baseurl)
        if url is not None:
            env["QUTE_URL"] = url.toString(QUrl.FullyEncoded)
        env.update(userscripts.store_source(frame))
        userscripts.run(cmd, *args, win_id=self._win_id, env=env)
Ejemplo n.º 8
0
    def _call_userscript(self, elem, context):
        """Call an userscript from a hint.

        Args:
            elem: The QWebElement to use in the userscript.
            context: The HintContext to use.
        """
        cmd = context.args[0]
        args = context.args[1:]
        env = {
            'QUTE_MODE': 'hints',
            'QUTE_SELECTED_TEXT': str(elem),
            'QUTE_SELECTED_HTML': elem.toOuterXml(),
        }
        url = self._resolve_url(elem, context.baseurl)
        if url is not None:
            env['QUTE_URL'] = url.toString(QUrl.FullyEncoded)
        userscripts.run(cmd, *args, win_id=self._win_id, env=env)
Ejemplo n.º 9
0
    def _call_userscript(self, elem, context):
        """Call an userscript from a hint.

        Args:
            elem: The QWebElement to use in the userscript.
            context: The HintContext to use.
        """
        cmd = context.args[0]
        args = context.args[1:]
        env = {
            'QUTE_MODE': 'hints',
            'QUTE_SELECTED_TEXT': str(elem),
            'QUTE_SELECTED_HTML': elem.toOuterXml(),
        }
        url = self._resolve_url(elem, context.baseurl)
        if url is not None:
            env['QUTE_URL'] = url.toString(QUrl.FullyEncoded)
        userscripts.run(cmd, *args, win_id=self._win_id, env=env)
Ejemplo n.º 10
0
 def _call_userscript(self, url):
     """Call an userscript from a hint."""
     cmd = self._context.args[0]
     args = self._context.args[1:]
     userscripts.run(cmd, *args, url=url, win_id=self._win_id)
Ejemplo n.º 11
0
 def _call_userscript(self, url):
     """Call an userscript from a hint."""
     qtutils.ensure_valid(url)
     cmd = self._context.args[0]
     args = self._context.args[1:]
     userscripts.run(cmd, *args, url=url)
Ejemplo n.º 12
0
 def _call_userscript(self, url):
     """Call an userscript from a hint."""
     cmd = self._context.args[0]
     args = self._context.args[1:]
     userscripts.run(cmd, *args, url=url, win_id=self._win_id)