-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelement.user.js
73 lines (65 loc) · 2.49 KB
/
element.user.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
// ==UserScript==
// @name Element.io tweak
// @namespace https://github.com/lilydjwg/userscripts
// @description Element.io tweak
// @match https://chat.mozilla.org/*
// @match https://app.element.io/*
// @match https://element.catgirl.cloud/*
// @match https://app.schildi.chat/*
// @version 0.1.4
// @run-at document-idle
// @grant none
// @sandbox JavaScript
// ==/UserScript==
const ICON_URL = 'https://telegram.org/img/website_icon.svg'
const img = document.createElement('img')
img.src = ICON_URL
img.style.position = 'relative'
img.style.top = '20px'
img.style.left = '-10px'
img.style.pointerEvents = 'none'
const img_typing = img.cloneNode()
img_typing.style.width = '12px'
img_typing.style.height = '12px'
img_typing.style.top = '16px'
img_typing.style.left = '-8px'
const img_member = img.cloneNode()
img_member.style.width = '8px'
img_member.style.height = '8px'
img_member.style.top = '7px'
img_member.style.left = '-6px'
// no longer works
const img_reply = img.cloneNode()
img_reply.style.width = '8px'
img_reply.style.height = '8px'
img_reply.style.top = '6px'
img_reply.style.left = '-6px'
img_reply.style.marginRight = '-6px'
function insertAfter(location, newnode) {
if(location.nextSibling) {
location.parentNode.insertBefore(newnode, location.nextSibling)
}else{
location.parentNode.appendChild(newnode)
}
}
function doit() {
for(let avatar of document.querySelectorAll('ol.mx_RoomView_MessageList [title^="@telegram_"][title$=":t2bot.io"], ol.mx_RoomView_MessageList [title^="@telegram_"][title$=":nichi.co"], ol.mx_RoomView_MessageList [title^="@telegram_"][title$=":moe.cat"], ol.mx_RoomView_MessageList [title^="@perigram_"][title$=":neo.angry.im"], ol.mx_RoomView_MessageList [title^="@tg_"][title$=":moechat.kimiblock.top"]')) {
const width = avatar.width
if(avatar.parentNode.tagName == 'SPAN' && avatar.parentNode.classList.contains('mx_Pill')) { // in reply to
if(avatar.nextSibling.nodeType == Node.TEXT_NODE) {
avatar.parentNode.insertBefore(img_reply.cloneNode(), avatar.nextSibling)
}
continue
}
if(!avatar.nextSibling || avatar.nextSibling.classList.contains('mx_DisambiguatedProfile')) {
if(width >= 24) {
insertAfter(avatar, img_typing.cloneNode())
}else if(width >= 14 && width <= 16) {
insertAfter(avatar, img_member.cloneNode())
} else {
insertAfter(avatar, img.cloneNode())
}
}
}
}
setInterval(doit, 1100)