-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathignore_users.user.js
89 lines (80 loc) · 3.26 KB
/
ignore_users.user.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
// ==UserScript==
// @name Ignorast
// @version 0.3
// @match *://govnokod.ru/*
// @match *://www.govnokod.ru/*
// @grant none
// ==/UserScript==
// см. настройки бана в меню пользователя
// Для работы нужно подключить gQuery
(function($) {
if(!/\/\d+/.test(location.pathname)) return;
var SCRIPT_ID = 'e79a9913-02be-494f-88bd-28c149013cf1';
var BANNED = SCRIPT_ID + '-banned';
var MODE = SCRIPT_ID + '-mode';
var BTN_CLASS = 'userscript-banned';
var banned = {};
var modeHTML = localStorage.getItem(MODE) == 'HTML';
(localStorage.getItem(BANNED) || '').split(',').forEach(function(uid){
if(uid) banned[uid] = true;
});
function banHTML(comms) { comms.children('.entry-comment-wrapper').hide(); }
function banGK(comms) { if(comms.length) comms.gk('hide'); }
function unbanHTML(comms) { comms.children('.entry-comment-wrapper').show(); }
function unbanGK(comms) { if(comms.length) comms.gk('show'); }
(modeHTML ? banHTML : banGK)($.gk('comments')
.each(function() {
var comm = $(this);
var uid = comm.gk('@uid');
comm.gk('link')
.after($('<a href="#" class="' + BTN_CLASS + '">' +
(uid in banned ? 'разбанить' : 'забанить') + '</a>')
.css('margin-left', '1ex')
.click(function() {
var comms = $.gk('comments:gkuid(' + uid + ')');
if(uid in banned) {
delete banned[uid];
(modeHTML ? unbanHTML : unbanGK)(comms);
comms.gk('link').siblings('.' + BTN_CLASS).text('забанить');
} else {
banned[uid] = true;
(modeHTML ? banHTML : banGK)(comms);
comms.gk('link').siblings('.' + BTN_CLASS).text('разбанить');
}
localStorage.setItem(BANNED, Object.keys(banned).join(','));
return false;
}));
})
.filter(function(){ return $(this).gk('@uid') in banned; }));
$('.pane-content ul')
.append('<li><p>Настройки бана</p></li>')
.append($('<li></li>')
.append($('<a href="#">' +
(modeHTML ? 'режим: скрытие' : 'режим: спойлер') + '</a>')
.click(function() {
var comms = $.gk('comments')
.filter(function(){ return $(this).gk('@uid') in banned; });
modeHTML = !modeHTML;
if(modeHTML) {
localStorage.setItem(MODE, 'HTML');
$(this).text('режим: скрытие');
unbanGK(comms); banHTML(comms);
} else {
localStorage.setItem(MODE, 'GK');
$(this).text('режим: спойлер');
unbanHTML(comms); banGK(comms);
}
return false;
})))
.append($('<li></li>')
.append($('<a href="#">разбанить всех</a>')
.click(function() {
var comms = $.gk('comments')
.filter(function(){ return $(this).gk('@uid') in banned; });
(modeHTML ? unbanHTML : unbanGK)(comms);
comms.gk('link').siblings('.' + BTN_CLASS).text('забанить');
banned = {};
localStorage.setItem(BANNED, '');
return false;
})));
})(window.jQuery || window.$);