-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.js
1 lines (1 loc) · 35 KB
/
inject.js
1
(function(){function I(){function e(t){let n=0,a=[{id:"Store",conditions:i=>i.default&&i.default.Chat&&i.default.Msg?i.default:null},{id:"MediaCollection",conditions:i=>i.default&&i.default.prototype&&i.default.prototype.processAttachments?i.default:null},{id:"MediaProcess",conditions:i=>i.BLOB?i:null},{id:"Wap",conditions:i=>i.createGroup?i:null},{id:"About",conditions:i=>i.getAbout?i:null},{id:"ServiceWorker",conditions:i=>i.default&&i.default.killServiceWorker?i:null},{id:"State",conditions:i=>i.STATE&&i.STREAM?i:null},{id:"WapDelete",conditions:i=>i.sendConversationDelete&&i.sendConversationDelete.length==2?i:null},{id:"Conn",conditions:i=>i.default&&i.default.ref&&i.default.refTTL?i.default:null},{id:"Cmd",conditions:i=>i.Cmd?i.Cmd:null},{id:"Me",conditions:i=>i.getMeUser?i:null},{id:"WapQuery",conditions:i=>i.default&&i.default.queryExist?i.default:null},{id:"CryptoLib",conditions:i=>i.decryptE2EMedia?i:null},{id:"OpenChat",conditions:i=>i.default&&i.default.prototype&&i.default.prototype.openChat?i.default:null},{id:"ChatStates",conditions:i=>i.sendChatStatePaused&&i.sendChatStateRecording&&i.sendChatStateComposing?i:null},{id:"UserConstructor",conditions:i=>i.default&&i.default.prototype&&i.default.prototype.isServer&&i.default.prototype.isUser?i.default:null},{id:"SendTextMsgToChat",conditions:i=>i.sendTextMsgToChat?i.sendTextMsgToChat:null},{id:"SendSeen",conditions:i=>i.sendSeen?i.sendSeen:null},{id:"sendDelete",conditions:i=>i.sendDelete?i.sendDelete:null},{id:"USyncQuery",conditions:i=>i.USyncQuery?i.USyncQuery:null},{id:"USyncUser",conditions:i=>i.USyncUser?i.USyncUser:null},{id:"CreateUser",conditions:i=>i.default&&i.default.prototype&&i.default.prototype.isServer&&i.default.prototype.isUser?i.default:null},{id:"ProfilePicThumbCollection",conditions:i=>i.ProfilePicThumbCollection?i.ProfilePicThumbCollection:null},{id:"StatusCollection",conditions:i=>i.StatusCollection?i.StatusCollection:null},{id:"_Presence",conditions:i=>i.setPresenceAvailable&&i.setPresenceUnavailable?i:null},{id:"getNumChatsPinned",conditions:i=>i.getNumChatsPinned?i:null},{id:"themeFn",conditions:i=>i.ThemeContext?i:null},{id:"findChat",conditions:i=>i&&i.findChat?i.findChat:null},{id:"createWid",conditions:i=>i&&i.createDeviceWid&&i.createWid?i.createWid:null},{id:"colorIndexToHex",conditions:i=>i&&i.colorIndexToHex?i.colorIndexToHex:null},{id:"DeleteChat",conditions:i=>i&&i.default&&i.default.getDeleteChatMutation?i.default.getDeleteChatMutation:null}];for(let i in t)if(typeof t[i]=="object"&&t[i]!==null&&(a.forEach(u=>{if(!u.conditions||u.foundedModule)return;let c=u.conditions(t[i]);c!==null&&(n++,u.foundedModule=c)}),n==a.length))break;let o=a.find(i=>i.id==="Store");return window.Store=o.foundedModule?o.foundedModule:{},a.splice(a.indexOf(o),1),a.forEach(i=>{i.foundedModule&&(window.Store[i.id]=i.foundedModule)}),window.Store.Chat.modelClass.prototype.sendMessage=function(i){window.Store.SendTextMsgToChat(this,...arguments)},window.Store}return new Promise((t,n)=>{if(document.querySelector("#pane-side")==null&&n("Page not loaded yet"),2.3>parseFloat(window.Debug.VERSION)){if(typeof webpackJsonp=="function"||webpackChunkwhatsapp_web_client)if(typeof webpackJsonp=="function")webpackJsonp([],{parasite:(a,o,i)=>{try{e(i),t()}catch(u){n(u)}}},["parasite"]);else{let a=new Date().getTime();webpackChunkwhatsapp_web_client.push([["parasite"+a],{},function(o,i,u){let c=[];for(let w in o.m){let p=o(w);c.push(p)}try{e(c),t()}catch(w){n(w)}}])}}else{let a={},o=self.require("__debug").modulesMap;Object.keys(o).filter(i=>i.includes("WA")&&i!=="WAWebEmojiPanelContentEmojiSearchEmpty.react").forEach(function(i){let u=o[i];if(u&&(a[i]={default:u.defaultExport,factory:u.factory,...u},Object.keys(a[i].default).length==0))try{self.ErrorGuard.skipGuardGlobal(!0),Object.assign(a[i],self.importNamespace(i))}catch{self.ErrorGuard.skipGuardGlobal(!1)}});try{e(a),t()}catch(i){n(i)}}})}var W=setInterval(()=>{I().then(()=>{window.WAPI={lastRead:{}},window.WAPI._serializeRawObj=e=>e?e.toJSON():{},window.WAPI.CheckPhoneRegister=async e=>{const t=new window.Store.USyncQuery().withContactProtocol();t.withUser(new window.Store.USyncUser().withPhone(`+${e}@c.us`)),t.withBusinessProtocol(),t.withDisappearingModeProtocol();let n=await t.execute();const{list:a}=n;if(a.length===1){const{contact:o}=a[0];if(o&&o.type==="in")return!0}return!1},window.WAPI.GetUserInfo=async e=>{let t=new window.Store.CreateUser(`${e}@c.us`,{intentionallyUsePrivateConstructor:!0});var n=await window.Store.ProfilePicThumbCollection.find(t),a=await window.Store.StatusCollection.find(t,void 0);return{avatar:n.__x_imgFull,sign:a.__x_status}},window.WAPI._serializeChatObj=e=>e==null?null:Object.assign(window.WAPI._serializeRawObj(e),{kind:e.kind,isGroup:e.isGroup,formattedTitle:e.formattedTitle,contact:e.contact?window.WAPI._serializeContactObj(e.contact):null,groupMetadata:e.groupMetadata?window.WAPI._serializeRawObj(e.groupMetadata):null,presence:e.presence?window.WAPI._serializeRawObj(e.presence):null,preMes:e.previewMessage}),window.WAPI._serializeContactObj=e=>e==null?null:Object.assign(window.WAPI._serializeRawObj(e),{verifiedName:e.verifiedName,isHighLevelVerified:e.isHighLevelVerified,isMe:e.isMe,isAddressBookContact:e.isAddressBookContact,isMyContact:e.isMyContact,isPSA:e.isPSA,isUser:e.isUser,isVerified:e.isVerified,isWAContact:e.isWAContact,labels:e.labels,profilePicThumbObj:e.profilePicThumb?WAPI._serializeProfilePicThumb(e.profilePicThumb):{},statusMute:e.statusMute,msgs:null}),window.WAPI._serializeMessageObj=e=>e==null?null:Object.assign(window.WAPI._serializeRawObj(e),{id:e.id._serialized,sender:e.senderObj?WAPI._serializeContactObj(e.senderObj):null,timestamp:e.t,content:e.body,isGroupMsg:e.isGroupMsg,isLink:e.isLink,isMMS:e.isMMS,isMedia:e.isMedia,isNotification:e.isNotification,isPSA:e.isPSA,type:e.type,chat:WAPI._serializeChatObj(e.chat),chatId:e.id.remote,quotedMsgObj:WAPI._serializeMessageObj(e._quotedMsgObj),mediaData:window.WAPI._serializeRawObj(e.mediaData)}),window.WAPI._serializeNumberStatusObj=e=>e==null?null:Object.assign({},{id:e.jid,status:e.status,isBusiness:e.biz===!0,canReceiveMessage:e.status===200}),window.WAPI._serializeProfilePicThumb=e=>e==null?null:Object.assign({},{eurl:e.eurl,id:e.id,img:e.img,imgFull:e.imgFull,raw:e.raw,tag:e.tag}),window.WAPI.createGroup=function(e,t){return Array.isArray(t)||(t=[t]),window.Store.Wap.createGroup(e,t)},window.WAPI.leaveGroup=function(e){e=typeof e=="string"?e:e._serialized;var t=WAPI.getChat(e);return t.sendExit()},window.WAPI.getAllLabels=function(e){const t=window.Store.Label._models.map(n=>({id:n.id,name:n.name,color:WAPI.colorIndexToHex(n.colorIndex)}));return e!==void 0&&e(t),t},window.WAPI.getAllContacts=function(e){const t=window.Store.Contact.map(n=>WAPI._serializeContactObj(n));return e!==void 0&&e(t),t},window.WAPI.getMyContacts=function(e){const t=window.Store.Contact.filter(n=>{var a;return n.isAddressBookContact===1&&((a=n.id)==null?void 0:a.server)!=="lid"}).map(n=>WAPI._serializeContactObj(n));return e!==void 0&&e(t),t},window.WAPI.inMyContactModel=function(e,t){const n=window.Store.Contact.some(a=>a.id._serialized===e);return t!==void 0&&t(n),n},window.WAPI.getContact=function(e,t){const n=window.Store.Contact.get(e);return t!==void 0&&t(window.WAPI._serializeContactObj(n)),window.WAPI._serializeContactObj(n)},window.WAPI.getAllChats=function(e){const t=window.Store.Chat.map(n=>WAPI._serializeChatObj(n));return e!==void 0&&e(t),t},window.WAPI.haveNewMsg=function(e){return e.unreadCount>0},window.WAPI.getAllChatsWithNewMsg=function(e){const t=window.Store.Chat.filter(window.WAPI.haveNewMsg).map(n=>WAPI._serializeChatObj(n));return e!==void 0&&e(t),t},window.WAPI.getAllChatIds=function(e){const t=window.Store.Chat.map(n=>n.id._serialized||n.id);return e!==void 0&&e(t),t},window.WAPI.getAllGroups=async function(e){const t=await Promise.all(window.Store.Chat.filter(n=>n.isGroup).map(n=>window.Store.GroupMetadata.update(n.id).then(()=>{let{participants:a}=n.groupMetadata;return a=a.map(o=>o.contact).filter(o=>!o.isMe).map(o=>window.WAPI._serializeContactObj(o)),Object.assign(window.WAPI._serializeChatObj(n),{participants:a,canSend:n.canSend})})));return e!==void 0&&e(t),t},window.WAPI.getChat=function(e,t){e=typeof e=="string"?e:e._serialized;const n=window.Store.Chat.get(e);return n.sendMessage=n.sendMessage?n.sendMessage:function(){return window.Store.sendMessage.apply(this,arguments)},t!==void 0&&t(n),n},window.WAPI.getChatByName=function(e,t){const n=window.WAPI.getAllChats().find(a=>a.name.includes(e));return t!==void 0&&t(n),n},window.WAPI.getChatByPhone=function(e,t){const n=window.WAPI.getAllChats().find(a=>a.id&&a.id.user&&a.id.user==e);return t!==void 0&&t(n),n},window.WAPI.sendImageFromDatabasePicBot=function(e,t,n){var a=window.WAPI.getChatByName("DATABASEPICBOT"),o=a.msgs.find(c=>c.caption==e);if(o===void 0)return!1;var i=WAPI.getChat(t);if(i===void 0)return!1;const u=o.caption;return o.id.id=window.WAPI.getNewId(),o.id.remote=t,o.t=Math.ceil(new Date().getTime()/1e3),o.to=t,n!==void 0&&n!==""?o.caption=n:o.caption="",o.collection.send(o).then(function(c){o.caption=u}),!0},window.WAPI.sendMessageWithThumb=function(e,t,n,a,o,i,u){var c=WAPI.getChat(i);if(c===void 0)return u!==void 0&&u(!1),!1;var w={canonicalUrl:t,description:a,matchedText:t,title:n,thumbnail:e,compose:!0};return c.sendMessage(o,{linkPreview:w,mentionedJidList:[],quotedMsg:null,quotedMsgAdminGroupJid:null}),u!==void 0&&u(!0),!0},window.WAPI.getNewId=function(){for(var e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=0;n<20;n++)e+=t.charAt(Math.floor(Math.random()*t.length));return e},window.WAPI.getChatById=function(e,t){let n=WAPI.getChat(e);return n?n=WAPI._serializeChatObj(n):n=!1,t!==void 0&&t(n),n},window.WAPI.getUnreadMessagesInChat=function(e,t,n,a){let i=WAPI.getChat(e).msgs._models,u=[];for(let c=i.length-1;c>=0;c--){if(c==="remove")continue;let w=i[c];if(!(typeof w.isNewMsg!="boolean"||w.isNewMsg===!1)){w.isNewMsg=!1;let p=WAPI.processMessageObj(w,t,n);p&&u.push(p)}}return a!==void 0&&a(u),u},window.WAPI.loadEarlierMessages=function(e,t){const n=WAPI.getChat(e);t!==void 0?n.loadEarlierMsgs().then(function(){t()}):n.loadEarlierMsgs()},window.WAPI.loadAllEarlierMessages=function(e,t){const n=WAPI.getChat(e);x=function(){n.msgs.msgLoadState.noEarlierMsgs?t&&t():n.loadEarlierMsgs().then(x)},x()},window.WAPI.asyncLoadAllEarlierMessages=function(e,t){t(),window.WAPI.loadAllEarlierMessages(e)},window.WAPI.areAllMessagesLoaded=function(e,t){return WAPI.getChat(e).msgs.msgLoadState.noEarlierMsgs?(t&&t(!0),!0):(t&&t(!1),!1)},window.WAPI.loadEarlierMessagesTillDate=function(e,t,n){const a=WAPI.getChat(e);x=function(){a.msgs.models[0].t>t&&!a.msgs.msgLoadState.noEarlierMsgs?a.loadEarlierMsgs().then(x):n()},x()},window.WAPI.getAllGroupMetadata=function(e){const t=window.Store.GroupMetadata.map(n=>n.all);return e!==void 0&&e(t),t},window.WAPI.getGroupMetadata=async function(e,t){let n=window.Store.GroupMetadata.get(e);return n!==void 0&&n.stale&&await window.Store.GroupMetadata.update(e),t!==void 0&&t(n),n},window.WAPI._getGroupParticipants=async function(e){return(await WAPI.getGroupMetadata(e)).participants},window.WAPI.getGroupParticipantIDs=async function(e,t){const n=(await WAPI._getGroupParticipants(e)).map(a=>a.id);return t!==void 0&&t(n),n},window.WAPI.getGroupAdmins=async function(e,t){const n=(await WAPI._getGroupParticipants(e)).filter(a=>a.isAdmin).map(a=>a.id);return t!==void 0&&t(n),n},window.WAPI.getMe=function(e){const t=Store.Contact.getMeContact();return e!==void 0&&e(t),t},window.WAPI.isLoggedIn=function(e){const t=window.Store.Contact&&window.Store.Contact.checksum!==void 0;return e!==void 0&&e(t),t},window.WAPI.isConnected=function(e){const t=document.querySelector('*[data-icon="alert-phone"]')===null&&document.querySelector('*[data-icon="alert-computer"]')===null;return e!==void 0&&e(t),t},window.WAPI.processMessageObj=function(e,t,n){if(e.isNotification)return n?WAPI._serializeMessageObj(e):void 0;if(e.id.fromMe===!1||t)return WAPI._serializeMessageObj(e)},window.WAPI.getAllMessagesInChat=function(e,t,n,a){const o=WAPI.getChat(e);let i=[];const u=o.msgs._models;for(const c in u){if(c==="remove")continue;const w=u[c];let p=WAPI.processMessageObj(w,t,n);p&&i.push(p)}return a!==void 0&&a(i),i},window.WAPI.getAllMessageIdsInChat=function(e,t,n,a){const o=WAPI.getChat(e);let i=[];const u=o.msgs._models;for(const c in u)c==="remove"||!t&&u[c].isMe||!n&&u[c].isNotification||i.push(u[c].id._serialized);return a!==void 0&&a(i),i},window.WAPI.getMessageById=function(e,t){let n=!1;try{let a=window.Store.Msg.get(e);a&&(n=WAPI.processMessageObj(a,!0,!0))}catch{}if(t!==void 0)t(n);else return n},window.WAPI.ReplyMessage=function(e,t,n){var a=window.Store.Msg.get(e);if(a===void 0)return n!==void 0&&n(!1),!1;a=a.value();const o=WAPI.getChat(a.chat.id);return o!==void 0?n!==void 0?(o.sendMessage(t,null,a).then(function(){function i(w){return new Promise(p=>setTimeout(p,w))}var u=0;function c(){for(let w=o.msgs.models.length-1;w>=0;w--){let p=o.msgs.models[w];if(!(!p.senderObj.isMe||p.body!=t))return n(WAPI._serializeMessageObj(p)),True}if(u+=1,u>30){n(!0);return}i(500).then(c)}c()}),!0):(o.sendMessage(t,null,a),!0):(n!==void 0&&n(!1),!1)},window.WAPI.sendMessageToID=function(e,t,n){try{window.getContact=o=>Store.WapQuery.queryExist(o),window.getContact(e).then(o=>{o.status===404?n(!0):Store.Chat.find(o.jid).then(i=>(i.sendMessage(t),!0)).catch(i=>WAPI.sendMessage(e,t)?(n(!0),!0):(n(!1),!1))})}catch{if(window.Store.Chat.length===0)return!1;firstChat=Store.Chat._models[0];var a=firstChat.id;return firstChat.id=typeof a=="string"?e:new window.Store.UserConstructor(e,{intentionallyUsePrivateConstructor:!0}),n!==void 0?(firstChat.sendMessage(t).then(function(){firstChat.id=a,n(!0)}),!0):(firstChat.sendMessage(t),firstChat.id=a,!0)}return n!==void 0&&n(!1),!1},window.WAPI.sendMessage=function(e,t,n){var a=WAPI.getChat(e);return a!==void 0?n!==void 0?(a.sendMessage(t).then(function(){function o(c){return new Promise(w=>setTimeout(w,c))}var i=0;function u(){for(let c=a.msgs.models.length-1;c>=0;c--){let w=a.msgs.models[c];if(!(!w.senderObj.isMe||w.body!=t))return n(WAPI._serializeMessageObj(w)),True}if(i+=1,i>30){n(!0);return}o(500).then(u)}u()}),!0):(a.sendMessage(t),!0):(n!==void 0&&n(!1),!1)},window.WAPI.sendMessage2=function(e,t,n){var a=WAPI.getChat(e);if(a!==void 0)try{return n!==void 0?a.sendMessage(t).then(function(){n(!0)}):a.sendMessage(t),!0}catch{return n!==void 0&&n(!1),!1}return n!==void 0&&n(!1),!1},window.WAPI.sendSeen=function(e,t){var n=window.WAPI.getChat(e);return n!==void 0?t!==void 0?(n.getLastMsgKeyForAction===void 0&&(n.getLastMsgKeyForAction=function(){}),Store.SendSeen(n,!1).then(function(){t(!0)}),!0):(Store.SendSeen(n,!1),!0):(t!==void 0&&t(),!1)},window.WAPI.getUnreadMessages=function(e,t,n,a){const o=window.Store.Chat.models;let i=[];for(let u in o){if(isNaN(u))continue;let c=o[u],w=WAPI._serializeChatObj(c);w.messages=[];const p=c.msgs._models;for(let C=p.length-1;C>=0;C--){let A=p[C];if(!(typeof A.isNewMsg!="boolean"||A.isNewMsg===!1)){A.isNewMsg=!1;let m=WAPI.processMessageObj(A,e,t);m&&w.messages.push(m)}}if(w.messages.length>0)i.push(w);else if(n){let C=c.unreadCount;for(let A=p.length-1;A>=0;A--){let m=p[A];if(C>0){if(!m.isSentByMe){let S=WAPI.processMessageObj(m,e,t);w.messages.unshift(S),C-=1}}else if(C===-1){if(!m.isSentByMe){let S=WAPI.processMessageObj(m,e,t);w.messages.unshift(S);break}}else break}w.messages.length>0&&(c.unreadCount=0,i.push(w))}}return a!==void 0&&a(i),i},window.WAPI.getGroupOwnerID=async function(e,t){const n=(await WAPI.getGroupMetadata(e)).owner.id;return t!==void 0&&t(n),n},window.WAPI.getCommonGroups=async function(e,t){let n=[];groups=window.WAPI.getAllGroups();for(let a in groups)participants=await window.WAPI.getGroupParticipantIDs(groups[a].id),participants.filter(o=>o==e).length&&n.push(groups[a]);return t!==void 0&&t(n),n},window.WAPI.getProfilePicSmallFromId=function(e,t){window.Store.ProfilePicThumb.find(e).then(function(n){n.img!==void 0?window.WAPI.downloadFileWithCredentials(n.img,t):t(!1)},function(n){t(!1)})},window.WAPI.getProfilePicFromId=function(e){let t=Store.ProfilePicThumb._models.find(n=>n.id._serialized==e);return t?t.img:null},window.WAPI.downloadFileWithCredentials=function(e,t){let n=new XMLHttpRequest;n.onload=function(){if(n.readyState==4)if(n.status==200){let a=new FileReader;a.readAsDataURL(n.response),a.onload=function(o){t(a.result.substr(a.result.indexOf(",")+1))}}else console.error(n.statusText);else t(!1)},n.open("GET",e,!0),n.withCredentials=!0,n.responseType="blob",n.send(null)},window.WAPI.downloadFile=function(e,t){let n=new XMLHttpRequest;n.onload=function(){if(n.readyState==4){if(n.status==200){let a=new FileReader;a.readAsDataURL(n.response),a.onload=function(o){t(a.result.substr(a.result.indexOf(",")+1))}}}else t(!1)},n.open("GET",e,!0),n.responseType="blob",n.send(null)},window.WAPI.getBatteryLevel=function(e){return window.Store.Conn.plugged?(e!==void 0&&e(100),100):(output=window.Store.Conn.battery,e!==void 0&&e(output),output)},window.WAPI.deleteConversation=function(e,t){let n=new window.Store.UserConstructor(e,{intentionallyUsePrivateConstructor:!0}),a=WAPI.getChat(n);return a?(window.Store.sendDelete(a,!1).then(()=>{t!==void 0&&t(!0)}).catch(()=>{t!==void 0&&t(!1)}),!0):(t!==void 0&&t(!1),!1)},window.WAPI.deleteMessage=function(e,t,n=!1,a){let o=new window.Store.UserConstructor(e,{intentionallyUsePrivateConstructor:!0}),i=WAPI.getChat(o);if(!i)return a!==void 0&&a(!1),!1;Array.isArray(t)||(t=[t]);let u=t.map(c=>window.Store.Msg.get(c));return n?i.sendRevokeMsgs(u,i):i.sendDeleteMsgs(u,i),a!==void 0&&a(!0),!0},window.WAPI.checkNumberStatus=function(e,t){return window.Store.WapQuery.queryExist(e).then(n=>{if(t!==void 0){if(n.jid===void 0)throw 404;t(window.WAPI._serializeNumberStatusObj(n))}}).catch(n=>{t!==void 0&&t(window.WAPI._serializeNumberStatusObj({status:n,jid:e}))}),!0},window.WAPI._newMessagesQueue=[],window.WAPI._newMessagesBuffer=sessionStorage.getItem("saved_msgs")!=null?JSON.parse(sessionStorage.getItem("saved_msgs")):[],window.WAPI._newMessagesDebouncer=null,window.WAPI._newMessagesCallbacks=[],window.Store.Msg.off("add"),sessionStorage.removeItem("saved_msgs"),window.WAPI._newMessagesListener=window.Store.Msg.on("add",e=>{if(e&&e.isNewMsg&&!e.isSentByMe){let t=window.WAPI.processMessageObj(e,!1,!1);t&&(window.WAPI._newMessagesQueue.push(t),window.WAPI._newMessagesBuffer.push(t)),!window.WAPI._newMessagesDebouncer&&window.WAPI._newMessagesQueue.length>0&&(window.WAPI._newMessagesDebouncer=setTimeout(()=>{let n=window.WAPI._newMessagesQueue;window.WAPI._newMessagesDebouncer=null,window.WAPI._newMessagesQueue=[];let a=[];window.WAPI._newMessagesCallbacks.forEach(function(o){o.callback!==void 0&&o.callback(n),o.rmAfterUse===!0&&a.push(o)}),a.forEach(function(o){let i=window.WAPI._newMessagesCallbacks.indexOf(o);window.WAPI._newMessagesCallbacks.splice(i,1)})},1e3))}}),window.WAPI._unloadInform=e=>{window.WAPI._newMessagesBuffer.forEach(t=>{Object.keys(t).forEach(n=>t[n]===void 0?delete t[n]:"")}),sessionStorage.setItem("saved_msgs",JSON.stringify(window.WAPI._newMessagesBuffer)),window.WAPI._newMessagesCallbacks.forEach(function(t){t.callback!==void 0&&t.callback({status:-1,message:"page will be reloaded, wait and register callback again."})})},window.addEventListener("unload",window.WAPI._unloadInform,!1),window.addEventListener("beforeunload",window.WAPI._unloadInform,!1),window.addEventListener("pageunload",window.WAPI._unloadInform,!1),window.WAPI.waitNewMessages=function(e=!0,t){return window.WAPI._newMessagesCallbacks.push({callback:t,rmAfterUse:e}),!0},window.WAPI.getBufferedNewMessages=function(e){let t=window.WAPI._newMessagesBuffer;return window.WAPI._newMessagesBuffer=[],e!==void 0&&e(t),t},window.WAPI.sendImage=function(e,t,n,a,o){var i=new window.Store.UserConstructor(t,{intentionallyUsePrivateConstructor:!0});return Store.Chat.find(i).then(u=>{var c=window.WAPI.base64ImageToFile(e,n),w=new Store.MediaCollection(u);w.processAttachments([{file:c},1],u,1).then(()=>{var p=w.models[0];p.sendToChat(u,{caption:a}),o!==void 0&&o(!0)})})},window.WAPI.sendAttachment=function(e,t,n,a){var o=new window.Store.UserConstructor(t,{intentionallyUsePrivateConstructor:!0});return Store.Chat.find(o).then(i=>{var u=new Store.MediaCollection(i);u.processAttachments([{file:e},1],1,i).then(()=>{var c=u._models[0];c.sendToChat(i,{caption:n}),a!==void 0&&a(!0)})})},window.WAPI.base64ImageToFile=function(e,t){for(var n=e.split(","),a=n[0].match(/:(.*?);/)[1],o=atob(n[1]),i=o.length,u=new Uint8Array(i);i--;)u[i]=o.charCodeAt(i);return new File([u],t,{type:a})},window.WAPI.sendContact=function(e,t){Array.isArray(t)||(t=[t]),t=t.map(n=>WAPI.getChat(n).__x_contact),t.length>1?window.WAPI.getChat(e).sendContactList(t):t.length===1&&window.WAPI.getChat(e).sendContact(t[0])},window.WAPI.getNewMessageId=function(e){var t=Store.Msg.models[0].__x_id.clone();return t.fromMe=!0,t.id=WAPI.getNewId().toUpperCase(),t.remote=e,t._serialized=`${t.fromMe}_${t.remote}_${t.id}`,t},window.WAPI.sendVCard=function(e,t){var n=Store.Chat.get(e),a=Object.create(Store.Msg.models.filter(u=>u.__x_isSentByMe)[0]),o=window.WAPI.getNewMessageId(e),i={ack:0,id:o,local:!0,self:"out",t:parseInt(new Date().getTime()/1e3),to:e,isNewMsg:!0};Array.isArray(t)?(Object.assign(i,{type:"multi_vcard",vcardList:t}),delete i.body):(Object.assign(i,{type:"vcard",subtype:t.displayName,body:t.vcard}),delete i.vcardList),Object.assign(a,i),n.addAndSendMsg(a)},window.WAPI.contactBlock=function(e,t){const n=window.Store.Contact.get(e);return n!==void 0?(n.setBlock(!0),t(!0),!0):(t(!1),!1)},window.WAPI.contactUnblock=function(e,t){const n=window.Store.Contact.get(e);return n!==void 0?(n.setBlock(!1),t(!0),!0):(t(!1),!1)},window.WAPI.removeParticipantGroup=function(e,t,n){window.Store.WapQuery.removeParticipants(e,[t]).then(()=>{const a=window.Store.GroupMetadata.get(id);if(checkParticipant=a.participants._index[t],checkParticipant===void 0)return n(!0),!0})},window.WAPI.promoteParticipantAdminGroup=function(e,t,n){window.Store.WapQuery.promoteParticipants(e,[t]).then(()=>{const a=window.Store.GroupMetadata.get(id);return checkParticipant=a.participants._index[t],checkParticipant!==void 0&&checkParticipant.isAdmin?(n(!0),!0):(n(!1),!1)})},window.WAPI.demoteParticipantAdminGroup=function(e,t,n){window.Store.WapQuery.demoteParticipants(e,[t]).then(()=>{const a=window.Store.GroupMetadata.get(id);return a===void 0||(checkParticipant=a.participants._index[t],checkParticipant!==void 0&&checkParticipant.isAdmin)?(n(!1),!1):(n(!0),!0)})},window.WAPI.isChatOpened=function(e){try{return window.WAPI.getChatById(e),Boolean(window.Store.SendTextMsgToChat)}catch{return!1}},window.WAPI.showAllChats=function(){window.Store.Chat._models.forEach(function(e){Object.defineProperty(e,"__x_shouldAppearInList",{get:function(){return!0},set:function(t){}})}),window.Store.Chat._models[0].t=window.Store.Chat._models[0].t+1},window.WAPI.showAllUnreadChats=function(){window.Store.Chat._models.forEach(function(e){e.__x_hasUnread===!1?Object.defineProperty(e,"__x_shouldAppearInList",{get:function(){return!1},set:function(t){}}):Object.defineProperty(e,"__x_shouldAppearInList",{get:function(){return!0},set:function(t){}})}),window.Store.Chat._models[0].t=window.Store.Chat._models[0].t+1},window.WAPI.showAllGroupChats=function(){window.Store.Chat._models.forEach(function(e){e.__x_isGroup===!1?Object.defineProperty(e,"__x_shouldAppearInList",{get:function(){return!1},set:function(t){}}):Object.defineProperty(e,"__x_shouldAppearInList",{get:function(){return!0},set:function(t){}})}),window.Store.Chat._models[0].t=window.Store.Chat._models[0].t+1},window.WAPI.showAllAwaitReplyChats=function(){window.Store.Chat._models.forEach(function(e){Object.defineProperty(e,"__x_shouldAppearInList",{get:function(){return e.__x_lastReceivedKey?e.__x_lastReceivedKey.fromMe:!1},set:function(t){}})}),window.Store.Chat._models[0].t=window.Store.Chat._models[0].t+1},window.WAPI.showAllNeedReplyChats=function(){window.Store.Chat._models.forEach(function(e){Object.defineProperty(e,"__x_shouldAppearInList",{get:function(){return!(e.__x_lastReceivedKey&&e.__x_lastReceivedKey.fromMe)},set:function(t){}})}),window.Store.Chat._models[0].t=window.Store.Chat._models[0].t+1},window.WAPI.showFilterLabelChats=function(e){window.Store.Chat._models.forEach(function(t){t.labels.includes(e)?Object.defineProperty(t,"__x_shouldAppearInList",{get:function(){return!0},set:function(n){}}):Object.defineProperty(t,"__x_shouldAppearInList",{get:function(){return!1},set:function(n){}})}),window.Store.Chat._models[0].t=window.Store.Chat._models[0].t+1},window.WAPI.openChat=function(e){Store.Cmd.openChatBottom(Store.Chat._models.find(t=>t.id._serialized==e))},window.WAPI.getTheme=Store.themeFn.getTheme,window.WAPI.setTheme=Store.themeFn.setTheme,window.WAPI.findChat=Store.findChat,window.WAPI.createWid=Store.createWid,window.WAPI.hasChat=e=>Store.Chat.some(t=>t&&t.id.user==e),window.WAPI.colorIndexToHex=Store.colorIndexToHex,window.WAPI.deleteChat=function(e){Store.DeleteChat(Date.now(),e,!0)},window.WAPI.archiveChat=function(e){let t=window.Store.Chat.get(e);Store.Cmd.archiveChat(t,!0)},window.WAPI.unarchiveChat=function(e){let t=window.Store.Chat.get(e);Store.Cmd.archiveChat(t,!1)}}).then(()=>{G(),window.postMessage({origin:"wa-plus-res",type:"getConfig"},"*"),clearInterval(W)}).catch(e=>{})},300)})();function G(){let I=[],W="",e={};const t=Store.ChatStates.sendChatStateComposing;async function n(){let r=(await window.WAPI.getAllGroups()).map(s=>({id:s.id.user,groupName:s.name||s.contact.name,canSend:s.canSend,labels:s.labels||[],users:s.participants.map(l=>({name:l.name||l.pushname||l.verifiedName||"",phone:l.id.user,isAdmin:s.groupMetadata.participants.find(g=>g.id.user==l.id.user).isAdmin,isBusiness:l.isBusiness,isMyContact:Boolean(l.isAddressBookContact)}))}));window.postMessage({origin:"wa-plus-res",type:"groupInfo",detail:r},"*")}function a(d){let r=[...new Set(Store.Msg._models.filter(s=>s.from&&s.from.user==d&&s.to&&s.to.server=="c.us"&&s.ack==1).map(s=>s.to.user))];window.postMessage({origin:"wa-plus-res",type:"chatStatus",detail:r},"*")}function o(){let d=Store.Contact._models.filter(r=>r.id.server=="c.us").map(r=>r.id.user);window.postMessage({origin:"wa-plus-res",type:"allContact",detail:d},"*")}async function i(){let r=(await window.WAPI.getAllChats()).filter(s=>{var l;return!s.isGroup&&s.archive&&((l=s.id)==null?void 0:l.user)>1}).map(s=>{var g,f,h,P;let l;return s.preMes&&(l={from:(f=(g=s.preMes)==null?void 0:g.from)==null?void 0:f.user,type:(h=s.preMes)==null?void 0:h.type,ack:(P=s.preMes)==null?void 0:P.ack}),{id:s.id._serialized,name:s.contact.name||s.contact.pushname||s.contact.verifiedName||s.formattedTitle,phone:s.id.user,labels:s.labels||[],isBusiness:s.contact.isBusiness,isMyContact:Boolean(s.contact.isAddressBookContact),preMes:l}});window.postMessage({origin:"wa-plus-res",type:"archiveInfo",detail:r},"*")}async function u(){let r=(await window.WAPI.getMyContacts()).map(s=>({id:s.id._serialized,name:s.name,nikename:s.pushname||s.verifiedName,labels:s.labels||[],phone:s.id.user,isBusiness:s.isBusiness}));window.postMessage({origin:"wa-plus-res",type:"contactInfo",detail:r},"*")}function c(){let r=window.WAPI.getAllChats().filter(s=>{var l;return!s.isGroup&&!s.archive&&((l=s.id)==null?void 0:l.user)>1}).map(s=>{var g,f,h,P;let l;return s.preMes&&(l={from:(f=(g=s.preMes)==null?void 0:g.from)==null?void 0:f.user,type:(h=s.preMes)==null?void 0:h.type,ack:(P=s.preMes)==null?void 0:P.ack}),{id:s.id._serialized,name:s.contact.name||s.contact.pushname||s.contact.verifiedName||s.formattedTitle,phone:s.id.user,labels:s.labels||[],isBusiness:s.contact.isBusiness||!1,isMyContact:s.contact.isAddressBookContact||!1,preMes:l}});window.postMessage({origin:"wa-plus-res",type:"chatInfo",detail:r},"*")}async function w(){let d=WAPI.getMe(),r=WAPI.getAllLabels(),s=WAPI.getTheme();d&&(W=d.id.user,window.postMessage({origin:"wa-plus-res",type:"userInfo",detail:{phone:W,avatar:d.profilePicThumb.img,isBusiness:d.isBusiness,labels:r,theme:s}},"*"))}function p(d){if(Store.Presence.removeAllListeners(),!d.open)return;let r=[],s=[],l=Store.Chat._models.filter(f=>!f.isGroup&&!f.archive&&f.id);d.subscribe.includes(1)&&(d.onlineSet.type=="all"?r=l.map(f=>f.id.user):d.onlineSet.type=="label"?r=l.filter(f=>f.labels&&f.labels.some(h=>d.onlineSet.labels.includes(h))).map(f=>f.id.user):d.onlineSet.type=="user"&&(r=d.onlineSet.users)),d.subscribe.includes(0)&&(d.offlineSet.type=="all"?s=l.map(f=>f.id.user):d.offlineSet.type=="label"?s=l.filter(f=>f.labels&&f.labels.some(h=>d.offlineSet.labels.includes(h))).map(f=>f.id.user):d.onlineSet.type=="user"&&(s=d.offlineSet.users));let g=r.concat(s);Store.Presence.on("change:isOnline",async(f,h)=>{if(f.isUser&&f.id&&g.includes(f.id.user)){let P=WAPI.getChatById(f.id._serialized),E=P.contact.name||P.contact.pushname||P.contact.verifiedName,b=f.id.user,y=WAPI.getProfilePicFromId(f.id._serialized);y||(y=(await WAPI.GetUserInfo(b)).avatar),e.subscribe.includes(Number(h))&&window.postMessage({origin:"wa-plus-res",type:"userStatus",params:{phone:b,name:E,status:h,avatar:y}},"*")}}),l.forEach(f=>{f.__x_isUser&&Store.Chat.get(f.id).presence.subscribe()})}function C(d,r){let s=Store.Msg._models.filter(g=>g.from.user==W&&d.includes(g.to.user)&&g.t>r-5).reverse(),l=d.map(g=>{let f=s.find(P=>P.to.user==g),h=Store.Contact.get(g+"@c.us");return f?{phone:f.to.user,ack:f.ack,name:h.name||h.pushname||h.verifiedName,labels:h.labels}:{phone:g,ack:0,name:h.name||h.pushname||h.verifiedName,labels:h.labels}});window.postMessage({origin:"wa-plus-res",type:"getSendDetail",detail:l},"*")}function A(d,r,s){window.postMessage({origin:"wa-plus-res",type:"phoneStatus",detail:{phone:d,status:r,failReason:s}},"*")}function m(d){let r=d.phone+"@c.us";WAPI.isChatOpened(r)&&d.msg&&WAPI.sendMessage(r,d.msg)}async function S(d,r,s){if(!WAPI.isConnected())return A(d.phone,!1,"\u7F51\u7EDC\u4E2D\u65AD"),window.postMessage({origin:"wa-plus-res",type:"stopSend"},"*");let l=d.phone+(r=="user"?"@c.us":"@g.us");if(WAPI.isChatOpened(l))s?(I.length&&await M(l),await _(500),d.msg&&WAPI.sendMessage(l,d.msg),A(d.phone,!0)):(d.msg&&WAPI.sendMessage(l,d.msg),I.length&&await M(l),A(d.phone,!0));else{if(r=="group")return A(d.phone,!1,"\u8D26\u53F7\u4E0D\u5B58\u5728");let f=document.getElementById("wamessages");f.href=`https://api.whatsapp.com/send?phone=${d.phone}&text=${encodeURI(d.msg||"")}`,f.click(),await _(2e3);let h=document.querySelector("#main footer button[data-tab='11']"),P=document.querySelector("button.emrlamx0.aiput80m,button.x889kno.x1a8lsjc");P?(P.click(),A(d.phone,!1,"\u8D26\u53F7\u4E0D\u5B58\u5728")):s?(I.length&&await M(l),h&&h.click(),A(d.phone,!0)):(h&&h.click(),I.length&&await M(l),A(d.phone,!0))}}async function M(d){let r=!0;for(let s=0;s<I.length;s++)await WAPI.sendAttachment(I[s],d,"")||(r=!1),await _(400);return r}function _(d){return new Promise(r=>setTimeout(r,d))}function v(d){let r={};return d.forEach(s=>{let l=2;if(Store.Msg._models.find(g=>g.from&&g.from.user==s&&g.body))l=7;else{let g=Store.Msg._models.filter(f=>f.to&&f.to.user==s).sort((f,h)=>f.ack-h.ack);g.length&&(l=g.pop().ack+3)}r[s]=l}),r}function O(d){Object.keys(d).forEach(r=>{let s=Store.Chat._models.find(l=>l.id&&l.id.user&&l.id.user==r);s&&(d[r].pin&&(s.pin=d[r].pin),d[r].name&&s.contact&&(s.contact.name=d[r].name))})}async function k(d){let r=d.filter(h=>!WAPI.hasChat(h)),s=d.filter(h=>WAPI.hasChat(h)),l=r.length,g=[];window.postMessage({origin:"wa-plus-res",type:"checkStart",existPhones:s,filterNum:l,restNum:l,validNum:0},"*");let f=setInterval(async()=>{if(!r.length)return window.postMessage({origin:"wa-plus-res",type:"checkEnd",existPhones:s,validPhones:g},"*"),clearInterval(f);let h=r.shift();await WAPI.CheckPhoneRegister(h)&&g.push(h),window.postMessage({origin:"wa-plus-res",type:"checking",restNum:r.length,validNum:g.length},"*")},500)}function T(d,r){d.forEach(async s=>{if(!WAPI.hasChat(s)){let l=WAPI.createWid(`${s}@c.us`),g=await WAPI.findChat(l);Object.assign(g,r=="ALL"?{__x_shouldAppearInList:!0}:{__x_labels:[r],labels:[r],__x_shouldAppearInList:!0})}}),Store.Chat.trigger("change:shouldAppearInList"),r!=="ALL"?setTimeout(()=>{Store.Label.addOrRemoveLabels([{id:r,type:"add"}],Store.Chat._models.filter(s=>s&&d.includes(s.id.user))),setTimeout(()=>{window.WAPI.showFilterLabelChats(r),window.postMessage({origin:"wa-plus-res",type:"addSuccess"},"*")},700+d.length)},1e3):setTimeout(()=>{window.WAPI.showAllChats(),window.postMessage({origin:"wa-plus-res",type:"addSuccess"},"*")},500+d.length)}function L(d){d.forEach(r=>{let s=r.split("@"),l={server:s[1],user:s[0],_serialized:r};WAPI.deleteChat(l)})}function U(d,r){d.forEach(s=>{window.WAPI[r?"archiveChat":"unarchiveChat"](s)})}window.addEventListener("message",async d=>{let r=d.data,s=r.type;if(r.origin==="wa-plus-req")if(s=="sendToUser")S(r.detail,r.sendType,r.picFirst);else if(s=="sendLinkToUser")m(r.detail);else if(s=="filelist")I=r.filelist;else if(s=="getGroupInfo")n();else if(s=="getArchiveInfo")i();else if(s=="getChatsInfo")c();else if(s=="getChatStatus")a(r.phone);else if(s=="getAllContact")o();else if(s=="getUserStatus"){let l=v(r.phoneList);window.postMessage({origin:"wa-plus-res",type:"currPhoneStatus",detail:l,upload:r.upload},"*")}else if(s=="getMyContactsInfo")u();else if(s=="getUserInfo")w();else if(s=="getSendDetail")C(r.trueList,r.startTime);else if(s=="filterChat"){const l=r.chatType;switch(l){case"ALL":window.WAPI.showAllChats();break;case"UNREAD":window.WAPI.showAllUnreadChats();break;case"AWAIT_REPLY":window.WAPI.showAllAwaitReplyChats();break;case"NEED_REPLY":window.WAPI.showAllNeedReplyChats();break;case"GROUP":window.WAPI.showAllGroupChats();break;default:window.WAPI.showFilterLabelChats(l);break}}else if(s=="toogleSubscribe")e=r.params,p(r.params);else if(s=="checkUser"){let l=Store.Chat.getActive();if(r.showDetail&&setTimeout(()=>{Store.Cmd.chatInfoDrawer(l)},100),l!==void 0){let g=await Store.About.getAbout(l.id);window.postMessage({origin:"wa-plus-res",type:"isUser",value:l.isUser,labels:l.labels,phone:l.id.user,id:l.id._serialized,isUser:l.isUser,sign:g.status,pin:l.pin},"*")}}else if(s=="updateLabels")Store.Label.addOrRemoveLabels([{id:r.id,type:r.mode}],[Store.Chat.getActive()]);else if(s=="batchEditLabels")Store.Label.addOrRemoveLabels(r.opts,Store.Chat._models.filter(l=>l&&r.phones.includes(l.id.user))),setTimeout(()=>{switch(r.showType){case"chat":c();break;case"archive":i();break;case"group":n();break}},300+Math.min(3e3,r.opts.length*r.phones.length));else if(s=="openChat")window.WAPI.openChat(r.phone+"@c.us");else if(s=="setOnline")Store._Presence[r.status?"setPresenceAvailable":"setPresenceUnavailable"]();else if(s=="setTyping")Store.ChatStates.sendChatStateComposing=r.status?t:()=>new Promise;else if(s=="pinToggle"){let l=Store.Chat.get(r.id);l&&(l.pin=r.pin)}else if(s=="updateName"){let l=Store.Chat.get(r.id);l&&l.contact&&(l.contact.name=r.name)}else if(s=="refreshConfig")O(r.config);else if(s=="changeLang")localStorage.WALangPref=`"${r.lang}"`,document.cookie=`wa_web_lang_pref=${r.lang};domain=.web.whatsapp.com`,location.reload();else if(s=="changeTheme")r.theme=="dark"?localStorage.setItem("system-theme-mode","false"):localStorage.removeItem("system-theme-mode"),WAPI.setTheme(r.theme);else if(s=="getLabels"){let l=WAPI.getAllLabels();window.postMessage({origin:"wa-plus-res",type:"getLabels",labels:l},"*")}else s=="checkStatus"?k(r.phonelist):s=="addContact"?T(r.phonelist,r.labelId):s=="delChat"?L(r.ids):s=="toogleArchive"&&(U(r.ids,r.value),setTimeout(()=>{switch(r.showType){case"chat":c();break;case"archive":i();break}},300))}),w()}