-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
83 lines (66 loc) · 2.25 KB
/
index.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
// Port from vizality plugin "Who Said What"
// Vizality plugin: https://github.com/valentinegb/who-said-what
const { Plugin } = require('powercord/entities');
const { getModule } = require('powercord/webpack');
const regModule = getModule(['register'], false);
let interval;
let index = 0;
let original;
module.exports = class MessageLog extends Plugin {
async startPlugin() {
let deleted = [];
const styleMessage = async ({ id }) => {
let el = document.getElementById(`chat-messages-${id}`);
if (!el) return;
if (el.classList.contains('deleted-message')) return;
el.classList.add('deleted-message');
};
const run = () => {
for (let obj of deleted) {
styleMessage(obj);
}
};
const getHandler = (regModule) => {
return regModule._actionHandlers._orderedActionHandlers.MESSAGE_DELETE.find(e => e.actionHandler.toString().includes('revealedMessageId'));
};
const setup = () => {
try {
original = getHandler(regModule);
} catch (e) {
return setTimeout(setup, 1000);
}
index = regModule._actionHandlers._orderedActionHandlers.MESSAGE_DELETE.indexOf(
getHandler(regModule)
);
const originalActionHandler =
regModule._actionHandlers._orderedActionHandlers.MESSAGE_DELETE[index].actionHandler;
const originalstoreDidChange =
regModule._actionHandlers._orderedActionHandlers.MESSAGE_DELETE[index].storeDidChange;
regModule._actionHandlers._orderedActionHandlers.MESSAGE_DELETE[index] = {
actionHandler: (obj) => {
if (document.getElementById(`chat-messages-${obj.id}`)?.className.includes('ephemeral')) {
return originalActionHandler(obj);
}
if (deleted.find((x) => x.id === obj.id)) return;
deleted.push(obj);
styleMessage(obj);
},
storeDidChange: (obj) => {
if (document.getElementById(`chat-messages-${obj.id}`)?.className.includes('ephemeral')) {
return originalstoreDidChange(obj);
}
}
};
};
interval = setInterval(run, 300);
this.loadStylesheet('./styles.css');
setup();
}
async pluginWillUnload() {
clearInterval(interval);
for (let e of document.getElementsByClassName('deleted-message')) {
e.remove();
}
regModule._actionHandlers._orderedActionHandlers.MESSAGE_DELETE[index] = original;
}
}