-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefreshThreads.js
More file actions
91 lines (85 loc) · 3.08 KB
/
RefreshThreads.js
File metadata and controls
91 lines (85 loc) · 3.08 KB
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
/* RefreshThreads
*
* Allows to periodically check for new thread replies using AJAX
* Contribute to translations in https://dev.wikia.com/wiki/Special:Blankpage/i18nedit/RefreshThreads
*
* @author Dorumin
*/
(function() {
if (wgNamespaceNumber != 1201 || window.RefreshThreadsInit) return;
window.RefreshThreadsInit = true;
var config = window.RefreshThreads || {},
i18n;
config.interval = config.interval || 15000;
if (typeof dev == 'undefined' || typeof dev.i18n == 'undefined') {
importArticle({
type: 'script',
article: 'u:dev:MediaWiki:I18n-js/code.js'
});
}
function add_messages(new_messages) {
$('.new-reply').before(new_messages);
new_messages.hide().fadeIn('slow').find('.timeago').timeago().end().each(function() {
window.skin != 'monobook' && WikiaButtons.init($(this));
});
}
function display_view_more(new_messages) {
var count = new_messages.length,
class_name = 'refresh-threads-view-more-button';
if ($('.' + class_name + '[data-count="' + count + '"]').length) return;
$('.' + class_name).remove();
$('<li>', {
class: class_name,
'data-count': count,
append: $('<a>', {
class: class_name + '-link',
text: i18n.msg('show-new-message' + (count == 1 ? '' : 's'), count).plain(),
css: {
cursor: 'pointer'
}
})
}).click(function() {
var $this = $(this);
$this.fadeOut(400, function() {
$this.remove();
add_messages(new_messages);
});
}).hide().fadeIn().insertBefore('.new-reply');
}
function query_content() {
var uri = new mw.Uri(location.href);
uri.query.action = 'render';
$.get(uri.toString(), function(page) {
var $page = $(page),
cur_last_id = $('.SpeechBubble.message').last().attr('id'),
new_messages = cur_last_id == '1' ?
$page.find('.replies').children('.message') :
$page.find('#' + cur_last_id).nextUntil('.new-reply');
setTimeout(query_content, config.interval);
if (!new_messages.length) return;
if (config.auto_add) {
add_messages(new_messages);
return;
}
display_view_more(new_messages);
});
}
mw.hook('dev.i18n').add(function(lib) {
lib.loadMessages('RefreshThreads').done(function(lang) {
i18n = lang;
i18n.useUserLang();
setTimeout(query_content, config.interval);
mw.util.addCSS('.refresh-threads-view-more-button {\
text-align: center;\
font-size: 11px;\
cursor: pointer;\
}\
.refresh-threads-view-more-button-link {\
width: 100%;\
height: 100%;\
display: block;\
padding: .5em;\
}');
});
});
})();