Advertisement
Guest User

Thimen24 Timers Grease/Tamper - Monkey

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