-
Notifications
You must be signed in to change notification settings - Fork 0
/
ksks.txt
191 lines (153 loc) · 6.59 KB
/
ksks.txt
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
window.addEventListener('load', () => {
console.log('loaded');
let words = '';
let lastWord = '';
let filteredEmoji = [];
let charInput = [];
let show = false;
let editable = false;
function getLastWord(wordSet) {
let wordsArray = wordSet.split(' ');
return wordsArray.at(-1);
}
function updateWords() {
return document.activeElement.textContent || document.activeElement.value;
}
function findEmoji(emojiList) {
const filteredTags = emojiList.filter((emoji) => {
return emoji.tags.includes(lastWord);
});
const filteredTagEmoji = filteredTags.map(each => {
return each.emoji;
});
return filteredTagEmoji;
}
function removeSuggestions() {
let shownSuggestions = [...document.getElementsByClassName('emoji-container')];
shownSuggestions.forEach(each => each.remove());
}
document.activeElement.addEventListener('keyup', (e) => {
if (document.activeElement.getAttribute('contenteditable') || document.activeElement.nodeName === 'INPUT' || document.activeElement.nodeName === 'TEXTAREA') {
if (URL.includes('https://twitter.com/')) {
const div = document.getElementsByClassName('DraftEditor-editorContainer')[0].firstChild;
let filteredEmoji = findEmoji(emoji);
let spans = [...document.activeElement.getElementsByTagName('span')].filter(each => each.getAttribute('data-offset-key'));
if (e.keyCode >= 65 && e.keyCode <= 90) {
filteredEmoji = [];
charInput.push(e.key);
show = false;
removeSuggestions();
} else if (e.keyCode === 13 || e.keyCode === 32) {
removeSuggestions();
lastWord = charInput.join('');
charInput = [];
filteredEmoji = findEmoji(emoji);
if (lastWord) {
show = true;
}
}
function insertTextAtCaret(text) {
suggestions.innerHTML = '';
removeSuggestions();
div.focus();
const dataTransfer = new DataTransfer();
// this may be 'text/html' if it's required
dataTransfer.setData('text/plain', text);
div.dispatchEvent(
new ClipboardEvent('paste', {
clipboardData: dataTransfer,
// need these for the event to reach Draft paste handler
bubbles: true,
cancelable: true
})
);
// clear DataTransfer Data
dataTransfer.clearData();
}
const suggestions = document.createElement('div');
words = updateWords();
lastWord = getLastWord(words);
filteredEmoji.map(each => {
let emojiToAdd = document.createElement('div');
emojiToAdd.className = 'emoji';
emojiToAdd.innerText = each;
emojiToAdd.addEventListener('click', () => insertTextAtCaret(each))
suggestions.appendChild(emojiToAdd);
});
if (show) {
div.parentElement.appendChild(suggestions);
}
} else {
const div = [...document.getElementsByTagName('div')].filter(each => each.getAttribute('contenteditable'))[0];
const suggestions = document.createElement('div');
function insertTextAtCaretInput(input, text) {
removeSuggestions();
let start = input.selectionStart;
let end = input.selectionEnd;
input.value = input.value.substring(0, start)
+ text
+ input.value.substring(end, input.value.length);
show = false;
}
function insertTextAtCaretDiv(text) {
removeSuggestions();
let selection = window.getSelection();
let range = selection.getRangeAt(0);
range.insertNode(document.createTextNode(text));
selection.removeAllRanges();
show = false;
}
//
if (e.keyCode >= 65 && e.keyCode <= 90) {
filteredEmoji = [];
charInput.push(e.key);
show = false;
removeSuggestions();
} else if (e.keyCode === 13 || e.keyCode === 32) {
removeSuggestions();
lastWord = charInput.join('');
charInput = [];
filteredEmoji = findEmoji(emoji);
if (lastWord) {
show = true;
}
}
if (div === document.activeElement) {
console.log('contenteditable')
filteredEmoji.map(each => {
let emojiToAdd = document.createElement('div');
emojiToAdd.className = 'emoji';
emojiToAdd.innerText = each;
emojiToAdd.addEventListener('click', () => insertTextAtCaretDiv(each))
suggestions.appendChild(emojiToAdd);
});
if (show) {
suggestions.className = 'emoji-container';
suggestions.style.left = `${x+10}px`;
suggestions.style.top = `${y}px`;
let selection = window.getSelection();
let range = selection.getRangeAt(0);
range.insertNode(suggestions);
selection.removeAllRanges();
}
} else if (document.activeElement.nodeName == 'INPUT' || document.activeElement.nodeName == 'TEXTAREA'){ // text areas and inputs
console.log('input')
let input = document.activeElement;
filteredEmoji.map(each => {
let emojiToAdd = document.createElement('div');
emojiToAdd.className = 'emoji';
emojiToAdd.innerText = each;
emojiToAdd.addEventListener('click', () => insertTextAtCaretInput(input, each))
suggestions.appendChild(emojiToAdd);
});
if (show) {
suggestions.className = 'emoji-container';
suggestions.style.left = `${x+10}px`;
suggestions.style.top = `${y+10}px`;
document.body.appendChild(suggestions);
}
}
}
}
})
})