Greasemonkey脚本仅在重新加载页面时运行

时间:2022-01-09 06:11:55

I am working on a Greasemonkey script to turn some text into links on a a Rally page. The script works fine only when I reload the page. If I navigate to the page in any manner (links, browser forward/back) the script does not run, despite the fact that the Greasemonkey menu shows my script at the bottom, with a checkmark.

我正在使用Greasemonkey脚本将一些文本转换为Rally页面上的链接。只有在我重新加载页面时,脚本才能正常工作。如果我以任何方式(链接,浏览器向前/向后)导航到该页面,则脚本不会运行,尽管Greasemonkey菜单在底部显示我的脚本,并带有复选标记。

Here is an example URL:

这是一个示例URL:

https://rally1.rallydev.com/#/4745909548/detail/userstory/6138899084/changesets

My matching rule:

我的匹配规则:

/^https://.*\.rallydev\.com/.*/changesets$/

I don't know if the hash is causing a problem, but everything is fine when I reload.

我不知道哈希是否会导致问题,但是当我重新加载时一切都很好。

Not sure where to go from here. Any help is appreciated.

不知道从哪里开始。任何帮助表示赞赏。

1 个解决方案

#1


8  

It's impossible to be sure what's going on, because the target page(s) are behind a pay-wall and their alleged "Free Trial" mechanism blows chunks.

无法确定发生了什么,因为目标页面位于付费墙后面,他们所谓的“免费试用”机制会破坏大块。

Here are some possible causes of the current behavior:

以下是当前行为的一些可能原因:

  1. The initial request is insecure (http) but redirects to a secure page (https).
  2. 初始请求是不安全的(http),但重定向到安全页面(https)。

  3. The first page load does a some other kind of redirect to the actual page.
  4. 第一页加载会执行其他类型的重定向到实际页面。

  5. The target content is in an <iframe> that does not load right away.
  6. 目标内容位于

  7. The target content is AJAXed-in.
  8. 目标内容是AJAXed-in。

  9. Something exotic that we would need to see the actual page to figure out.
  10. 我们需要看到实际页面才能找到的异国情调。

  11. The initial URL does not really end in changesets.
  12. 初始URL并未真正以变更集结束。

Also, get into the habit of escaping the /s in the middle of regular expressions. It's not always needed, but it will eventually bite you in the [censored] if you don't. So the script should use:

另外,养成在正则表达式中间转义/ s的习惯。它并不总是需要,但如果你不这样做,它最终会在[审查]中咬你。所以脚本应该使用:

// @include  /^https:\/\/.*\.rallydev\.com\/.*\/changesets$/

to start, but see below.

开始,但见下文。


Steps to a solution:

解决方案的步骤:

  1. Change your @include to account for http and the Possibility of trailing space or trailing slash in the URL. Use:

    将您的@include更改为http帐户以及URL中尾随空格或尾随斜杠的可能性。使用:

    // @include  /^https?:\/\/.*\.rallydev\.com\/.*\/changesets(?:\s|\/)*$/
    
  2. Examine the page with Firebug. Is the content AJAXed-in? Is it in an <iframe>? If so, what is the iframe URL, if any?
  3. 使用Firebug检查页面。内容是AJAXed-in吗?它在

  4. To also detect AJAX and/or redirects, use Firebug's Net panel and/or Wireshark.
  5. 要同时检测AJAX和/或重定向,请使用Firebug的Net面板和/或Wireshark。

  6. If possible, provide us with login credentials so that we may see a problematic page.
  7. 如果可能,请向我们提供登录凭据,以便我们可以看到有问题的页面。

  8. Snapshot a problematic page (Save it via Firefox) and link to that HTML and JS in Pastebin.com.
  9. 快照一个有问题的页面(通过Firefox保存)并链接到Pastebin.com中的HTML和JS。

  10. Consider using code like:

    考虑使用以下代码:

    if (window.top != window.self) {
        //--- Don't run on/in frames or iframes.
        return;
    }
    

    To have the script run only in (or not in) iframes, as applicable.

    让脚本仅在(或非在)iframe中运行,如果适用的话。


If the problem is caused by AJAX delays (or loading of new content), get around that by using the waitForKeyElements() utility as shown in "Fire Greasemonkey script on AJAX request".

如果问题是由AJAX延迟(或加载新内容)引起的,请使用waitForKeyElements()实用程序来解决这个问题,如“AJAX请求中的Fire Greasemonkey脚本”所示。

#1


8  

It's impossible to be sure what's going on, because the target page(s) are behind a pay-wall and their alleged "Free Trial" mechanism blows chunks.

无法确定发生了什么,因为目标页面位于付费墙后面,他们所谓的“免费试用”机制会破坏大块。

Here are some possible causes of the current behavior:

以下是当前行为的一些可能原因:

  1. The initial request is insecure (http) but redirects to a secure page (https).
  2. 初始请求是不安全的(http),但重定向到安全页面(https)。

  3. The first page load does a some other kind of redirect to the actual page.
  4. 第一页加载会执行其他类型的重定向到实际页面。

  5. The target content is in an <iframe> that does not load right away.
  6. 目标内容位于

  7. The target content is AJAXed-in.
  8. 目标内容是AJAXed-in。

  9. Something exotic that we would need to see the actual page to figure out.
  10. 我们需要看到实际页面才能找到的异国情调。

  11. The initial URL does not really end in changesets.
  12. 初始URL并未真正以变更集结束。

Also, get into the habit of escaping the /s in the middle of regular expressions. It's not always needed, but it will eventually bite you in the [censored] if you don't. So the script should use:

另外,养成在正则表达式中间转义/ s的习惯。它并不总是需要,但如果你不这样做,它最终会在[审查]中咬你。所以脚本应该使用:

// @include  /^https:\/\/.*\.rallydev\.com\/.*\/changesets$/

to start, but see below.

开始,但见下文。


Steps to a solution:

解决方案的步骤:

  1. Change your @include to account for http and the Possibility of trailing space or trailing slash in the URL. Use:

    将您的@include更改为http帐户以及URL中尾随空格或尾随斜杠的可能性。使用:

    // @include  /^https?:\/\/.*\.rallydev\.com\/.*\/changesets(?:\s|\/)*$/
    
  2. Examine the page with Firebug. Is the content AJAXed-in? Is it in an <iframe>? If so, what is the iframe URL, if any?
  3. 使用Firebug检查页面。内容是AJAXed-in吗?它在

  4. To also detect AJAX and/or redirects, use Firebug's Net panel and/or Wireshark.
  5. 要同时检测AJAX和/或重定向,请使用Firebug的Net面板和/或Wireshark。

  6. If possible, provide us with login credentials so that we may see a problematic page.
  7. 如果可能,请向我们提供登录凭据,以便我们可以看到有问题的页面。

  8. Snapshot a problematic page (Save it via Firefox) and link to that HTML and JS in Pastebin.com.
  9. 快照一个有问题的页面(通过Firefox保存)并链接到Pastebin.com中的HTML和JS。

  10. Consider using code like:

    考虑使用以下代码:

    if (window.top != window.self) {
        //--- Don't run on/in frames or iframes.
        return;
    }
    

    To have the script run only in (or not in) iframes, as applicable.

    让脚本仅在(或非在)iframe中运行,如果适用的话。


If the problem is caused by AJAX delays (or loading of new content), get around that by using the waitForKeyElements() utility as shown in "Fire Greasemonkey script on AJAX request".

如果问题是由AJAX延迟(或加载新内容)引起的,请使用waitForKeyElements()实用程序来解决这个问题,如“AJAX请求中的Fire Greasemonkey脚本”所示。