XF 1.5 Make javascript only work on specific dates possible?

borgqueenx

Active member
Im having some javascripts on my site (snow effect) and it works/gets called by an edit in a template file.
I want it to work on between 20 december and 20 january. is there a way to do this?
 
No.

But you could generalize it by replacing it with Date.prototype.getFullYear()

Code:
var now = Date.now();
if (now >= Date.parse(Date(now.getFullYear(), 11, 20)) && now <= Date.parse(Date(now.getFullYear() + 1, 0, 20))) {
// code
}
 
Last edited:
I've updated the code, it appears that using Date as a constructor gives a string and not a milliseconds/object. Just checked it out in the console and it works.
 
Really unrelated to this thread, but if you're going to do that snowfalling thing, it may be a good idea to create a custom user field that will let users disable that as it can get fairly annoying if you're trying to read something :)
 
this is what i have and not working currently.
<xen:require js="js/xenforo/snowfall.jquery.min.js"/>
<script>
var now = Date.now();
if (now >= Date.parse(Date(now.getFullYear(), 11, 7)) && now <= Date.parse(Date(now.getFullYear() + 1, 0, 20))) {
$(document).snowfall({flakeCount : 95, maxSpeed : 10, maxSize : 5,round : true});
}
</script>
 
Really unrelated to this thread, but if you're going to do that snowfalling thing, it may be a good idea to create a custom user field that will let users disable that as it can get fairly annoying if you're trying to read something :)
will be difficult....instead im just having the effect small/slightly so its not that intrusive.
 
will be difficult....instead im just having the effect small/slightly so its not that intrusive.
will be difficult....instead im just having the effect small/slightly so its not that intrusive.

Not difficult at all, create a custom user field with the id "disableSnowfall" and do this:

Code:
<xen:if is="!{$visitor.customFields.disableSnowfall}">
[Your JS here]
</xen:if>
 
Not difficult at all, create a custom user field with the id "disableSnowfall" and do this:

Code:
<xen:if is="!{$visitor.customFields.disableSnowfall}">
[Your JS here]
</xen:if>
still doesn't tell me everything. what javascript to put there? if i understand correctly this makes it always work or always disabled. I want it only work during my specific time, and then that the user has the option to disable it.
 
Reasons I hate JavaScript...

Code:
var now = new Date();
if (now >= new Date(now.getFullYear(), 11, 20) && now <= new Date(now.getFullYear() + 1, 0, 20)) {
// code
}

Screen Shot 2015-12-08 at 5.11.24 PM.webp
 
still doesn't tell me everything. what javascript to put there? if i understand correctly this makes it always work or always disabled. I want it only work during my specific time, and then that the user has the option to disable it.
Jake's point is that you should give the users the ability to disable it. Put the javascript between the conditional statement he provided and people can disable it if they don't want it.
 
Jake's point is that you should give the users the ability to disable it. Put the javascript between the conditional statement he provided and people can disable it if they don't want it.
currently the script is in a template logo_block. so adding it to the user's field will probaly not work. i think.
 
Back
Top Bottom