我怎样才能添加一个重复定时器到Firefox的插件? [英] How can I add a recurring timer to a Firefox addon?

查看:125
本文介绍了我怎样才能添加一个重复定时器到Firefox的插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新插件生成器预览(https://builder.addons.mozilla.org/)创建插件,并且我需要一个每10分钟运行一次的函数。我已经尝试了setInterval和setTimeout,但他们都返回以下错误:

I am trying to create an addon with the new addons builder preview (https://builder.addons.mozilla.org/), and I need a function to run about once every 10 minutes. I have tried both setInterval and setTimeout, but they both return the following error:

    error: An exception occurred.
Traceback (most recent call last):
  File "resource://jid0-31njasqk3btmpa6paroepuybjn4-myaddon-lib/main.js", line 41, in 
    setTimeout(function() { timedCount(); }, 10000);
ReferenceError: setTimeout is not defined

(setTimeout被setInterval替换setTimeout函数在我创建的类似网页中工作得很好,我只是调用了自己的函数来给出一个无限循环(这听起来很愚蠢,应该有一个while循环,但它是在教程中)
但是现在我无法在我的插件中找到这个错误。

(with setTimeout being replaced with setInterval when I tried it. The setTimeout function worked great in the similar webpage that I built. I just had the function call itself to give an infinite loop (It sounds stupid, there should be a while loop, but it was in a tutorial;) But now I can't get past that error in my addon.

另外,如果你能帮我解析本地或远程页面(最好是远程的,但是我可以让它在本地主机上解析一个django创建的页面,或者甚至更好,只要告诉我如何使用python;)这将是非常棒的。

Also, if you can help me parse a local or remote page in this addon (preferably remote, but I could make it parse a django-created page on localhost instead), or even better, just tell me how to use python ;) that would be great.

谢谢!

Thanks!

推荐答案

使用 timer module

Use the timer module:

var tmr = require('timer');
tmr.setInterval(timedCount, 10000); // no need for an anon function since you don't pass any arguments to your function nor capture anything in a closure

这篇关于我怎样才能添加一个重复定时器到Firefox的插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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