-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject.js
487 lines (436 loc) · 18.8 KB
/
inject.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
console.log("Slackenger loaded successfully")
const headerFontSize = '18px'
const messageSenderPhotoSize = '36px'
const darkGreyColor = '#1c1c1c'
const lighterDarkGreyColor = '#1d1c1d'
const lightGreyColor = '#e4e4e4'
function pollForElement(elem, timeout, callback) {
const intervalPoll = setInterval(() => {
const element = document.querySelector(elem);
if (element) {
clearInterval(intervalPoll);
callback();
}
}, 400);
setTimeout(() => clearInterval(intervalPoll), timeout);
}
let css = '';
function addCss(input) {
css += input;
}
// From https://stackoverflow.com/questions/15505225/inject-css-stylesheet-as-string-using-javascript
function injectCss() {
var node = document.createElement('style');
node.innerHTML = css;
document.body.appendChild(node);
css = ''
}
addCss(`@import url('https://fonts.googleapis.com/css?family=Lato:400,900&display=swap');`);
addCss(`body{ font-family: 'Lato' !important }`);
pollForElement('[aria-label="Conversation List"]', 10000, sidepanel)
function sidepanel() {
const chatBanner = document.querySelector('[role="banner"]');
chatBanner.style['display'] = 'none'
const sidePanelSelector = chatBanner.parentElement.classList[0]
addCss(`.${sidePanelSelector} { background-color: #4f2f4c }`);
const leftPanel = document.body.children[1].firstElementChild.firstElementChild.firstElementChild
leftPanel.style['min-width'] = '230px'
leftPanel.style['max-width'] = '230px'
const convoList = document.querySelector('[aria-label="Conversation List"]').children
const convoListElement = convoList[1]
const convoListElementSelector = convoListElement.classList[1]
addCss('.' + convoListElementSelector + '{ height: 28px }');
const convoExample = convoList[1].firstElementChild.firstElementChild.firstElementChild
// console.log(convoExample)
const convoTitleText = convoExample.children[1].firstElementChild.firstElementChild
const convoTitleTextSelector = convoTitleText.classList[1]
addCss('.' + convoTitleTextSelector + `::before { content: "# "; color: #8a8a8a99; padding-right: 2px }`);
addCss('.' + convoTitleTextSelector + ' { color: #ffffff88 }');
const convoImageSelector = convoExample.firstElementChild.classList[0]
addCss('.' + convoImageSelector + '{ display: none }');
const convoMessagePreview = convoExample.children[1].children[1]
const convoMessagePreviewSelector = convoMessagePreview.classList[1]
addCss('.' + convoMessagePreviewSelector + '{ display: none }');
const conversations = document.querySelector('[aria-label="Conversations"]');
const conversationSidebar = conversations.parentElement.parentElement.parentElement;
conversationSidebar.style['background-color'] = '#4f2f4c';
let myConvoBanner = document.createElement('div')
myConvoBanner.classList.add("myConvoBanner")
let workspaceTitle = document.createElement('input')
workspaceTitle.type = 'text'
workspaceTitle.value = 'Type here and press enter'
chrome.storage.sync.get(["workspaceTitle"], (items) => {
if (items.workspaceTitle) {
workspaceTitle.value = items.workspaceTitle
}
})
workspaceTitle.classList.add("workspaceTitle")
workspaceTitle.classList.add("customInput")
workspaceTitle.addEventListener('keyup', (e) => {
//enter key
if (e.keyCode === 13) {
chrome.storage.sync.set({ "workspaceTitle": workspaceTitle.value }, () => {
// console.log('saved workspace title')
});
workspaceTitle.blur();
}
})
let yourName = document.createElement('input')
yourName.type = 'text'
yourName.value = 'Type here and press enter'
chrome.storage.sync.get(["yourName"], (items) => {
if (items.yourName) {
yourName.value = items.yourName
}
})
yourName.classList.add("yourName")
yourName.classList.add("customInput")
yourName.addEventListener('keyup', (e) => {
//enter key
if (e.keyCode === 13) {
chrome.storage.sync.set({ "yourName": yourName.value }, () => {
// console.log('saved your nane')
});
yourName.blur();
}
})
const yourNameWrapper = document.createElement('span')
yourNameWrapper.classList.add("yourNameWrapper")
yourNameWrapper.appendChild(yourName)
myConvoBanner.appendChild(workspaceTitle)
myConvoBanner.appendChild(yourNameWrapper)
conversations.parentElement.insertBefore(myConvoBanner, conversations.parentElement.firstElementChild)
addCss(`
.myConvoBanner input {
font-family: Lato;
border:none;
background-color:transparent;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.myConvoBanner {
padding: 8px 16px;
cursor: pointer;
}
.myConvoBanner:hover {
background-color: #00000022;
}
.workspaceTitle {
font-size: ${headerFontSize};
font-weight: bold;
text-overflow: ellipsis;
color: #ffffff;
}
.yourName {
font-size: 15px;
padding-top: 2px;
color: #ffffff88;
margin: 0;
}
.yourNameWrapper::before {
padding-right: 7px;
content: "●";
color: #00FFB7;
}
`)
let myConvoPanel = document.createElement('div')
myConvoPanel.classList.add("myConvoPanel")
let channelsLabel = document.createElement('p')
channelsLabel.classList.add("channelsLabel")
channelsLabel.appendChild(document.createTextNode("Channels"))
myConvoPanel.appendChild(channelsLabel)
conversations.parentElement.insertBefore(myConvoPanel, conversations)
addCss(`
.myConvoPanel {
height: 28px;
cursor: pointer;
}
.channelsLabel {
font-weight: bold;
transition: color 0.1s linear;
margin: 0;
padding-left: 12px;
color: #ffffff88;
}
.channelsLabel:hover {
color: #ffffff;
}
.channelsLabel::after {
float: right;
content: "⨁";
font-weight: bold;
padding-right: 15px;
color: #ffffff88;
}
`)
// Poll for unread conversation (there may be no unread conversations on first load)
const unreadConvoPoll = setInterval(() => {
// highlighted conversations have aria-relevant="additions text"
const highlightedConversations = document.querySelectorAll('[aria-relevant="additions text"]');
// unread conversations have aria-live="polite"
const unreadConversation = Array.from(highlightedConversations).filter(node => node.outerHTML.includes('aria-live="polite"'))[0]
if (unreadConversation) {
clearInterval(unreadConvoPoll);
// unread circle badge notification
const unreadBadge = unreadConversation.children[1].firstElementChild
const unreadBadgeSelector = unreadBadge.classList[1]
addCss('.' + unreadBadgeSelector + '{ display: none }');
// ie _1ht3
const unreadConversationSelector = unreadConversation.classList[3];
const unreadConversationTitle = unreadConversation.firstElementChild.firstElementChild.firstElementChild.children[1].firstElementChild.firstElementChild
// ie _1ht6
const unreadConversationTitleSelector = unreadConversationTitle.classList[0]
// ie "._1ht3 ._1ht6"
addCss('.' + unreadConversationSelector + ' .' + unreadConversationTitleSelector + `{ color: #ffffff; }`);
injectCss();
}
}, 2000);
// Poll for selected conversation (there may be no selected conversations on first load)
const selectedConvoPoll = setInterval(() => {
// highlighted conversations have aria-relevant="additions text"
const highlightedConversations = document.querySelectorAll('[aria-relevant="additions text"]');
// unread conversations have aria-live="polite"
const selectedConvo = Array.from(highlightedConversations).filter(node => !node.outerHTML.includes('aria-live="polite"'))[0]
if (selectedConvo) {
clearInterval(selectedConvoPoll);
const selectedConvoSelector = selectedConvo.classList[3];
addCss('.' + selectedConvoSelector + `{
background-color: #8c5888 !important;
color: white;
}`);
injectCss();
}
}, 2000);
injectCss();
}
pollForElement('[role="main"]', 10000, mainpanel)
function mainpanel() {
const main = document.querySelector('[role="main"]');
const mainHeader = main.getElementsByTagName('span')[0].firstElementChild
// ie _673w
const mainHeaderSelector = mainHeader.classList[0]
const mainHeaderCallIcons = mainHeader.children[1]
// ie _fl2
const mainHeaderCallIconsSelector = mainHeaderCallIcons.classList[0]
// ie "._673w ._fl2"
// TODO: Modify icons to look like slack
// addCss('.' + mainHeaderSelector + ' .' + mainHeaderCallIconsSelector + `{ display: none }`);
// Modify svg paths
addCss(`
path {
fill: white;
stroke: #1d1c1d70;
stroke-width: 1px;
}
`)
const mainHeaderTitle = mainHeader.firstElementChild
// Photo takes a while to load so poll
const mainHeaderPhotoPoll = setInterval(() => {
if (mainHeaderTitle.children.length === 2) {
clearInterval(mainHeaderPhotoPoll)
const mainHeaderPhoto = mainHeaderTitle.firstElementChild
const mainHeaderPhotoSelector = mainHeaderPhoto.classList[0]
addCss('.' + mainHeaderPhotoSelector + '{ display: none }');
// const mainHeaderTitleSubtext = mainHeaderTitle.children[2].firstElementChild
//TODO: Add icons and stuff to subtext
addCss(`
.${mainHeaderSelector} h2 {
font-size: ${headerFontSize} !important;
font-weight: 900 !important;
}
.${mainHeaderSelector} h2::before {
content: "#";
padding-right: 1px;
font-size: 17px;
}
`);
injectCss();
}
}, 500)
const newMessage = document.querySelector('[aria-label="New message"]').firstElementChild
const newMessageSelector = newMessage.classList['value'].replace(' ', '.')
addCss(`
.${newMessageSelector} {
margin: 0 20px 20px 20px;
border: 1px solid ${darkGreyColor};
border-radius: 5px;
}
`);
const newMessageBox = newMessage.children[3]
const newMessageBoxSelector = newMessageBox.classList[0]
addCss(`
.${newMessageBoxSelector} {
background-color: white;
}
`);
injectCss();
}
pollForElement('[aria-label="Messages"]', 10000, messages)
function messages() {
//ie _1wfr
const messagesPanelSelector = document.querySelector('[role="presentation"]').firstElementChild.classList[1]
addCss(`.${messagesPanelSelector} { padding: 0; }`)
const infoPanel = document.querySelector('[data-testid="info_panel"]')
if (infoPanel) {
const infoPanelSelector = infoPanel.classList
//TODO: Add a threads looking panel here
addCss(`.${infoPanelSelector} { display: none; }`)
}
const messagesSelector = document.querySelector('[aria-label="Messages"]').classList[0]
addCss(`
.${messagesSelector} {
padding-bottom: 10px;
}
.${messagesSelector} h4 {
margin: 32px;
width: 90%;
border-bottom: 1px solid #000;
border-color: ${lightGreyColor};
line-height: 0.1em;
font-weight: bold;
color: ${lighterDarkGreyColor};
}
.${messagesSelector} time {
padding: 8px 16px;
background: white;
}
`)
const messagesElem = document.querySelector('[aria-label="Messages"]').children[2]
// Find your sent messages aka float right bubbles
const pollForMyMessage = setInterval(() => {
const myMessage = Array.from(messagesElem.children).filter(message => {
const someElement = message.firstElementChild.firstElementChild
if (someElement) {
if (someElement.firstElementChild)
// Messages sent by yourself will have an h5 element
return someElement.firstElementChild.nodeName === 'H5'
}
})[0]
if (myMessage) {
clearInterval(pollForMyMessage)
const otherMessage = Array.from(messagesElem.children).filter(message => {
return message.firstElementChild.children.length === 2
})[0]
// the random div on top of messages sent by other people
// ie _1t_q
const randomEmptySpaceSelector = otherMessage.firstElementChild.firstElementChild.classList[0]
addCss(`.${randomEmptySpaceSelector} { height: 0 }`)
// ie _1t_p
const messageGroupSelector = otherMessage.firstElementChild.classList[0]
const messageSenderPhotoWrapper = otherMessage.firstElementChild.firstElementChild.firstElementChild.firstElementChild
// ie _4ldz
const messageSenderPhotoWrapperSelector = messageSenderPhotoWrapper.classList[0]
// the selector that sets absolute position and bottom: 2
// ie
const messageSenderPhotoWrapper2Selector = messageSenderPhotoWrapper.classList[1]
const messageSenderPhoto = otherMessage.firstElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild
// ie _4ld-
const messageSenderPhotoSelector = messageSenderPhoto.classList[0]
addCss(`
.${messageGroupSelector} {
padding: 6px 22px;
margin-bottom: 0;
}
.${messageGroupSelector}:hover {
background-color: #eeeeee88;
}
.${messageGroupSelector} h5 {
font-size: 15px;
font-weight: bold;
color: ${darkGreyColor};
cursor: pointer;
}
.${messageGroupSelector} h5:hover {
text-decoration: underline;
}
.${messageSenderPhotoWrapper2Selector} {
bottom: inherit !important;
top: 8px !important;
}
.${messageSenderPhotoWrapperSelector} {
transform: none !important;
height: ${messageSenderPhotoSize} !important;
width: ${messageSenderPhotoSize} !important;
max-height: ${messageSenderPhotoSize} !important;
max-width: ${messageSenderPhotoSize} !important;
}
.${messageSenderPhotoSelector} {
border-radius: 3px;
max-height: ${messageSenderPhotoSize} !important;
max-width: ${messageSenderPhotoSize} !important;
height: ${messageSenderPhotoSize} !important;
width: ${messageSenderPhotoSize} !important;
}
.${messageSenderPhotoSelector} img {
min-height: ${messageSenderPhotoSize} !important;
min-width: ${messageSenderPhotoSize} !important;
height: ${messageSenderPhotoSize} !important;
width: ${messageSenderPhotoSize} !important;
}
`)
const myMessageGroup = myMessage.firstElementChild.firstElementChild.firstElementChild
// ie _ih3
const messageSenderSelector = myMessageGroup.classList[0]
const myMessageExample = myMessage.firstElementChild.firstElementChild.children[1]
// the one unique class that makes the message float right
// ie _3i_m
const myBubbleSelector = myMessageExample.classList[3]
const myMessageExampleText = myMessage.firstElementChild.firstElementChild.children[1].firstElementChild
// ie _3058
const myMessageExampleTextSelector = myMessageExampleText.classList[0]
// ie _hh7
const messageTextSelector = myMessageExampleText.classList[2]
addCss(`
.${messageSenderSelector} {
clip: inherit !important;
height: inherit !important;
width: inherit !important;
position: inherit !important;
white-space: nowrap;
opacity: 1 !important;
}
.${myBubbleSelector} .${myMessageExampleTextSelector} {
float: left !important;
}
.${myMessageExampleTextSelector} {
padding: 1px 12px !important;
margin: 0 !important;
}
.${messageTextSelector} {
background-color: transparent !important;
background-image: none !important;
color: ${darkGreyColor} !important;
}
`)
injectCss()
}
}, 1000);
injectCss();
}
// Message requests has a div with id message-dots
pollForElement('#message-dots', 10000, removeMessageRequests)
function removeMessageRequests() {
const messageDots = document.querySelector('#message-dots');
const messageRequests = messageDots.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement
messageRequests.style['display'] = 'none'
}
// From https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
// This function calls onMutation when new conversations are loaded in the DOM
function beginObserve() {
// Select the node that will be observed for mutations
const targetNode = document.querySelector('[aria-label="Conversation List"]');
// Options for the observer (which mutations to observe)
const config = { childList: true };
// Callback function to execute when mutations are observed
const onMutation = function (mutationsList, observer) {
if (mutationsList[0].type === 'childList') {
console.log('Child nodes added or removed.');
// TODO: Process new conversations
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(onMutation);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
}