Skip to content

Instantly share code, notes, and snippets.

@nielsnuebel
Created September 8, 2016 10:06
Show Gist options
  • Select an option

  • Save nielsnuebel/f27ee60a315f01574f8258a574afa219 to your computer and use it in GitHub Desktop.

Select an option

Save nielsnuebel/f27ee60a315f01574f8258a574afa219 to your computer and use it in GitHub Desktop.
// Restart GIFs (doesn't work in Firefox)
if( /\.gif/i.test( backgroundImageURL ) ) {
var searchstring = '.gif?currenttime=';
var timestamp = Math.floor(Date.now() / 1000)
var position = backgroundImageURL.indexOf(searchstring);
if(position !== -1) {
var oldtimestamp = backgroundImageURL.substr(position + searchstring.length, timestamp.length);
backgroundImageURL = backgroundImageURL.replace(oldtimestamp,timestamp);
}
else {
backgroundImageURL = backgroundImageURL.replace('.gif', searchstring + timestamp);
}
currentBackground.style.backgroundImage = backgroundImageURL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment