我的非常简单的 Greasemonkey 脚本没有运行? [英] My very simple Greasemonkey script is not running?

查看:40
本文介绍了我的非常简单的 Greasemonkey 脚本没有运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用这个非常基本的 Greasemonkey 脚本时遇到问题,很可能是元数据配置.

这里是基本文件的完整源

//==用户脚本==//@name 谷歌你好//@namespace https://google.com//@description 基本谷歌你好//@包括     *//@版本1//==/用户脚本==警报(嗨谷歌!");

当我访问 Google.com 时,这个脚本应该会运行,但没有弹出警报.有什么问题?

我正在尝试使用 Firefox 在 Ubuntu 上运行此脚本.

解决方案

如果 alerts() 没有触发, 您可能点击了 Firefox 的 Prevent此页面来自创建附加对话框 选项,或设置浏览器首选项(旧版本的 Firefox),否则 Firefox 可能在内存中变得不稳定.

Universal Greasemonkey 调试步骤:

(针对 alert() 的问题添加了一个步骤.)

  1. 首先确保脚本甚至为相关页面触发.
    在浏览该页面时,点击 Greasemonkey 图标旁边的向下三角形(或者,您可以在 Firefox 上打开 Tools -> Greasemonkey菜单.)并验证是否出现并选中了预期的脚本名称.例如:

  2. 查看

  3. 打开 about:config,搜索 capability.policy.default.Window.alert 并删除或重置该值(如果找到).p>

  4. 卸载 Greasemonkey 脚本.
  5. 彻底清除浏览器缓存.
  6. 完全关闭 Firefox.使用任务管理器或等效工具来验证内存中没有 Firefox 线程/任务/进程.
  7. 重新启动 Firefox.
  8. 重新安装 Greasemonkey 脚本.
  9. 如果它仍然不起作用,请创建一个新的 Firefox 配置文件或完全尝试不同的计算机.

其他问题:

  1. 请提供以下三个方面的版本:(1) 操作系统,(2) Firefox,(3) Greasemonkey 或 Tampermonkey 或 Scriptish 等.

  2. @include * 意味着脚本将为每个页面触发!这几乎总是一种糟糕的做法.(有一些例外,但您的情况不是一个.)

  3. @namespace 不控制页面的运行位置. @namespace 唯一能做的就是允许多个脚本具有相同的名称(只要它们的 @namespace 不同).请参阅@namespace 文档.

  4. 避免使用 alert() 进行调试.这很烦人,可以掩盖计时问题.
    使用console.log().您可以浏览器控制台上查看结果和有用的错误消息(提示、提示).

  5. Google 几乎总是使用/重定向到 www.google.com(适用于美国英语用户).因此,//@include https://google.com 几乎永远不会像您想要的那样工作.

    推荐您使用:

    //@match *://www.google.com/*

    作为起点.

    在 Firefox Greasemonkey 中,您还可以使用神奇的 .tld 来支持大多数 Google 的国际域,如下所示:

    //@include http://www.google.tld/*//@include https://www.google.tld/*

    使用两行.请注意,它的性能不如 @match 行.因此,如果您只关心一个国家/地区,只需使用 @match.

<小时>

综合起来:

  1. 卸载您的脚本.
  2. 重新启动 Firefox.
  3. 安装这个脚本:

    //==用户脚本==//@name 谷歌你好//@namespace John Galt//@description 基本谷歌你好//@match *://www.google.com/*//@版本1//@grant 无//==/用户脚本==console.log ("嗨谷歌!");

  4. 访问 Google 并注意 Firefox 浏览器控制台上的结果.

  5. 如果仍有问题,请按照上述所有调试步骤进行操作.
  6. 如果仍有问题,请打开一个新问题并提供以下所有内容:

    1. 上面提到的三个版本.
    2. 您在浏览器控制台上收到的相关错误和消息.
    3. 复制问题所需的确切代码和步骤.为此制作一个MCVE!
    4. 简要总结您尝试解决的问题.

I am having issues with this very basic Greasemonkey script, most likely with the metadata configuration.

Here is the full source of the basic file

// ==UserScript==
// @name        Google Hello
// @namespace   https://google.com
// @description Basic Google Hello
// @include     *
// @version     1
// ==/UserScript==

alert("hi google!");

This script should run when I access Google.com, but the alert is not popping up. What is the issue?

I am attempting to run this script on Ubuntu with Firefox.

解决方案

If alerts() are not firing, chances are you may have clicked Firefox's Prevent this page from creating additional dialogs option, or set a browser preference (older versions of Firefox), or Firefox may have become unstable in memory.

Universal Greasemonkey debug steps:

(With one step added for problems with alert().)

  1. First make sure that the script is even firing for the page in question.
    While browsing that page, click on the down-triangle next to the Greasemonkey icon (Alternatively, you can Open Tools -> Greasemonkey on the Firefox menu.) and verify that the expected script name appears and is checked. EG:

  2. See if there are any relevant messages/errors on Firefox's Browser Console.
    Activate the console by pressing CtrlShiftJ, or equivalent.

    Here's a screenshot showing how both messages and errors appear in the Browser Console -- caused by both the web page and the Greasemonkey script:

  3. Open about:config, search for capability.policy.default.Window.alert and delete or reset the value, if it is found.

  4. Uninstall the Greasemonkey script.
  5. Completely clear the browser cache.
  6. Shutdown Firefox completely. Use Task Manager, or equivalent, to verify that there is no Firefox thread/task/process in memory.
  7. Restart Firefox.
  8. Install the Greasemonkey script afresh.
  9. If it still doesn't work, create a new Firefox profile or try a different computer altogether.

Additional issues:

  1. Please supply your versions of three things: (1) The OS, (2) Firefox, (3) Greasemonkey or Tampermonkey or Scriptish, etc.

  2. @include * means that the script will fire for every page! This is almost always a poor practice. (There are some exceptions, but your case is not one.)

  3. @namespace does not control where the page runs. The only thing @namespace does is allow more than one script to have the same name (as long as their @namespaces are different). See the @namespace documentation.

  4. Avoid using alert() for debugging. It's annoying and can mask timing problems.
    Use console.log(). You can see the results, and helpful error messages (hint, hint) on the Browser Console.

  5. Google almost always uses/redirects to www.google.com (For English USA users). So, // @include  https://google.com will almost never work like you want.

    Recommend you use:

    // @match  *://www.google.com/*
    

    as a starting point.

    In Firefox Greasemonkey, you can also use the magic .tld to support most of Google's international domains, like so:

    // @include  http://www.google.tld/*
    // @include  https://www.google.tld/*
    

    Use both lines. Note that this does not perform as well as the @match line does. So, if you only care about one nation/locale, just use @match.


Putting it all together:

  1. Uninstall your script.
  2. Restart Firefox.
  3. Install this script:

    // ==UserScript==
    // @name        Google Hello
    // @namespace   John Galt
    // @description Basic Google Hello
    // @match       *://www.google.com/*
    // @version     1
    // @grant       none
    // ==/UserScript==
    
    console.log ("Hi Google!");
    

  4. Visit Google and note the results on Firefox's Browser Console.

  5. If there is still a problem, follow all of the debug steps above.
  6. If there is still a problem, Open a new question and supply ALL of the following:

    1. The three versions, mentioned above.
    2. The relevant errors and messages you get on the Browser Console.
    3. The exact code and steps needed to duplicate the problem. Make an MCVE for this!
    4. A short summary of what you have tried to solve the problem.

这篇关于我的非常简单的 Greasemonkey 脚本没有运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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