Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * WhatsApp Chrome Extension
- */
- (function() {
- var interval = setInterval(function () {
- var selector = document.querySelector(".app-wrapper-main");
- if(selector) {
- clearInterval(interval);
- setTimeout(startService, 2000);
- }
- }, 500);
- function startService()
- {
- console.debug("[FASTEE] Service ready");
- longPullCreationQueue();
- var chats = document.querySelectorAll(".chatlist .chat"), i, flag = false;
- for(i = 0;i<chats.length;i++) {
- watchNode(chats[i], function(mutations) {
- var chat;
- mutations.forEach(function(mutation) {
- chat = mutation.target.parentNode.parentNode.parentNode.parentNode.parentNode;
- activeChat = chat.className.indexOf("active") > -1;
- if(!activeChat && mutation.target.className == 'icon-meta unread-count' && (mutation.type == 'childList' || (mutation.type == 'attributes' && mutation.attributeName == 'class'))) {
- flag = true;
- }
- });
- if(flag) {
- flag = false;
- handleBackgroundNotification(chat);
- }
- });
- }
- }
- function watchNode(target, callback)
- {
- // create an observer instance
- var observer = new MutationObserver(function(mutations) {
- callback(mutations, observer);
- });
- // configuration of the observer:
- var config = { childList: true, characterData: true, subtree: true };
- // pass in the target node, as well as the observer options
- observer.observe(target, config);
- }
- function handleBackgroundNotification(chat)
- {
- var offsetTop = window.innerHeight-window.screen.availHeight;
- var x = chat.getBoundingClientRect().left + (chat.offsetWidth/2);
- var y = offsetTop + chat.getBoundingClientRect().top + (chat.offsetHeight/2)
- var chatId = chat.getAttribute("data-reactid");
- triggerMouse(x, y).then(function() {
- console.debug("[FASTEE] Background notification handled")
- setTimeout(function () {
- markHandledMessages().then(function(response) {
- watchNode(document.querySelector("#pane-side"), function(mutations, callback) {
- markHandledMessages(true);
- })
- });
- }, 500);
- });
- }
- function markHandledMessages(active)
- {
- active = active||false;
- return new Promise(function(resolve, reject) {
- var messages = document.querySelectorAll(".message-list .msg"), i, flag = false, newMessages = [];
- for(i = 0;i<messages.length;i++) {
- if(!active && messages[i].className.indexOf('msg-unread') > -1) {
- flag = true;
- continue;
- }
- else if(active && !messages[i].getAttribute("fastee-marked") && messages[i].className.indexOf('msg-unread') == -1) {
- flag = true;
- }
- if(flag) {
- newMessages.push(getMessage(messages[i]));
- }
- messages[i].setAttribute("fastee-marked", true);
- }
- console.debug("[FASTEE] All messages processed with FASTEE", newMessages)
- resolve(newMessages)
- });
- }
- function getMessage(messageNode)
- {
- var loop = false;
- if(messageNode.querySelector(".message-author .emojitext")) {
- owner = messageNode.querySelector(".message-author .emojitext").innerText;
- }
- else {
- var chatlist = document.querySelectorAll(".chatlist .msg"), i, loop = false;
- messageNode.setAttribute("fastee-target", true);
- for(i = chatlist.length;i>0;i--) {
- if(chatlist[i].getAttribute("fastee-target")) {
- loop = true;
- continue ;
- }
- if(loop && chatlist[i].querySelector(".message-author .emojitext")) {
- owner = chatlist[i].querySelector(".message-author .emojitext");
- }
- }
- messageNode.removeAttribute("fastee-target")
- }
- return {
- id : messageNode.getAttribute("data-reactid"),
- owner : owner,
- text : messageNode.querySelector(".message-text .emojitext").innerHTML,
- };
- }
- window.newGroup = function(name, members, owner, ownerUid, forumId, conversationId)
- {
- return new Promise(function(resolve, reject) {
- document.querySelector(".pane-list-controls .menu-item:last-child").click();
- setTimeout(function () {
- document.querySelector(".pane-list-controls .active .dropdown a:first-child").click();
- triggerKeyboard(name).then(function() {
- if(!document.querySelector(".drawer-container-new-group .drawer-controls button")) {
- reject();
- return ;
- }
- document.querySelector(".drawer-container-new-group .drawer-controls button").click();
- setTimeout(function () {
- // var i = 0, hold = false;
- // while(i < members.length) {
- // if(hold) continue;
- //
- // hold = true;
- // triggerKeyboard(members[i]).then(function() {
- // document.querySelector(".chatlist .contact:first-child").click();
- // i++;
- // hold = false;
- // });
- // }
- createMembers(name, members, owner, ownerUid, forumId, conversationId);
- }, 1000);
- });
- }, 100);
- });
- }
- function updateChatCreated(owner, ownerUid, forumId, conversationId, chatId) {
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4) {
- if(xmlHttp.status == 204) {
- // resolve();
- }
- // else
- // error(xmlHttp);
- }
- };
- xmlHttp.open("POST", server.site+"/"+ownerUid+"/WHATSAPP/chats", true); // true for asynchronous
- xmlHttp.setRequestHeader("Authorization","Basic "+window.btoa(owner+":?"));
- xmlHttp.setRequestHeader("Session-Id",user.SessionId);
- xmlHttp.setRequestHeader("Content-Type","application/json;charset=UTF-8");
- xmlHttp.send(JSON.stringify({
- forumId: forumId,
- conversationId: conversationId,
- chatId: chatId
- }));
- window.location.reload();
- }
- var i = -1;
- function createMembers(name, members, owner, ownerUid, forumId, conversationId)
- {
- i++;
- if(i == members.length) {
- i = -1;
- document.querySelector(".drawer-new-group .drawer-controls button").click();
- setTimeout(function() {
- updateChatCreated(owner, ownerUid, forumId, conversationId, document.querySelector(".chatlist .chat:first-child").getAttribute("data-reactid"))
- }, 5000)
- return ;
- }
- var member = members[i];
- document.querySelector(".new-group-search input").value = "";
- triggerKeyboard(member).then(function() {
- if(document.querySelector(".chatlist .contact:first-child")) {
- document.querySelector(".chatlist .contact:first-child").click();
- }
- setTimeout(function() {
- createMembers(name, members, owner, ownerUid, forumId, conversationId);
- }, 100)
- });
- }
- window.sendMessage = function(chatId, text)
- {
- document.querySelector(".chatlist .chat[data-reactid='"+chatId+"']").click();
- triggerKeyboard(text).then(function() {
- document.querySelector("footer .block-compose button.send-container").click();
- });
- }
- var server = {
- local: "http://localhost/stagingfastee/d9b762932b90c3f8aa99aa47aaf57a08",
- site: "https://stagingsdk.fastee.co/appserv.svc",
- }
- var user = {
- uid: "d9b762932b90c3f8aa99aa47aaf57a08",
- email: "pub.whatsapp@fastee.co",
- password: "?",
- Authorization: "Basic cHViLndoYXRzYXBwQGZhc3RlZS5jbzo/",
- }
- setTimeout(function () {
- user.SessionId = generateUUID();
- }, 100);
- function triggerKeyboard(str)
- {
- return new Promise(function(resolve, error) {
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4) {
- if(xmlHttp.status == 204) {
- setTimeout(function () {
- resolve(xmlHttp);
- }, 500);
- }
- else
- error(xmlHttp);
- }
- };
- xmlHttp.open("POST", server.local+"/WHATSAPP/sendkeys", true); // true for asynchronous
- xmlHttp.setRequestHeader("Authorization",user.Authorization);
- xmlHttp.send(JSON.stringify({
- text: str,
- }));
- })
- }
- function triggerMouse(x, y)
- {
- return new Promise(function(resolve, error) {
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4) {
- if(xmlHttp.status == 204) {
- setTimeout(function () {
- resolve(xmlHttp);
- }, 500);
- }
- else
- error(xmlHttp);
- }
- };
- xmlHttp.open("POST", server.local+"/WHATSAPP/mouseclick".replace("{uid}", user.uid), true); // true for asynchronous
- xmlHttp.setRequestHeader("Authorization",user.Authorization);
- xmlHttp.setRequestHeader("Content-Type","application/json");
- xmlHttp.send(JSON.stringify({
- x: x,
- y: y,
- }));
- })
- }
- function longPullCreationQueue()
- {
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.onreadystatechange = function() {
- if (xmlHttp.readyState == 4) {
- if(xmlHttp.status == 200) {
- var response = JSON.parse(xmlHttp.responseText).chat;
- window.newGroup(response.topic, response.members, response.owner, response.ownerUid, response.forumId, response.conversationId).then(function() {
- longPullCreationQueue();
- });
- }
- else if(xmlHttp.status == 204) {
- longPullCreationQueue()
- }
- // else
- // error(xmlHttp);
- }
- };
- xmlHttp.open("GET", server.site+"/"+user.uid+"/WHATSAPP/chats", true); // true for asynchronous
- xmlHttp.setRequestHeader("Authorization",user.Authorization);
- xmlHttp.setRequestHeader("Session-Id",user.SessionId);
- xmlHttp.send();
- }
- var history = [];
- function generateUUID(){
- var d = new Date().getTime();
- var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
- var r = (d + Math.random()*16)%16 | 0;
- d = Math.floor(d/16);
- return (c=='x' ? r : (r&0x3|0x8)).toString(16);
- });
- history.push(uuid)
- return uuid;
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement