2016-10-20 7 views
0

Nicht die beste Methode, aber ich möchte ein Array von Objekten speichern, die type und datetime enthalten. Ich benutze es, Mail zu senden, und ich möchte nicht zu Spam-Mail, aber Grenze so eine Art sendet nur aus Mail alle 15 Minuten:Eine Liste aus einer globalen Variablen lesen und speichern

var sendMail = true; 

var emailType = "test" // set for test 

var log = [] 
var tempLog = global.get("emaillog") 

// read the log from global variables 
if (typeof tempLog !== 'undefined' && tempLog) 
{ 
    log = tempLog 
} 

// search the log 
for (var i = 0, len = log.length; i < len; i++) 
{ 
    var logElement = log[i] 
    var logElementEmailType = logElement.Type 
    var logElementEmailDateTime = logElement.DateTime 

    var dif = new Date() - logElementEmailDateTime; 

    if (logElementEmailType == emailType && Math.abs(dif/1000) < (60*5)) 
    { 
     sendMail = false 
    } 
} 

// add to log 
var newLogElement = 
{ 
    DateTime: new Date(), 
    Type: mailType 
} 

log.push(newLogElement) 

// save global variable 
global.set("maillog",log) 

Aber dies nicht, ich Spamming unten hart: D

+0

Was funktioniert nicht und wo steckst du fest? – abdulbarik

Antwort

1

Ich glaube, dass Diff in Millisekunden ist. Sie teilen es durch 1000 und erhalten Mikrosekunden.

Verwandte Themen