如何将书签转换为Greasemonkey用户脚本? [英] How to convert a bookmarklet into a Greasemonkey userscript?

查看:163
本文介绍了如何将书签转换为Greasemonkey用户脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种简单的方法可以做到这一点。有没有什么需要改变的,因为它的运行方式不同?

Is there a easy way to do this. And is there anything that needs to be changed due to differences in how it is ran?

推荐答案

最简单的方法:


  1. 通过 URL解码器。所以 javascript:alert%20('Hi%20Boss!')%3B ,例如,变为:

    javascript :alert('Hi Boss!');

  1. Run the bookmarklet code through a URL decoder. so that javascript:alert%20('Hi%20Boss!')%3B, for example, becomes:
    javascript:alert ('Hi Boss!');

去除前导 javascript:关闭。结果: alert('Hi Boss!');

Strip the leading javascript: off.   Result: alert ('Hi Boss!');

将此代码添加到您的结尾Greasemonkey文件。例如,使用以下代码创建名为

Hello World.user.js 的文件:

Add this code to the end of your Greasemonkey file. For example, create a file named,
Hello World.user.js, with this code:

// ==UserScript==
// @name            Hello World!
// @description     My first GM script from a bookmarklet
// @include         https://stackoverflow.com/questions/*
// @grant           none
// ==/UserScript==

alert ('Hi Boss!');


  • 打开 Hello World.user.js 使用Firefox( Ctrl O )。 Greasemonkey将提示安装脚本。

  • Open Hello World.user.js with Firefox (CtrlO ).   Greasemonkey will prompt to install the script.

    现在,bookmarklet代码将在您使用 @include @exclude 指令。

    Now the bookmarklet code will run automatically on whatever pages you specified with the @include and @exclude directives.

    更新要确保最大兼容性,请使用在以后版本的Greasemonkey和Tampermonkey中添加的 @grant none 指令。

    Update: To ensure maximum compatibility, use the @grant none directive that was added in later versions of Greasemonkey and Tampermonkey.






    重要提示:


    IMPORTANT:


    • 用户脚本将比激活书签更快地运行。通常,这不是问题。

    • The userscript will run much sooner than you could ever activate a bookmark. Normally, this is not a problem.

    但在某些情况下,您可能需要等待页面的某些部分完全加载

    在这种情况下,您可以使用 waitForKeyElements <等技术/工具/ a>。

    But in some cases, you might need to wait for some part of the page to fully load.
    In that case, you can use techniques/utilities like waitForKeyElements.

    另请参阅在AJAX驱动的网站上选择并激活正确的控件

    如果仍然无法使用新脚本,请务必阅读我非常简单的Greasemonkey脚本没有运行?。在您打开的有关新脚本问题的任何问题中,请按照步骤和包含指定信息

    If you still can't get your new script to work, be sure to read My very simple Greasemonkey script is not running?. Follow the steps and include the specified information in any question you open about problems with the new script.

    这篇关于如何将书签转换为Greasemonkey用户脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆