/
content.js
189 lines (132 loc) · 5.29 KB
/
content.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
// Taken from WABot wiki page: https://github.com/aalsuwaidi/wabot/wiki/WhatsApp-Web under heading 'Webpack and finding the Store'
// Returns promise that resolves to all installed modules
function getAllModules() {
return new Promise((resolve) => {
const id = _.uniqueId('fakeModule_');
window['webpackJsonp'](
[], {
[id]: function(module, exports, __webpack_require__) {
resolve(__webpack_require__.c);
}
}, [id]
);
});
}
// Get module by ID found from the function above
function _requireById(id) {
return webpackJsonp([], null, [id]);
}
// Module IDs
var createFromData_id = 0;
var prepareRawMedia_id = 0;
var store_id = 0;
var Store = {};
var DiffStore = [];
var modules = getAllModules()._value;
// Automatically locate modules
for (var key in modules) {
if (modules[key].exports) {
if (modules[key].exports.createFromData) {
createFromData_id = modules[key].id.replace(/"/g, '"');
}
if (modules[key].exports.prepRawMedia) {
prepareRawMedia_id = modules[key].id.replace(/"/g, '"');
}
if (modules[key].exports.default) {
if (modules[key].exports.default.Wap) {
store_id = modules[key].id.replace(/"/g, '"');
}
}
}
}
function findAlreadyDeletedMessages() {
for (var x = 0; x < Store.Msg.models.length; x++) {
messageObj = Store.Msg.models[x];
DiffStore[x] = {
"__x_body": String(messageObj.__x_body),
"__x_type": String(messageObj.__x_type),
};
if (String(messageObj.__x_body == "undefined")) {
//console.log("wtf is it undefined?");
//console.log(messageObj);
}
if (messageObj.__x_type == "revoked" && messageObj.hasOwnProperty("__x_body")) // deleted messages
{
//if we have older messages lets just change the type
Store.Msg.models[x].__x_type = "revokedAndSeenByWhatsAppDoc";
}
}
console.log("starting Monitor phase");
var scanForDelete = setInterval(function() {
//Lets DIFF BABY
//var t0 = performance.now();
for (var x = 0; x < Store.Msg.models.length; x++) {
messageObj = Store.Msg.models[x];
if (messageObj.__x_type == "revoked" && messageObj.hasOwnProperty("__x_body")) // deleted messages
{
// This _only_ returns chat types, for things like images/audio/video/files you'd have to get the client to download the files from the Store object and then keep them locally and it seems like a bunch of work. However you can get the thumbnail as a B64 image from the __x_body
if (DiffStore[x].__x_type == "chat") {
console.log("Found a deleted chat message! Here is the original:");
console.log(DiffStore[x].__x_body);
Store.Msg.models[x].__x_type = "chat";
Store.Msg.models[x].__x_body = "This Message was deleted: '" + DiffStore[x].__x_body + "'";
} else if (DiffStore[x].__x_type == "image") {
console.log("Found a deleted image! We only have the thumbnail, but in B64 its: " + DiffStore[x].__x_body);
Store.Msg.models[x].__x_type = "chat";
Store.Msg.models[x].__x_body = "This image was deleted but we have a B64 of it in console..";
}
}
}
//var t1 = performance.now();
//console.log("Call to diff messages took " + (t1 - t0) + " milliseconds.")
}, 1000);
}
/* Extension Code */
function init(initialNumber) {
var startLogging = false;
Store = _requireById(store_id).default;
var keys = Object.keys(Store.Wap);
//Here we add the messages as they come in to our 'DiffStore'
Store.Msg.models.push = function(message) {
Array.prototype.push.call(this, message);
if (startLogging == true) {
DiffStore.push({
"__x_body": String(message.__x_body),
"__x_type": String(message.__x_type),
});
}
};
Store.Msg.models.onPush = function(message) {
console.log("onPush message?:");
console.log((Store.Msg.models));
}
Store.Chat.models.pop = function(message) {
Array.prototype.push.call(this, message);
console.log("Popped chat model Message");
this.onPush(message);
};
Store.Chat.models.onPop = function(message) {
console.log("onPop chat model message:");
console.log(message);
}
var initialSetup = setInterval(function() {
if (Store.Msg.models.length >= initialNumber) {
findAlreadyDeletedMessages();
startLogging = true;
clearInterval(initialSetup);
}
}, 500);
}
var WhatsAppWebLoaded = setInterval(function() {
Store = _requireById(store_id).default;
if (Store.Msg.models.length > 1) {
clearInterval(WhatsAppWebLoaded);
setTimeout(function() {
console.log("Starting with " + Store.Msg.models.length + " messages in model.");
init(Store.Msg.models.length);
console.log("Loaded!");
}, 3000);
} else {
console.log("Waiting for app...");
}
}, 1000);