SHARE
TWEET

Thimen Timers

a guest Dec 3rd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Thimen24 Timers
  3. // @author      NepSuss
  4. // @version     1
  5. // @grant       none
  6. // @include     http*://www.twitch.tv/thimen24*
  7. // @include     https://www.twitch.tv/popout/thimen24/*
  8. // ==/UserScript==
  9.  
  10. //Put the commands you want timer for inside here.
  11. //Don't include '!'
  12. const cooldowns = {
  13. /*command: cooldown(in minutes)*/
  14.     'gamble': 5,
  15.     'heist': 7,
  16.     'give': 1,
  17.     'request': 1
  18. };
  19.  
  20.  
  21. /*DO NOT CHANGE ANYTHING BELOW THIS POINT IF YOU DON'T KNOW WHAT YOU ARE DOING*/
  22.  
  23. window.onload = ()=>{// When page is fully loaded
  24.     //Find known elements on the page
  25.     const $chatMsg = document.querySelector('textarea[data-a-target=chat-input]');
  26.     const $sndBtn = document.querySelector('button[data-a-target=chat-send-button]');
  27.     const $container = document.querySelector('div[data-test-selector=chat-input-buttons-container]');
  28.  
  29.     //Create our own tiemer element
  30.     const $timerDiv = document.createElement('div');
  31.     $timerDiv.className = "tw-align-content-center tw-align-items-center tw-flex tw-flex-row";
  32.     $container.insertBefore($timerDiv, $container.children[$container.children.length-1]);
  33.  
  34.     //Functuon for updating color
  35.     const updateColor = () => {
  36.         let cmd = $chatMsg.value.match(RegExp("^!("+Object.keys(cooldowns).join('|')+")"));
  37.         if(cmd){
  38.             localStorage[cmd[1]] = Date.now() + (cooldowns[cmd[1]] * 6e4);
  39.             let el = document.getElementById(cmd[1]);
  40.             el.style.color = "darkred";
  41.             el.style.fontWeight = "normal";
  42.         }
  43.     };
  44.  
  45.     //For each of the commands defined in 'cooldowns'
  46.     Object.keys(cooldowns).forEach(e=>{
  47.  
  48.         //If localstorage[command] is undefined
  49.         if(!localStorage[e]){
  50.             //Set it to max cooldown the first time the script is ran
  51.             localStorage[e] = Date.now() + cooldowns[e] * 6e4;
  52.         }
  53.  
  54.         //Creation of a div element for this command
  55.         let el = document.createElement('div');
  56.  
  57.         //Set attributes for the command element
  58.         el.id = e;
  59.         el.className = "tw-relative";
  60.         el.innerText = "!"+e;
  61.         el.style.margin = "0 .5em";
  62.         el.style.color = localStorage[e] > Date.now() ? 'darkred':'green';
  63.         el.style.fontWeight = localStorage[e] > Date.now() ? 'normal':'bold';
  64.  
  65.         //Append this element to our timer element
  66.         $timerDiv.appendChild(el);
  67.     });
  68.  
  69.     //Attatch eventlisteners
  70.     $sndBtn.addEventListener('click',updateColor);//If the purple "Chat" button is clicked, run the updateColor function
  71.     $chatMsg.addEventListener('keydown', e=>{//If a key is pressed inside the textarea  (chat-input)
  72.         if(e.keyCode === 13) updateColor(); //If te keycode is 13 (Enter key is pressed), run the updateColor function
  73.     });
  74.  
  75.     setInterval(()=>{//Run theese lines for all the command divs in an interval of 1000ms (1e3)
  76.         Object.keys(cooldowns).forEach(e=>{
  77.             if(localStorage[e] < Date.now()){
  78.                 let el = document.getElementById(e);
  79.                 el.style.color = "green";
  80.                 el.style.fontWeight = "bold";
  81.             }
  82.         });
  83.     },1e3);
  84. };
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