forked from 1024--/govnokod.ru-userscripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGKFilter.user.js
610 lines (597 loc) · 24.1 KB
/
GKFilter.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
// ==UserScript==
// @name GK Filter
// @namespace GK
// @description Filter posts & comments on govnokod.ru
// @include *://govnokod.ru/*
// @include *://www.govnokod.ru/*
// @require https://code.jquery.com/jquery-1.4.min.js
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @version 3.2.3
// @grant unsafeWindow
// @grant GM_registerMenuCommand
// @grant GM.getValue
// @grant GM.setValue
// ==/UserScript==
// This is my modified version of the script http://userscripts.org/scripts/source/393166.user.js (version 3.2.0) made by Vindicar
(async function($){
//dirty, DIRTY hack to wait for certain element to appear. -_-
//But I have no idea how to do it right.
function waitForSelector(selector, context, mustexist, callback) {
if (($(selector, context).length>0) == mustexist)
callback();
else
setTimeout(function(){waitForSelector(selector, context, mustexist, callback)}, 50);
}
//short function for adding custom CSS rules. Why use Greasemonkey specific GM_setStyle() just for that?
function addCSS(rule) {
var styleElement = document.createElement("style");
styleElement.type = "text/css";
if (typeof styleElement.styleSheet !== 'undefined')
styleElement.styleSheet.cssText = rule;
else
styleElement.appendChild(document.createTextNode(rule));
document.getElementsByTagName("head")[0].appendChild(styleElement);
}
addCSS([
'.comment-text.transparent * {color: transparent !important;}',
'.entry-content.transparent pre * {color: transparent !important;}',
'.description.transparent * {color: transparent !important;}',
'.hentry.entry-post-hidden .entry-content {display:none !important;}',
'.hentry.entry-post-hidden .description {display:none !important;}',
].join('\n'));
addCSS([
'#GKFSettings {\
position:fixed; z-index:1000; top:0;\
height:80%; width:80%; margin:10%;\
overflow-x: auto; overflow-y: scroll;\
border:solid 2px brown;\
background-color:rgb(242, 240, 227);\
}',
'#GKFSettings p {margin:0;padding:0;}',
'#GKFSettings label {font-weight:bold;margin: 0 5px 0 0}',
'#GKFSettings .GKFSgroupform {margin:20px;}',
'#GKFSettings #GKFSglobalsform {margin:20px;}',
'#GKFSettings .GKFSbuttons {text-align:center;}',
'#GKFSettings input {width:100%;}',
'#GKFSettings input[type="checkbox"] {width:auto;}',
'#GKFSettings input.GKFSgrouptitle {width:auto;}',
'#GKFSettings .GKFSdeletegroup {width:30px;}',
'#GKFSettings option.GKFSgood {background-color: #CCFFCC;}',
'#GKFSettings option.GKFSneutral {background-color: #FFFFFF;}',
'#GKFSettings option.GKFSevil {background-color: #FFCCCC;}',
].join('\n'));
//============================================================================================================
var Group = function () {
if (typeof this == 'undefined')
throw "Use 'new', Luke!";
Group.prototype.init.call(this);
}
$.extend(Group, {
ACTION_NONE : 0,
ACTION_HIDECONTENT : 1,
ACTION_HIDETHREAD : 2,
ACTION_WHITESPACE : 3,
ACTION_SPOILER : 4,
ACTION_UNSPOILER : 5,
ACTION_HIDEPOST : 6,
VOTE_NONE : 0,
VOTE_UP : 1,
VOTE_DOWN : -1,
});
Group.prototype = {
init: function() {
this.active = true;
this.title = '';
this.chapters = [];
this.users = [];
this.comment_action = this.ACTION_NONE;
this.comment_vote = this.VOTE_NONE;
this.post_action = this.ACTION_NONE;
this.post_vote = this.VOTE_NONE;
this.color = '';
return this;
},
serialize: function() {
return JSON.stringify({
"active" : this.active,
"title" : this.title,
"chapters" : this.chapters,
"users" : this.users,
"comment_action": this.comment_action,
"comment_vote" : this.comment_vote,
"post_action": this.post_action,
"post_vote" : this.post_vote,
"color" : this.color,
});
},
unserialize : function(str) {
var obj = JSON.parse(str);
this.active = obj.active;
this.title = obj.title;
this.chapters = []
for (var i=0;i<obj.chapters.length;i++)
this.chapters.push(obj.chapters[i].toLowerCase());
this.users = [];
for (var i=0;i<obj.users.length;i++)
this.users.push(obj.users[i].toLowerCase());
this.comment_action = obj.comment_action;
this.comment_vote = obj.comment_vote;
this.post_action = obj.post_action;
this.post_vote = obj.post_vote;
this.color = obj.color;
return this;
},
toString: function() {
return this.serialize();
},
matchUser: function(user, chapter) {
return (this.active) && (
(this.chapters.length == 0) ||
(chapter.length == 0) ||
(this.chapters.indexOf(chapter.toLowerCase()) != -1)
) && (this.users.indexOf(user.toLowerCase()) != -1);
},
};
Group.unserialize = function(str) {
var group = new Group()
group.unserialize(str);
return group;
};
//============================================================================================================
var Comment = {
find: function(context) {
if (typeof context === 'undefined')
context = document;
return $(context).find('.hcomment');
},
getAuthor: function($comment) {
return $comment.find('.entry-author:eq(0)').find('a').text().trim();
},
getChapter: function($comment) {
return $comment.closest('.hentry').find('a[rel="chapter"]').text().trim();
},
hideContent: function($comment) {
$comment.find('.entry-comment-wrapper:eq(0)').hide();
},
hideThread: function($comment) {
$comment.hide();
},
hidePost: function($comment) {
$comment.closest('.hentry').hide();
},
whitespace: function($comment) {
$comment.find('.comment-text:eq(0)').addClass('transparent');
},
spoiler: function($comment, text='показать всё, что скрыто', hint=false) {
var $ec = $comment.find('.entry-comment:eq(0)');
var $lnk;
if (!$ec.hasClass('entry-comment-hidden')) {
$lnk = $('<span class="hidden-text"><a class="ajax" href="#">'+text+'</a></span>');
$ec
.addClass('entry-comment-hidden')
.find('.comment-text:eq(0)')
.before($lnk);
}
else {
$lnk = $ec.find('.hidden-text:eq(0)').find('a.ajax');
$lnk.text(text);
}
if (hint)
$lnk.attr('title', $comment.find('.comment-text:eq(0)').text());
},
unspoiler: function($comment) {
var $ec = $comment.find('.entry-comment:eq(0)');
if ($ec.hasClass('entry-comment-hidden'))
$ec
.removeClass('entry-comment-hidden')
.find('.hidden-text:eq(0)')
.remove();
},
voteUp: function($comment, delay=10.0) {
var id = $comment.find('.entry-comment-wrapper:eq(0)').attr('id');
var $links = $comment.find('a.comment-vote-on')
.filter(function(){
return $(this).parentsUntil('#'+id, '.hcomment').length == 0; //jQuery 1.4 >_<
});
if ($links.length == 1) //чтобы не наломать дров в случае чего
//$links.css('border','solid 1px blue');
setTimeout(function(){$links.click()}, Math.floor(Math.random()*delay*1000+100) );
},
voteDown: function($comment, delay=10.0) {
var id = $comment.find('.entry-comment-wrapper:eq(0)').attr('id');
var $links = $comment.find('a.comment-vote-against')
.filter(function(){
return $(this).parentsUntil('#'+id, '.hcomment').length == 0; //jQuery 1.4 >_<
});
if ($links.length == 1) //чтобы не наломать дров в случае чего
//$links.css('border','solid 1px blue');
setTimeout(function(){$links.click()}, Math.floor(Math.random()*delay*1000+100) );
},
mark: function($comment, color) {
$comment.find('.entry-author:eq(0)').find('a').css('color', color);
},
};
//============================================================================================================
var Post = {
find: function(context) {
if (typeof context === 'undefined')
context = document;
return $(context).find('.hentry');
},
getAuthor: function($post) {
return $post.find('.author').find('a:not(has(img))').text().trim();
},
getChapter: function($post) {
return $post.find('a[rel="chapter"]').text().trim();
},
hideContent: function($post) {
$post.find('.entry-content:eq(0)').hide();
$post.find('.description:eq(0)').hide();
},
hideThread: function($post) {
$post.hide();
},
whitespace: function($post) {
$post.find('.entry-content:eq(0)').addClass('transparent');
$post.find('.description:eq(0)').addClass('transparent');
},
spoiler: function($post, text='показать всё, что скрыто', hint=false) {
if (!$post.hasClass('entry-post-hidden')) {
$lnk = $('<span class="hidden-text"><a class="ajax" href="#">'+text+'</a></span>');
if (hint)
$lnk.attr('title', $post.find('.entry-content:eq(0)').text());
$lnk.click(function(event){
$(this).closest('.hentry').removeClass('entry-post-hidden');
$(this).remove();
});
$post
.addClass('entry-post-hidden')
.find('.entry-content:eq(0)')
.before($lnk);
}
},
voteUp: function($post, delay=10.0) {
var $links = $post.find('a.vote-on:eq(0)');
if ($links.length == 1) //чтобы не наломать дров в случае чего
//$links.css('border','solid 1px blue');
setTimeout(function(){$links.click()}, Math.floor(Math.random()*delay*1000+100) );
},
voteDown: function($post, delay=10.0) {
var $links = $post.find('a.vote-against:eq(0)');
if ($links.length == 1) //чтобы не наломать дров в случае чего
//$links.css('border','solid 1px blue');
setTimeout(function(){$links.click()}, Math.floor(Math.random()*delay*1000+100) );
},
mark: function($post, color) {
$post.find('.author').find('a').css('color', color);
},
};
//============================================================================================================
function processPosts(groups, $context) {
Post.find($context).each(function(){
var $post = $(this);
var user = Post.getAuthor($post);
var chapter = Post.getChapter($post);
for (var i=0;i<groups.length;i++)
if (groups[i].matchUser(user, chapter)) {
switch (groups[i].post_action) {
case Group.ACTION_HIDECONTENT: Post.hideContent($post); break;
case Group.ACTION_HIDETHREAD: Post.hideThread($post); break;
case Group.ACTION_WHITESPACE: Post.whitespace($post); break;
case Group.ACTION_SPOILER: Post.spoiler($post, Options.globals.spoilertext, Options.globals.spoilerhint); break;
default: ; break;
};
switch (groups[i].post_vote) {
case Group.VOTE_UP: Post.voteUp($post, Options.globals.votedelay); break;
case Group.VOTE_DOWN: Post.voteDown($post, Options.globals.votedelay); break;
default: ; break;
};
if (!!groups[i].color)
Post.mark($post, groups[i].color);
};
});
}
function processComments(groups, $context) {
Comment.find($context).each(function(){
var $comment = $(this);
var user = Comment.getAuthor($comment);
var chapter = Comment.getChapter($comment);
for (var i=0;i<groups.length;i++)
if (groups[i].matchUser(user, chapter)) {
switch (groups[i].comment_action) {
case Group.ACTION_HIDECONTENT: Comment.hideContent($comment); break;
case Group.ACTION_HIDETHREAD: Comment.hideThread($comment); break;
case Group.ACTION_WHITESPACE: Comment.whitespace($comment); break;
case Group.ACTION_SPOILER: Comment.spoiler($comment, Options.globals.spoilertext, Options.globals.spoilerhint); break;
case Group.ACTION_UNSPOILER: Comment.unspoiler($comment); break;
default: ; break;
};
switch (groups[i].comment_vote) {
case Group.VOTE_UP: Comment.voteUp($comment, Options.globals.votedelay); break;
case Group.VOTE_DOWN: Comment.voteDown($comment, Options.globals.votedelay); break;
default: ; break;
};
if (!!groups[i].color)
Comment.mark($comment, groups[i].color);
break;
};
});
}
function processCommentsPage(groups, $context) {
Comment.find($context).each(function(){
var $comment = $(this);
var user = Comment.getAuthor($comment);
var chapter = Comment.getChapter($comment);
for (var i=0;i<groups.length;i++)
if (groups[i].matchUser(user, chapter)) {
switch (groups[i].comment_action) {
case Group.ACTION_HIDECONTENT: Comment.hideContent($comment); break;
case Group.ACTION_HIDETHREAD: Comment.hideThread($comment); break;
case Group.ACTION_HIDEPOST: Comment.hidePost($comment); break;
case Group.ACTION_WHITESPACE: Comment.whitespace($comment); break;
case Group.ACTION_SPOILER: Comment.spoiler($comment, Options.globals.spoilertext, Options.globals.spoilerhint); break;
case Group.ACTION_UNSPOILER: Comment.unspoiler($comment); break;
default: ; break;
};
switch (groups[i].comment_vote) {
case Group.VOTE_UP: Comment.voteUp($comment, Options.globals.votedelay); break;
case Group.VOTE_DOWN: Comment.voteDown($comment, Options.globals.votedelay); break;
default: ; break;
};
if (!!groups[i].color)
Comment.mark($comment, groups[i].color);
break;
};
});
}
//============================================================================================================
function hijackComments(groups) {
//перехват загрузки комментариев
var oldLoadComments = unsafeWindow.comments['load'];
function newLoadComments(aElemTrigger) {
var $parent = $(aElemTrigger).closest('.entry-comments');
oldLoadComments.call(this,aElemTrigger);
waitForSelector('.hcomment', $parent, true, function(){
processComments(groups, $parent);
});
}
unsafeWindow.comments['load'] = newLoadComments;
}
//============================================================================================================
var Options = {
COLORS : {
"":"[нет]",
"silver":"silver",
"gray":"gray",
"black":"black",
"maroon":"maroon",
"red":"red",
"orange":"orange",
"yellow":"yellow",
"olive":"olive",
"lime":"lime",
"green":"green",
"aqua":"aqua",
"blue":"blue",
"navy":"navy",
"teal":"teal",
"fuchsia":"fuchsia",
"purple":"purple",
},
$wnd : undefined,
magic : undefined,
globals : {},
installOnSaveListener: function() {
if (typeof Options.magic === 'undefined') {
window.addEventListener("message", Options.handlerOnSave, false);
Options.magic = Math.random().toString(36).slice(2);
}
},
handlerOnSave: function(event) {
var messageJSON;
try {
messageJSON = JSON.parse(event.data);
}
catch (zError) {
// Do nothing
}
if ( !messageJSON || (typeof messageJSON.GKFILTER === 'undefined') )
return; //-- Message is not for us.
else {
if (messageJSON.GKFILTER === Options.magic) {
GM.setValue('groups',JSON.stringify(messageJSON.groups));
GM.setValue('globals',JSON.stringify(messageJSON.globals));
}
}
},
load: async function() {
var arr = JSON.parse(await GM.getValue('groups','[]'));
Options.groups = [];
for (var i=0;i<arr.length;i++)
Options.groups.push(Group.unserialize(arr[i]));
var glb = JSON.parse(await GM.getValue('globals','{}'));
Options.globals = {
spoilertext: (typeof glb.spoilertext === 'undefined') ? 'показать всё, что скрыто' : glb.spoilertext.toString(),
spoilerhint: (typeof glb.spoilerhint === 'undefined') ? true : Boolean(glb.spoilerhint),
votedelay: (typeof glb.votedelay === 'undefined') ? 10.0 : parseFloat(glb.votedelay),
};
},
save: function(){
var grp = [];
for (var i=0;i<Options.groups.length;i++)
grp.push(Options.groups[i].serialize());
var msg = {'GKFILTER':Options.magic,groups:grp,globals:Options.globals};
window.postMessage(JSON.stringify(msg), "*");
},
buildGroupForm: function(group) {
var $form = $('\
<fieldset class="GKFSgroupform">\
<legend>\
<input type="text" value="" placeholder="Название группы" class="GKFSgrouptitle"/>\
<button class="GKFSdeletegroup">X</button>\
</legend>\
<p><input type="checkbox" value="" class="GKFSgroupactive"/><label>Группа используется</label></p>\
<p><label>Участники (обязательно):</label><input type="text" value="" placeholder="Введите имена участников, разделенные ;" class="GKFSuserlist"/></p>\
<p><label>Разделы (по умолчанию во всех):</label><input type="text" value="" placeholder="Введите названия разделов, разделенные ;" class="GKFSchapterlist"/></p>\
<p><label>Посты:</label><select rows="1" class="GKFSpost GKFSactions">\
<option value="'+Group.ACTION_NONE+'" class="GKFSneutral">ничего не делать</option>\
<option value="'+Group.ACTION_HIDECONTENT+'" class="GKFSevil">скрыть содержимое</option>\
<option value="'+Group.ACTION_HIDETHREAD+'" class="GKFSevil">скрыть целиком</option>\
<option value="'+Group.ACTION_WHITESPACE+'" class="GKFSevil">закрыть белым</option>\
<option value="'+Group.ACTION_SPOILER+'" class="GKFSevil">закрыть спойлером</option>\
</select>, <select rows="1" class="GKFSpost GKFSvotes">\
<option value="'+Group.VOTE_NONE+'" class="GKFSneutral">не голосовать</option>\
<option value="'+Group.VOTE_UP+'" class="GKFSgood">плюсануть</option>\
<option value="'+Group.VOTE_DOWN+'" class="GKFSevil">минусануть</option>\
</select></p>\
<p><label>Комменты:</label><select rows="1" class="GKFScomment GKFSactions">\
<option value="'+Group.ACTION_NONE+'" class="GKFSneutral">ничего не делать</option>\
<option value="'+Group.ACTION_HIDECONTENT+'" class="GKFSevil">скрыть коммент</option>\
<option value="'+Group.ACTION_HIDETHREAD+'" class="GKFSevil">скрыть ветку</option>\
<option value="'+Group.ACTION_HIDEPOST+'" class="GKFSevil">скрыть пост в стоке</option>\
<option value="'+Group.ACTION_WHITESPACE+'" class="GKFSevil">закрыть белым</option>\
<option value="'+Group.ACTION_SPOILER+'" class="GKFSevil">закрыть спойлером</option>\
<option value="'+Group.ACTION_UNSPOILER+'" class="GKFSgood">убрать спойлер</option>\
</select>, <select rows="1" class="GKFScomment GKFSvotes">\
<option value="'+Group.VOTE_NONE+'" class="GKFSneutral">не голосовать</option>\
<option value="'+Group.VOTE_UP+'" class="GKFSgood">плюсануть</option>\
<option value="'+Group.VOTE_DOWN+'" class="GKFSevil">минусануть</option>\
</select></p>\
<p><label>Выделение цветом:</label><select rows="1" class="GKFScolors"></select></p>\
</fieldset>');
var coloropts = [];
for (var color in Options.COLORS)
coloropts.push('<option value="'+color+'" style="color:'+color+'">'+Options.COLORS[color]+'</option>');
$form.find('.GKFScolors').append(coloropts.join('\n'));
$form.find('.GKFSgroupactive').attr('checked', group.active ? 'checked' : '');
$form.find('.GKFSgrouptitle').val(group.title);
$form.find('.GKFSuserlist').val(group.users.join(';'));
$form.find('.GKFSchapterlist').val(group.chapters.join(';'));
$form.find('.GKFSpost.GKFSactions').val(group.post_action);
$form.find('.GKFSpost.GKFSvotes').val(group.post_vote);
$form.find('.GKFScomment.GKFSactions').val(group.comment_action);
$form.find('.GKFScomment.GKFSvotes').val(group.comment_vote);
$form.find('.GKFScolors').val(group.color);
return $form;
},
parseGroupForm: function($form) {
var group = new Group();
group.active = !!$form.find('.GKFSgroupactive')[0].checked;
group.title = $form.find('.GKFSgrouptitle').val();
var arr;
arr = $form.find('.GKFSuserlist').val().split(';');
for (var i=0;i<arr.length;i++) {
var s = $.trim(arr[i]).toLowerCase();
if (s.length > 0)
group.users.push(s);
}
arr = $form.find('.GKFSchapterlist').val().split(';');
for (var i=0;i<arr.length;i++) {
var s = $.trim(arr[i]).toLowerCase();
if (s.length > 0)
group.chapters.push(s);
}
group.post_action = parseInt($form.find('.GKFSpost.GKFSactions').val(),10);
group.post_vote = parseInt($form.find('.GKFSpost.GKFSvotes').val(),10);
group.comment_action = parseInt($form.find('.GKFScomment.GKFSactions').val(),10);
group.comment_vote = parseInt($form.find('.GKFScomment.GKFSvotes').val(),10);
group.color = $form.find('.GKFScolors').val();
return group;
},
addGroup: function() {
var $form = Options.buildGroupForm(new Group());
$('.GKFSdeletegroup', $form).bind('click', function(e){Options.delGroup($(this).closest('.GKFSgroupform'));});
Options.$wnd.find('p.GKFSgroups').append($form);
},
delGroup: function($group) {
if (confirm('Удалить группу "'+$group.find('.GKFSgrouptitle').val()+'"?'))
$group.remove();
},
buildGlobalsForm: function() {
var $form = $('\
<fieldset id="GKFSglobalsform">\
<legend>Глобальные настройки</legend>\
<p><label>Текст спойлера:</label><input id="GKFSspoilertext" type="text" value=""/></p>\
<p><input id="GKFSspoilerhint" type="checkbox"/><label>Показывать скрытый текст во всплывающей подсказке.</label></p>\
<p><label>Интервал голосования, сек</label><input id="GKFSvotedelay" type="input" value=""/></p>\
</fieldset>');
$form.find('#GKFSspoilertext').val(Options.globals.spoilertext);
$form.find('#GKFSspoilerhint').attr('checked', Options.globals.spoilerhint ? 'checked' : '');
$form.find('#GKFSvotedelay').val(Options.globals.votedelay);
return $form;
},
parseGlobalsForm: function($form) {
var res = {};
res.spoilertext = $form.find('#GKFSspoilertext').val();
res.spoilerhint = $form.find('#GKFSspoilerhint')[0].checked;
res.votedelay = parseFloat($form.find('#GKFSvotedelay').val());
return res;
},
accept: function() {
Options.groups = [];
Options.$wnd.find('.GKFSgroupform').each(function(){
Options.groups.push(Options.parseGroupForm($(this)));
});
Options.globals = Options.parseGlobalsForm(Options.$wnd.find('#GKFSglobalsform'));
Options.save();
Options.hide();
},
cancel: function() {
Options.hide();
},
show: function() {
if ($('#GKsettings').length > 0)
return;
Options.$wnd = $('<div id="GKFSettings">\
<p class="GKFSbuttons">\
<button class="GKFSaccept">Сохранить</button>\
<button class="GKFScancel">Отменить</button>\
</p>\
<hr class="GKFSseparator" />\
<p class="GKFSgroups"></p>\
<p class="GKFSbuttons"><button class="GKFScreategroup">Добавить группу</button></p>\
<hr class="GKFSseparator" />\
<p class="GKFSbuttons">\
<button class="GKFSaccept">Сохранить</button>\
<button class="GKFScancel">Отменить</button>\
</p>\
</div>');
var $place = Options.$wnd.find('p.GKFSgroups');
for (var i=0;i<Options.groups.length;i++)
$place.append(Options.buildGroupForm(Options.groups[i]));
Options.$wnd.find('.GKFSbuttons:eq(1)').after(Options.buildGlobalsForm());
$('.GKFSaccept', Options.$wnd).bind('click', function(e){Options.accept();});
$('.GKFScancel', Options.$wnd).bind('click', function(e){Options.cancel();});
$('.GKFSdeletegroup', Options.$wnd).bind('click', function(e){Options.delGroup($(this).closest('.GKFSgroupform'));});
$('.GKFScreategroup', Options.$wnd).bind('click', function(e){Options.addGroup();});
$('body').append(Options.$wnd);
},
hide: function() {
if (typeof Options.$wnd !== 'undefined') {
Options.$wnd.remove();
Options.$wnd = undefined;
};
},
};
//регистрируем пользовательские команды
GM_registerMenuCommand("GK Filter settings", function(){Options.show();}, 'f');
//============================================================================================================
Options.installOnSaveListener();
await Options.load();
if (Options.groups.length > 0)
//делаем дело
if (/govnokod\.ru\/\d+/.test(location))
//мы на странице поста, обрабатываем все комментарии на странице
processComments(Options.groups, $('body'));
else {
//мы на главной или где-то еще
//исключение: не обрабатываем посты в профиле пользователя, иначе мы можем их так и не увидеть.
if (!/govnokod\.ru\/user\/\d+\/codes/.test(location))
processPosts(Options.groups);
//тем не менее, перехватим загрузку комментариев
hijackComments(Options.groups);
if(/\/comments/.test(location.pathname))
//мы в стоке, обрабатываем все комментарии на странице
processCommentsPage(Options.groups, $('body'));
}
})(window.jQuery || window.$);