Skip to content

Instantly share code, notes, and snippets.

@vaibhavgeek
Created July 24, 2018 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaibhavgeek/56a1c24c4bbf72be50b7f8989aa5ca38 to your computer and use it in GitHub Desktop.
Save vaibhavgeek/56a1c24c4bbf72be50b7f8989aa5ca38 to your computer and use it in GitHub Desktop.
whatsapp.js
function isChatMessage(message) {
if (message.__x_isSentByMe) {
return false;
}
if (message.__x_isNotification) {
return false;
}
if (!message.__x_isUserCreatedType) {
return false;
}
return true;
}
function getUnreadChats() {
var Chats = Store.Chat.models;
var Output = [];
for (chat in Chats) {
if (isNaN(chat)) {
continue;
};
var temp = {};
temp.contact = Chats[chat].__x_formattedTitle;
temp.id = Chats[chat].__x_id;
temp.messages = [];
var messages = Chats[chat].msgs.models;
for (var i = messages.length - 1; i >= 0; i--) {
if (!messages[i].__x_isNewMsg) {
break;
} else {
if (!isChatMessage(messages[i])) {
continue
}
messages[i].__x_isNewMsg = false;
temp.messages.push({
message: messages[i].__x_body,
timestamp: messages[i].__x_t,
type : messages[i].__x_type,
e : messages[i]
});
}
}
if(temp.messages.length > 0) {
Output.push(temp);
}
}
console.log("Unread messages: ", Output);
return Output;
}
setTimeout(function() {
// 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]
);
});
}
var modules = getAllModules()._value;
// Automatically locate modules
for (var key in modules) {
if (modules[key].exports) {
if (modules[key].exports.default) {
if (modules[key].exports.default.Wap) {
store_id = modules[key].id.replace(/"/g, '"');
}
}
}
}
}, 5000);
function _requireById(id) {
return webpackJsonp([], null, [id]);
}
// Module IDs
var store_id = 0;
var Store = {};
function init() {
Store = _requireById(store_id).default;
console.log("Store is ready" + Store);
}
setTimeout(function() {
init();
}, 7000);
function sendMsg (id, text) {
if (window.Store === undefined) {
webpackJsonp([], {"bcihgfbdeb": (x, y, z) => window.Store = z('"bcihgfbdeb"')}, "bcihgfbdeb");
webpackJsonp([], {"iaeeehaci": (x, y, z) => window.Store.Wap = z('"iaeeehaci"')}, "iaeeehaci");
}
var Chats = Store.Chat.models;
var contact = id;
var message = text;
for (chat in Chats) {
if (isNaN(chat)) {
continue;
};
var temp = {};
temp.contact = Chats[chat].__x__formattedTitle;
temp.id = Chats[chat].__x_id;
if(temp.id.search(contact)!=-1 && temp.id.search('g.us')==-1 ){
Chats[chat].sendMessage(message);
return true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment