waitForKeyElements(); - 停止在Chrome扩展程序中弹出一个脚本的脚本? [英] waitForKeyElements(); - Stop a script firing on a popup in Chrome Extension?

查看:194
本文介绍了waitForKeyElements(); - 停止在Chrome扩展程序中弹出一个脚本的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是后续,需要询问和保证一个新的职位,所以请原谅,如果我提到的事情可能不清楚,没有阅读其他问题。



<当使用
waitForKeyElements()工具时,我遇到了一个问题,其中 div 包含在同一个URL中包含的小型弹出窗口中。我的扩展程序目前正在 Twitter 网站上运行,我的意图是 div 包含在个人资料页面(例如 http://twitter.com/todayshow )被移动高于另一个页面上的 div 。我通过 waitForKeyElements()执行此操作,因为使用此实用程序解决了一些加载问题。然而,在配置文件页面上,您可以单击指向其他用户名称的链接,该用户名称会弹出一个小窗口(位于同一窗口/选项卡中,同一网址内)关于他们的一些信息和一些以前的推文。这里的问题是,在这个弹出框中出现相同的 div ,然后移动到弹出窗口后面的主页面,它不应该在那里。在配置文件页面上,这可以通过将 false 参数插入 waitForKeyElements()来停止,但是在非-profile页面仍然可以激活这个弹出窗口,然后移动到主页面上,因为 div 我希望在配置文件页面上移动它,造成明确的问题。



我想知道是否有解决方法,例如 Chrome中的错误阻止我排除这些页面。到目前为止(只是头脑风暴)我在考虑: div c>不存在开始,创建一个空的意思 false 将处理该问题。

  • 以某种方式停止脚本虽然由于Twitter的工作方式,这将不得不监视 OnClick()和页面URL(我认为),我不确定该怎么做。
  • 当弹出窗口出现时停止运行,但我几乎不知道从哪里开始。



  • 任何帮助表示赞赏。任何与此问题相关的必要代码都可以在前两个链接中找到,而我正面临的问题可以通过快速访问Twitter来查看。



    编辑:当插入 false 参数时,它可以在通过URL栏直接转到配置文件时起作用,如果您在配置文件中并使用链接得到一个配置文件,脚本没有插入,我的扩展失败。所以这也需要解决,或完全替代方法。

    解决方案

    我有一个脑波,可以使用 insertAfter()插入< div> 我最初在< div> 我原本是在移动。这个< div> 没有出现在弹出框中,这意味着当它不应该出现时,任何内容都不会移动到后台页面上。



    关于上一个问题,我的代码现在简单地表示:

      waitForKeyElements(
    你想移动div的sj选择器,//与它相反的
    moveSelectDivs
    );

    function moveSelectDivs(jNode){
    jNode.insertAfter(APPROPRIATE JQUERY SELECTOR); //再次,相反。
    }

    这解决了我遇到的问题,我的扩展现在可以正常工作,但是我会留下这个问题,以防将来有人回来。


    This question is a follow-on to another question which needed asking and warranted a new post, so excuse me if I refer to things which may not be clear without reading the other question.

    When using the utility waitForKeyElements() I'm facing an issue in which a div is included inside a small popup contained within the same URL. My extension is currently running on the Twitter site, and my intention is that a div contained on the profile pages (e.g. http://twitter.com/todayshow) gets moved above another div on the page. I'm doing this via waitForKeyElements() because of some loading issues which are resolved by using this utility.

    However, on a profile page you can click a link to another users name which pops up a small window (inside the same window/tab, on the same URL) showing some info about them and a few previous tweets. The issue here is that the same div appears on this popup and is then moved to the main page behind the popup window, where it shouldn't be. On a profile page, this can be stopped by plugging in the false parameter to waitForKeyElements(), however on a non-profile page it is still possible to activate this popup which is then moving onto the main page, as the div I wish to move it above on a profile page still exists here, causing clear issues.

    I'm wondering if there's a way around this, as bugs in Chrome have stopped me from excluding these pages. So far (just brainstorming) I'm thinking:

    • on a page where the div doesn't exist to begin with, create an empty one meaning false will handle the issue.
    • somehow stop the script from firing on a given URL, although due to the way Twitter works this would have to monitor OnClick() and the page URL (I think) which I'm unsure how to do.
    • stop running when the popup appears, but I have almost no idea where to start with that.

    Any help is appreciated. Any necessary code related to this question can be found in the first two links, and the issue I'm facing can be seen by a quick visit to Twitter.

    EDIT: When plugging in the false param it works when going directly to profiles via the URL bar, if you're on a profile and use a link to get to a profile, the script isn't inserted and my extension fails. So this would need resolving too, or an alternative method altogether.

    解决方案

    I had a brainwave that I could use insertAfter() to insert the <div> I was originally moving in front of, after the <div> I was originally moving. This <div> is not present on the popup, which means that nothing is moved onto the back page when it shouldn't be.

    In regards to the previous question, my code is now simply:

    waitForKeyElements (
        "jQuery selector for div(s) you want to move", // Opposite to what it was.
        moveSelectDivs
    );
    
    function moveSelectDivs (jNode) {
         jNode.insertAfter ("APPROPRIATE JQUERY SELECTOR"); // Again, the opposite.
    }
    

    This solves the issue I was having and my extension is now working just fine, however I will leave this question posted in case anybody comes back to it in future.

    这篇关于waitForKeyElements(); - 停止在Chrome扩展程序中弹出一个脚本的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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