Greasemonkey脚本仅在重新加载页面时运行 [英] Greasemonkey script only runs when page is reloaded

查看:135
本文介绍了Greasemonkey脚本仅在重新加载页面时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

以下是一个示例网址:

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

我的匹配规则:

/^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.

推荐答案

无法确定发生了什么,因为目标页面是付费的-wall和他们所谓的免费试用机制打破了大块。

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. 初始请求是不安全的(http),但重定向到安全页面(https)。

  2. 第一页加载会执行另一种重定向到实际页面。

  3. 目标内容位于< iframe> 中,不会立即加载。

  4. 目标内容为AJAXed- in。

  5. 我们需要查看实际页面的异常情况。

  6. 初始网址并非真正以<$ c结尾$ c>更改集。

  1. The initial request is insecure (http) but redirects to a secure page (https).
  2. The first page load does a some other kind of redirect to the actual page.
  3. The target content is in an <iframe> that does not load right away.
  4. The target content is AJAXed-in.
  5. Something exotic that we would need to see the actual page to figure out.
  6. The initial URL does not really end in changesets.

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

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:

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

开始,但请参见下文。



解决方案的步骤:


Steps to a solution:


  1. 更改 @include 以考虑http以及URL中尾随空格或尾随斜杠的可能性。使用:

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

// @include  /^https?:\/\/.*\.rallydev\.com\/.*\/changesets(?:\s|\/)*$/


  • 使用 Firebug 检查页面。内容是AJAXed-in?它在< iframe> 中?如果是,iframe网址是什么?如果有的话?

  • 要检测AJAX和/或重定向,请使用 Firebug的Net面板和/或 Wireshark

  • 如果可能,请向我们提供登录凭据,以便我们看到有问题的页面。

  • 快照有问题的页面(通过Firefox保存)和链接到 Pastebin.com 中的HTML和JS。

  • 考虑使用以下代码:

  • Examine the page with Firebug. Is the content AJAXed-in? Is it in an <iframe>? If so, what is the iframe URL, if any?
  • To also detect AJAX and/or redirects, use Firebug's Net panel and/or Wireshark.
  • If possible, provide us with login credentials so that we may see a problematic page.
  • Snapshot a problematic page (Save it via Firefox) and link to that HTML and JS in Pastebin.com.
  • Consider using code like:

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

    让脚本仅在iframe中运行(或不运行),如适用。

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



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


    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".

    这篇关于Greasemonkey脚本仅在重新加载页面时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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