开发者

Trying to Detect Characters to determine if Page Should Reload, or not. (Safari Extension)

开发者 https://www.devze.com 2023-01-25 00:37 出处:网络
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

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 i开发者_StackOverflow社区s created */
    clearTimeout(timer);
}


Your code is wonky. Instead of else, you need else if.

Of course, you could set the timer only if both conditions are set (instead of setting the timer, then clearing it):

if (location.host == "mail.exmx.net" && location.href.indexOf("?ae=Item&t=IPM.Note&a=New") == -1) {

    /* 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*/ );
}
0

精彩评论

暂无评论...
验证码 换一张
取 消