尝试检测字符以确定页面是否应该重新加载。 (Safari 扩展)
大家都知道,我对 JavaScript 比较陌生(而且我一直在尝试用纯 JS 做事,而不是使用 jQuery 等)。在我签约的地方,我们有一个 Exchange 服务器,我使用网络邮件客户端。
为了防止它在没有任何活动时超时,我开始组装一个 Safari 扩展,因为我可以使用一个扩展将 JS 注入到页面中。我认为这将是一个很好的练习,因为我正在从头开始学习 JS。
好吧,这部分是有效的,除了当你回复或发送新电子邮件时,所以我尝试添加第二位代码来防止这种情况,但它仍然会刷新。我不明白为什么。我将不胜感激任何帮助!如果我要回复或回复全部,我还必须添加规则,但我认为如果我能让这个工作正常,我就能让这些工作顺利进行。
这是我的代码:
if (location.host === "mail.exmx.net") {
/* The Domain is https://mail.exmx.net/owa/?ae=Folder&t=IPF.Note */
var timer = setTimeout(function() {
location.reload( );
}, 30000 /* 30 Seconds used just as a test to speed up waiting time*/ );
}
else (location.href.indexOf("?ae=Item&t=IPM.Note&a=New") != -1) {
/* my attempt at using a static part of the string that's in the location bar when a new email is created */
clearTimeout(timer);
}
Just so everyone knows, I'm relatively new to JavaScript, (and I've been trying to do things in pure JS rather than using jQuery, etc.). At a place I contract for, we have an Exchange server, I use the webmail client.
To prevent it from timing me out when there isn't any activity, I started putting together a Safari Extension since I could inject JS into a page using one. And I thought it would be a good exercise since I'm learning JS from scratch.
Well, that part of it works, except for when you're replying, or sending a new email, so I tried adding in the second bit of code to prevent that, but it still refreshes. I can't figure out why. I would appreciate any help! I am also going to have to add in rules for if I'm replying, or replying all, but I think if I can get this working, I can get those going to.
So here's my code:
if (location.host === "mail.exmx.net") {
/* The Domain is https://mail.exmx.net/owa/?ae=Folder&t=IPF.Note */
var timer = setTimeout(function() {
location.reload( );
}, 30000 /* 30 Seconds used just as a test to speed up waiting time*/ );
}
else (location.href.indexOf("?ae=Item&t=IPM.Note&a=New") != -1) {
/* my attempt at using a static part of the string that's in the location bar when a new email is created */
clearTimeout(timer);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码很奇怪。您需要
else if
,而不是else
。当然,您可以仅在两个条件都设置的情况下设置计时器(而不是设置计时器,然后清除它):
Your code is wonky. Instead of
else
, you needelse if
.Of course, you could set the timer only if both conditions are set (instead of setting the timer, then clearing it):