NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Chain alert // @namespace http://tampermonkey.net/ // @version 0.6 // @description Alert when time left under set times // @author Ahab [1735214] // @include *torn.com* // @updateURL https://openuserjs.org/meta/Ahab/Chain_alert.meta.js // @license MIT // ==/UserScript== const times = [10,15,20,25,30,35,90,120,180] var hitsOver = 1000 var audioPlayer = document.createElement('audio'); var timesNew = jQuery.extend(true, [], times) var act = 0 audioPlayer.src = 'https://www.torn.com/casino/russianRoulette/audio/bang.ogg'; audioPlayer.preload = 'auto'; if(localStorage.alertStatus === undefined){ localStorage.alertStatus = 0 } $(document).ready(function (){ $('a[class*="chain-bar___"]').after("<div id='chainAlert' style='color:rgb(153, 10, 0)'><span>Chain Alert: </span><span id='state'>Off</span></div>") if(localStorage.alertStatus == 1){ $('div[id*="chainAlert"]')[0].style.color = 'rgb(61, 153, 0)' $('span[id*="state"]').text('On') alert() } }) $('div[id*="chainAlert"]').on('click', function(){ if($('span[id*="state"]').text() == 'Off'){ $(this)[0].style.color = 'rgb(61, 153, 0)' $('span[id*="state"]').text('On') localStorage.alertStatus = 1 alert() } else{ $(this)[0].style.color = 'rgb(153, 10, 0)' $('span[id*="state"]').text('Off') localStorage.alertStatus = 0 } }) document.addEventListener('visibilitychange', function (event) { if (document.hidden) { act = 1 } else { act = 0 } }); function alert(){ if(localStorage.alertStatus == 1 && $('div[class*="cooldown___"]').length == 0 && act == 0){ var observerTarget = $('p[class*="bar-timeleft"]')[0]; var observerConfig = { attributes: false, childList: false, characterData: true, subtree: true }; var observer = new MutationObserver(function(mutations) { if(localStorage.alertStatus == 1 && parseInt($('p[class*="bar-value___"]')[4].innerText.split('/')[0]) > hitsOver && $('div[class*="cooldown___"]').length == 0){ $.each(times, function(index){ if(parseInt((mutations[0].target.nodeValue).split(':')[0])*60+parseInt((mutations[0].target.nodeValue.split(':')[1])) <= timesNew[index]){ audioPlayer.play(); timesNew.splice(timesNew.indexOf(timesNew[index]),1) } else if(parseInt((mutations[0].target.nodeValue).split(':')[0])*60+parseInt((mutations[0].target.nodeValue.split(':')[1])) >= 295){ timesNew = jQuery.extend(true, [], times) } }) } else{ if($('p[class*="bar-timeleft"]').length == 0){ console.log("doesn't exist"); } observer.disconnect() } }); observer.observe(observerTarget, observerConfig); } }