var page_actions = []; page_actions.push('home'); page_actions.push('catalog'); page_actions.push('product'); page_actions.push('cart'); page_actions.push('cart_not_empty'); function code() { if(!verifyAction()) return; var original_favicon = ($('link[rel="shortcut icon"]').length) ? $('link[rel="shortcut icon"]').attr('href') : 'https://tab.sellerboard.io/img/favicon.png'; var favicon = 'data:image/svg+xml,😌' ; var original_title = document.title; var message = 'You forgot something here!'; var number = 1; var second_message = 'Come back!' ; function createWorker(main){ var blob = new Blob( ["(" + main.toString() + ")(self)"], {type: "text/javascript"} ); return new Worker(window.URL.createObjectURL(blob)); } var worker = createWorker(function(self){ setInterval(function(){ self.postMessage(Date.now()); }, (parseInt(5) * 120 + 200)); }); worker.onmessage = function(e) { if(!document.hasFocus()){ document.title = number == 1 ? message : second_message; number = number == 1 ? 2 : 1; } else { document.title = original_title; } } $(window).blur(function() { if($('link[rel="shortcut icon"]').length) { $('link[rel="shortcut icon"]').attr('href', favicon); } else { var headTag = document.getElementsByTagName("head")[0]; var linkTag = document.createElement('link'); linkTag.rel = 'shortcut icon'; linkTag.href = favicon; headTag.appendChild(linkTag); } }); $(window).focus(function() { $('link[rel="shortcut icon"]').attr('href', original_favicon); setTimeout(function() { document.title = original_title; }, 900); }); } function time_format(seconds) { var minutes = Math.floor((seconds % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((seconds % (1000 * 60)) / 1000); if(minutes < 10) { minutes = '0' + minutes; } if(seconds < 10) { seconds = '0' + seconds; } return minutes + ':' + seconds; } function verifyAction() { if(jQuery.inArray( 'home', page_actions) !== -1 && location.pathname == '/') { return true; } else if (jQuery.inArray( 'product', page_actions) !== -1 && location.pathname.indexOf('/products/') !== -1) { return true; } else if (jQuery.inArray( 'catalog', page_actions) !== -1 && location.pathname.indexOf('/collections/') !== -1) { return true; } else if (jQuery.inArray( 'cart', page_actions) !== -1 && location.pathname.indexOf('/cart') !== -1) { return true; } else if (jQuery.inArray( 'cart_not_empty', page_actions) !== -1 && location.pathname.indexOf('/cart') !== -1 && $('tr.cart__row').length) { return true; } return false; } if (typeof jQuery === 'undefined') { var headTag = document.getElementsByTagName("head")[0]; var scriptTag = document.createElement('script'); scriptTag.type = 'text/javascript'; scriptTag.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'; scriptTag.onload = code; headTag.appendChild(scriptTag); } else { code(); }