Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TwitchDropFarmer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://www.twitch.tv/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. var DIRECTORY_URL = 'https://www.twitch.tv/directory/game/Legends%20of%20Runeterra';
  12.  
  13. (function() {
  14. 'use strict';
  15. var nbReloads = 0;
  16.  
  17. function stuff() {
  18. var currentGame = document.querySelector('.font-size-5.pd-l-05.ember-view[data-tt_content]') ? document.querySelector('.font-size-5.pd-l-05.ember-view[data-tt_content]').innerHTML : "";
  19.  
  20. if (window.location.href == DIRECTORY_URL) {
  21. // choose a streamer
  22. var streams = document.getElementsByClassName('qa-stream-preview');
  23. var validStreams = [];
  24.  
  25. console.log(streams.length);
  26. for(var i=0; i < streams.length; i++) {
  27. // remove vodcasts and low viewer counts (might not have quality options)
  28. var isVodCast = streams[i].getElementsByClassName('is-watch-party').length;
  29. var viewerCount = streams[i].getElementsByClassName('card__info')[0].getElementsByClassName('ember-view')[0].innerHTML.split(' ')[0];
  30.  
  31. if(!isVodCast && viewerCount > 100) {
  32. validStreams.push(streams[i].getElementsByTagName('a')[0].href);
  33. }
  34. }
  35.  
  36. if(validStreams.length) {
  37. // select a random stream
  38. window.location = validStreams[Math.floor(Math.random() * validStreams.length)];
  39. } else {
  40. // we filtered everything out... Go to #2 directly (to give a chance to get them to #1 and shuffle the streamer order a bit!)
  41. window.location = streams[Math.min(1, streams.length-1)].getElementsByTagName('a')[0].href;
  42. }
  43. } else if (currentGame != "Legends of Runeterra") {
  44. // get back to ESL!
  45. window.location = DIRECTORY_URL;
  46. } else {
  47. // re-evaluate every now and then and reload every few cycles incase something gets stuck
  48. nbReloads++;
  49. if(nbReloads >= 6) {
  50. location.reload();
  51. } else {
  52. setTimeout(stuff, 1000*60*5);
  53. }
  54. }
  55. }
  56.  
  57. setTimeout(stuff, 1000*10);
  58. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement