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

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

问题描述

我有这个非常基本的Greasemonkey脚本问题,很可能是元数据配置。



这是基本文件的完整来源

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

alert(hi google!);

当我访问Google.com时,此脚本应该运行,但不会弹出警报。什么是问题?



我正试图在Ubuntu上使用Firefox运行此脚本。

解决方案

如果 alerts()未触发,有可能您可能点击了Firefox的创建其他对话框选项,或设置浏览器首选项(旧版本的Firefox)或Firefox可能在内存中变得不稳定。



通用Greasemonkey调试步骤:



(添加了 alert ()。)


  1. 首先确保脚本甚至触发

    浏览该页面时,请点击Greasemonkey图标旁边的下三角形(或者,您可以打开工具在Firefox菜单上的em> - > Greasemonkey ),并确认出现并检查了预期的脚本名称。 EG:


  2. 查看是否有有关


  3. 打开关于:config ,搜索 capabilities.policy.default.Window.alert 并删除或


  4. 卸载Greasemonkey脚本。

  5. 完全清除浏览器缓存。

  6. 完全关闭Firefox。使用任务管理器或等效项来验证是否存在在内存中没有Firefox线程/任务/进程。

  7. 重新启动Firefox。

  8. 安装Greasemonkey脚本重新开始。

  9. 如果仍然无效,请创建一个新的Firefox个人资料,或尝试使用不同的计算机





其他问题:




  1. p> 请提供您的版本三件事:(1)操作系统,(2)Firefox,(3)Greasemonkey或Tampermonkey或Scriptish等。


  2. @include * 表示脚本将针对每个页面触发!这几乎是总是一个糟糕的做法。 (有一些例外,但你的情况不是一个例子。)


  3. @namespace 不能控制页面的运行。 @namespace 唯一允许多个脚本具有相同的名称(只要他们的 @namespace s不同)。请参阅 @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. 卸载你的脚本。 / li>
  2. 重新启动Firefox。

  3. 安装脚本:

      // == UserScript == 
    // @name Google Hello
    // @namespace John Galt
    // @description基本Google Hello
    // @match *://www.google.com/*
    // @version 1
    // @grant none
    // == / UserScript ==

    console.log(嗨Google!);


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


  5. 如果仍然有问题,请按照上述所有调试步骤进行操作。 / li>
  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天全站免登陆