I'm making a website that shows all top streams on twitch, and based on what the stream is about it categorizes them. So if someone would click on English, it shows all the top english streams. By the way, i manually add categories to the streams. An example: Currently i check if the number 1 stream is streamer34, if yes, it applies class "English". If not it checks if the top stream is the other 33 streams. This is already quite a lot of code, example here:
var stream0 = "<? echo $lolarray->streams[0]->channel->name; ?>";
if(stream0 == "Streamer1") {
$('#stream0').addClass('class2');
$('#stream0').addClass('class1');
$('#stream0').addClass('class33');
$('#stream0').addClass('class99');
}
if(stream0 == "Streamer2") {
$('#stream0').addClass('class5');
$('#stream0').addClass('class2');
$('#stream0').addClass('class81');
$('#stream0').addClass('class0');
}
if(stream0 == "Streamer3") {
$('#stream0').addClass('class1');
$('#stream0').addClass('class444');
$('#stream0').addClass('class100');
}
$lolarray refers to the JSON Twitch API page. #stream0 is the div that holds the top stream inside it.
But this only checks for the top stream, for example, it won't add the class to streamer3 if he's the third most viewed stream, only if he's first. So, my site shows the top 60 streams. So the code i just showed goes x60... Only replacing all 0's by 1 - 59.
This gets my code to almost 15000 lines.. which feels pretty insane and almost not doable.
Oh just for extra information, the classes refer to value's of checkboxes.
I hope there's a shorter way, i've no idea.
This doesn't seem to work (from an answer):
var streamers {
'esl_csgo': [
'tournament',
'competition',
'english'
]
};
var setTwitchClass1 function(streamer) {
var classNames = streamers[streamer];
for (i=0; i<classNames.length; i++) {
$('#stream0').addClass(classNames[i]);
}
};
setTwitchClass1('esl_csgo');