This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathignored.js
120 lines (105 loc) · 3.53 KB
/
ignored.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
(function ()
{
var user = ':login';
var offset = 0;
var num = 0;
var tableStart = '<table><thead><tr><th>Date</th><th>User</th><th style="width:50px">X</th></tr></thead><tbody id="i">';
var tableEnd = '</tbody></table>';
function getIgnoredUsers()
{
Twitch.api({ method: ('users/' + user + '/blocks'), params: { limit: 500, offset: offset } }, function (error, list)
{
fillTable(list.blocks);
});
}
function fillTable(blocks)
{
var length = blocks.length;
for (var i = 0; i < length; i++)
{
tablePush(blocks[i]);
}
if (length == 500)
{
offset += 500;
getIgnoredUsers();
}
}
function tablePush(block)
{
var name = block.user.name;
var datestring = block.updated_at === "1970-01-01T00:00:00Z" ? "unknown date (long ago)" : (new Date(block.updated_at)).toLocaleString();
$('#i').append('<tr id="user-' + name + '"><td>' + datestring + '</td><td><a href="http://www.twitch.tv/' + name + '/profile" target="_blank">' + name + '</a></td><td><a href="javascript:void(0)" id="remove-ignore-' + num + '">X</a></td></tr>');
$('#remove-ignore-' + num).click(function ()
{
modifyIgnore(name, 'DELETE');
});
++num;
}
function modifyIgnore(name, action)
{
Twitch.api({ method: ('users/' + user + '/blocks/' + name), params: { _method: action }, verb: action }, function (error, list)
{
if (error)
{
if (!(action == 'DELETE' && error.status == 404))
{
console.log('Error:');
console.debug(error);
alert('Error! Check browser console for more information');
return;
}
}
console.debug(list);
if (action == 'DELETE')
{
console.log('Removed ' + name + ' from your ignore list');
$('#user-' + name).remove();
}
else if (action == 'PUT')
{
console.log('Added ' + name + ' to your ignore list');
tablePush({
updated_at: (new Date()).toISOString(),
user: {
name: name
}
});
$('#adduser').val('');
}
});
}
$(document).ready(function ()
{
$('#about').hide();
Twitch.init({ clientId: '92jn2uggt59emnh5n3um56bvn4gnan' }, function (error, status)
{
if (status.authenticated)
{
$('.twitch-connect').hide();
$('.initially_hidden').css('display', 'block');
Twitch.api({ method: '' }, function (error, list)
{
user = list.token.user_name;
$('#load').html(tableStart + tableEnd);
getIgnoredUsers();
window.location.hash = "";
});
}
$('.twitch-connect').click(function ()
{
Twitch.login({
scope: ['user_blocks_read', 'user_blocks_edit']
});
});
});
$('#about-btn').click(function ()
{
$('#about').slideToggle(500);
});
$('#adduser-button').click(function ()
{
modifyIgnore($('#adduser').val(), 'PUT');
});
});
})();