Skip to content

Instantly share code, notes, and snippets.

@tadeubdev
Created August 19, 2014 19:13
Show Gist options
  • Save tadeubdev/bbae25d3c02607ac7468 to your computer and use it in GitHub Desktop.
Save tadeubdev/bbae25d3c02607ac7468 to your computer and use it in GitHub Desktop.
// Para saber mais siga até: http://tadeubarbosa.github.io/audio-somente-em-aba-mestre/
///////
// Funções simples mas que ajudam bastante neste projeto
// Time: Gist > https://gist.github.com/tadeubarbosa/969a249e68e3ac55f341
time = function(){return new Date().getTime().toString().substring(0,10);};
// Repeat : Gist > https://gist.github.com/tadeubarbosa/57ba0b9cab817afef487
String.prototype.repeat=function(num){return new Array(num+1).join(this);}
// Random : Gist > https://gist.github.com/tadeubarbosa/f7b16de4a95204a5ebf1
random=function(rep){min=parseInt('1'.repeat(rep));max=parseInt('9'.repeat(rep));return Math.floor(Math.random()*(max-min+1))+min;}
///
////////
var app;
if ( !sessionStorage['window'] ) sessionStorage['window'] = random( 9 );
(app.fn=function(){
if( !localStorage['window'] || parseInt(localStorage['time']) < ( time()-3 ) )
{
localStorage['window'] = sessionStorage['window'];
}
app.mestre = (sessionStorage['window'] == localStorage['window']);
if( !app.mestre ) return;
localStorage['time'] = time();
})();
setInterval(function(){ app.fn(); }, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment