Twitch bot detector

Запрашивает у апи твича количество зрителей и юзеров чата, сравнивая показатели

As of 2017-01-16. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Twitch bot detector
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Запрашивает у апи твича количество зрителей и юзеров чата, сравнивая показатели
// @author       Андрей Д
// @match        https://www.twitch.tv/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

var viewers = 0;
var chatters = 0;

var xhr = new XMLHttpRequest();

function connect(channel_name){
    var theUrl = 'https://api.twitch.tv/kraken/streams/'+channel_name;
$.ajax({
        url: theUrl,
        dataType: "jsonp",
        success: function( response ) {
            var viewerlist = response.stream.viewers;
            viewers = viewerlist;
            if(viewerlist !== ""){
                console.log('#######################################'+'\nЗрителей '+viewers);
            }else{
                  console.log("Не могу получить чаттеров");
            }
        }
    });
}

function chat (name){
var theUrl = 'https://tmi.twitch.tv/group/user/'+name+'/chatters';
$.ajax({
        url: theUrl,
        dataType: "jsonp",
        success: function( response ) {
            var viewerlist = response.data.chatter_count;
            chatters = viewerlist;
            if(viewerlist !== ""){
                console.log('#######################################'+'\nВ чате '+chatters);
            }else{
                  console.log('#######################################'+'\nНе могу получить чаттеров');
            }
        }
    });
}

function alg (view, chat) {

	return chat / view * 100;
}



//docReady(function() {
$(window).load(function(){
    console.log('#######################################'+'\nВыделяем имя стримера..');
    var twitchname;
    //var name1 = document.getElementsByClassName("links_group");
    var name1 = window.location.href;
    twitchname = name1.substr(22);
    /////
console.log('#######################################'+'\nЗагрузка..');
setTimeout(function(){
	connect(twitchname);
    chat(twitchname);
    setTimeout(function(){
    console.log('#######################################'+'\nДоля '+alg(viewers,chatters).toFixed(1));
    }, 5000);
}, 5000);
})();