Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save krabs-github/1af5a566b6c2e764c009aa8a73da242f to your computer and use it in GitHub Desktop.
Save krabs-github/1af5a566b6c2e764c009aa8a73da242f to your computer and use it in GitHub Desktop.
[JavaScript - Set Interval and Clear Interval for Stream Deck Template] JavaScript - Set Interval and Clear Intervals for Stream Deck Template #JavaScript
// Declare globally
var vKrabs_Intervals = {};
// Functions
let vKrabs_IntervalID = JSON.stringify(jsn.context);
function startInterval(func, time) {
vKrabs_Intervals[vKrabs_IntervalID] = setInterval(func, time);
}
function stopInterval() {
clearInterval(vKrabs_Intervals[vKrabs_IntervalID]);
}
if (vKrabs_Intervals[vKrabs_IntervalID]) {
stopInterval();
startInterval(UpdateTwitchImage, 5000); // Change UpdateTwitchImage to the function you want to run in the interval
} else {
startInterval(UpdateTwitchImage, 5000); // Change UpdateTwitchImage to the function you want to run in the interval
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment