Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name TwitchDropFarmer
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match https://www.twitch.tv/*
- // @grant none
- // ==/UserScript==
- var DIRECTORY_URL = 'https://www.twitch.tv/directory/game/Legends%20of%20Runeterra';
- (function() {
- 'use strict';
- var nbReloads = 0;
- function stuff() {
- 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 : "";
- if (window.location.href == DIRECTORY_URL) {
- // choose a streamer
- var streams = document.getElementsByClassName('qa-stream-preview');
- var validStreams = [];
- console.log(streams.length);
- for(var i=0; i < streams.length; i++) {
- // remove vodcasts and low viewer counts (might not have quality options)
- var isVodCast = streams[i].getElementsByClassName('is-watch-party').length;
- var viewerCount = streams[i].getElementsByClassName('card__info')[0].getElementsByClassName('ember-view')[0].innerHTML.split(' ')[0];
- if(!isVodCast && viewerCount > 100) {
- validStreams.push(streams[i].getElementsByTagName('a')[0].href);
- }
- }
- if(validStreams.length) {
- // select a random stream
- window.location = validStreams[Math.floor(Math.random() * validStreams.length)];
- } else {
- // we filtered everything out... Go to #2 directly (to give a chance to get them to #1 and shuffle the streamer order a bit!)
- window.location = streams[Math.min(1, streams.length-1)].getElementsByTagName('a')[0].href;
- }
- } else if (currentGame != "Legends of Runeterra") {
- // get back to ESL!
- window.location = DIRECTORY_URL;
- } else {
- // re-evaluate every now and then and reload every few cycles incase something gets stuck
- nbReloads++;
- if(nbReloads >= 6) {
- location.reload();
- } else {
- setTimeout(stuff, 1000*60*5);
- }
- }
- }
- setTimeout(stuff, 1000*10);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement