-
Notifications
You must be signed in to change notification settings - Fork 280
/
replyer.plugin.js
68 lines (66 loc) · 2.5 KB
/
replyer.plugin.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
//META{"name":"Replyer"}*//
var Replyer = function () {};
Replyer.prototype.getName = function() {
return "Replyer";
};
Replyer.prototype.getDescription = function() {
return "Reply to people with a button (Thanks Zerebos for pointing out a new method for grabbing IDs)";
};
Replyer.prototype.getVersion = function() {
return "1.2";
};
Replyer.prototype.getAuthor = function() {
return "Hammock & Zerebos";
};
Replyer.prototype.start = function() {
$(document).on("mouseover.rpr", function(e) {
var target = $(e.target);
if(target.parents(".message").length > 0) {
var isCompact = false;
var allmessages = $('.messages .message-group');
var nameDateBlock = $('.messages .message-group .comment .message .body h2');
var replyBtn = '<span class="replyer" style="cursor:pointer;color:rgba(255,255,255,.4) !important;position:relative;top:-1px;margin-left:5px;text-transform:uppercase;font-size:10px;padding:3px 5px;box-sizing:border-box;background:#282b30;-webkit-border-radius:3px;">Reply</span>';
allmessages.on('mouseover',function() {
if (nameDateBlock.find('.replyer').length == 0) {
$(this).find(nameDateBlock).append(replyBtn);
$(this).find('.replyer').click(function() {
var group = $(this).parents('.message-group')[0];
var user = group[Object.keys(group).find((key) => key.startsWith("__reactInternalInstance"))].child.child.memoizedProps.user.id
var reply = '<@!'+user+'> '
var textarea = $('.content .channelTextArea-1HTP3C textarea')[0]
textarea.focus()
textarea.selectionStart = 0;
textarea.selectionEnd = 0;
document.execCommand("insertText", false, reply);
textarea.selectionStart = textarea.value.length;
textarea.selectionEnd = textarea.value.length;
});
}
});
allmessages.on('mouseleave',function() {
if (nameDateBlock.find('.replyer').length == 1) {
$(this).find('.replyer').empty().remove();
}
});
}
});
console.log('Replyer started.');
};
Replyer.prototype.load = function() {};
Replyer.prototype.unload = function() {
$(document).off("mouseover.rpr");
$('.messages .message-group').off('mouseover');
$('.messages .message-group').off('mouseleave');
};
Replyer.prototype.stop = function() {
$(document).off("mouseover.rpr");
$('.messages .message-group').off('mouseover');
$('.messages .message-group').off('mouseleave');
};
Replyer.prototype.getSettingsPanel = function() {
return null;
};
Replyer.prototype.onMessage = function() {
};
Replyer.prototype.onSwitch = function() {
};