-
Notifications
You must be signed in to change notification settings - Fork 0
/
name-helper.js
75 lines (62 loc) · 2.5 KB
/
name-helper.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
var bodyObserver = new MutationObserver(function (mutations, observer) {
const sendButtons_one = document.querySelectorAll('[class^="msg-form__send-button artdeco-button artdeco-button--1"]');
const sendButtons_two = document.querySelectorAll('[class^="artdeco-button artdeco-button--3"]:not(.artdeco-button--secondary)')
if(sendButtons_one != null){
sendButtons_one.forEach(it => it.onclick = (e) => onSendButtonClick(e, it))
}
if (sendButtons_two != null){
sendButtons_two.forEach(it => it.onclick = (e) => onSendButtonClick(e, it))
}
});
bodyObserver.observe(document.body, { childList: true, subtree: true, attributes: false, characterData: false });
function onSendButtonClick(e, item){
if (findUpId(item, "msg-overlay") != null){
onBubbleSendClick(e, item)
}
else if (findUpId(item, "li-modal-container") != null){
onIndirectSendClick(e);
}
}
function findUpId(element, id) {
while (element.parentNode) {
element = element.parentNode;
if (element.id === id)
return element;
}
return null;
}
function onBubbleSendClick(e, sendButton){
const bubbleParent = sendButton.closest('[id^="msg-overlay-conversation-bubble"]')
if (bubbleParent != null){
const bigBubble = bubbleParent.querySelector("dt")
const message = bubbleParent.querySelector('[class="msg-form__contenteditable t-14 t-black--light t-normal flex-grow-1 notranslate"]');
if (message != null && bigBubble != null){
onSendClick(e, message.innerText, bigBubble.innerText);
}
}
}
function onIndirectSendClick(e){
const message = document.getElementById("custom-message").value;
const nameText = document.getElementsByClassName("inline t-24 t-black t-normal break-words")[0].innerText;
onSendClick(e, message, nameText);
}
function onSendClick(e, message, name) {
if (message !== ""){
var result = checkFirstLineNaming(message, name);
if (result === false){
if(!confirm("You probably entered a wrong name ;)\n\n OK for nevermind, Cancel for a chance to make a correction.")){
e.preventDefault();
e.stopPropagation();
return false;
}
}
}
}
function checkFirstLineNaming(message, name){
const firstName = name.split(' ')[0];
const lastName = name.split(' ')[1];
if (message.includes(firstName) || message.includes(lastName)){
return true;
}
return false;
}