SHARE
TWEET

Timer with fade

a guest Dec 3rd, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Put the commands you want timer for inside here.
  2. //Don't include '!'
  3. const cooldowns = {
  4.     'gamble': 5,
  5.     'slots': 1,
  6.     'give': 1,
  7.     'request': 1
  8. };
  9.  
  10.  
  11. /*DO NOT CHANGE ANYTHING BELOW THIS POINT IF YOU DON'T KNOW WHAT YOU ARE DOING*/
  12. window.onload = ()=>{
  13.     const $chatMsg = document.querySelector('textarea[data-a-target=chat-input]');
  14.     const $sndBtn = document.querySelector('button[data-a-target=chat-send-button]');
  15.     const $container = document.querySelector('div[data-test-selector=chat-input-buttons-container]');
  16.     const $timerDiv = document.createElement('div');
  17.     const updateColor = () => {
  18.         let cmd = $chatMsg.value.match(RegExp("^!("+Object.keys(cooldowns).join('|')+")"));
  19.         if(cmd){
  20.             localStorage[cmd[1]] = Date.now() + (cooldowns[cmd[1]] * 60e3);
  21.             let el = document.getElementById(cmd[1]);
  22.             el.style.color = "darkred";
  23.             el.style.fontWeight = "bold";
  24.             el.style.backroundColor="rgba(130,0,0,.8)";
  25.         }
  26.     };
  27.    
  28.     Object.keys(cooldowns).forEach(e=>{
  29.         if(!localStorage[e]){
  30.             localStorage[e] = Date.now() + cooldowns[e] * 60e3;
  31.         }
  32.     });
  33.    
  34.     Object.keys(cooldowns).forEach(e=>{
  35.         let el = document.createElement('div');
  36.         el.id = e;
  37.         el.className = "tw-relative";
  38.         el.style.margin = "0 .5em";
  39.         el.innerText = "!"+e;
  40.         el.style.color = localStorage[e] > Date.now() ? 'darkred':'green';
  41.         el.style.fontWeight = localStorage[e] > Date.now() ? 'normal':'bold';
  42.         el.style.backgroundColor = localStorage[e] > Date.now() ? 'rgba(130,0,0,.8)':'transparent';
  43.        
  44.        
  45.         $timerDiv.appendChild(el);
  46.     });
  47.    
  48.     $timerDiv.className = "tw-align-content-center tw-align-items-center tw-flex tw-flex-row";
  49.     $container.insertBefore($timerDiv, $container.children[$container.children.length-1]);
  50.    
  51.     $sndBtn.addEventListener('click',updateColor);
  52.     $chatMsg.addEventListener('keydown', e=>{
  53.         if(e.keyCode != 13) return;
  54.         updateColor();
  55.     });
  56.    
  57.     setInterval(()=>{
  58.         Object.keys(cooldowns).forEach(e=>{
  59.             if(localStorage[e] < Date.now()){
  60.                 let el = document.getElementById(e);
  61.                 el.style.color = "green";
  62.                 el.style.fontWeight = "bold";
  63.                 el.style.backgroundColor ="transparent";
  64.             }else{
  65.                 let el = document.getElementById(e);
  66.                 var alpha = ((localStorage[e] - Date.now())/(cooldowns[e]* 60e3));
  67.                 el.style.backgroundColor = "rgba(130,0,0,"+.8*alpha+")";
  68.                  
  69.                
  70.  
  71.  
  72.             }
  73.         });
  74.     },1e3);
  75. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top