-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwechat_injection.js
108 lines (98 loc) · 3.12 KB
/
wechat_injection.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
console.log("### wechat index js hijacked ###");
(function injectCodeToAngularApp() {
var angular = window.angular;
var originalBootstrap = angular.bootstrap;
angular.bootstrap = function(element, moduleNames) {
var ModuleName = "webwxApp";
angular.module(ModuleName).run([
"$rootScope",
function($rootScope) {
$rootScope.$on("root:pageInit:success", function() {
$rootScope.$on("message:add:success", function(e, oMessage) {
conversationLogger(oMessage);
});
var injector = angular.element(document).injector();
var chatFactory = injector.get("chatFactory");
var originalMessageProcess = chatFactory.messageProcess;
chatFactory.messageProcess = function(oMessage) {
originalMessageProcess.call(chatFactory, oMessage);
pingPongRobot(oMessage);
};
});
}
]);
return originalBootstrap.apply(angular, arguments);
};
function conversationLogger(oMessage) {
console.log(
"### new conversation message: ",
JSON.stringify(oMessage, null, 3)
);
}
function pingPongRobot(receivedMessage) {
console.log(
"### message reveived, processing it ",
JSON.stringify(receivedMessage, null, 3)
);
var content = receivedMessage.Content.trim().toLowerCase();
var toUser = window._contacts[receivedMessage.FromUserName];
if (toUser.isRoomContact()) {
content = content.split(":<br/>")[1];
}
var myName = $(".header .avatar").scope().account.UserName;
var toSelf = receivedMessage.FromUserName === myName;
var reply = toSelf ? replyToSelf : replyTo;
switch (content) {
case "ping":
reply("pong", toUser);
break;
case "pingping":
reply("pongpong", toUser);
break;
case "pingpingping":
reply("pongpongpong", toUser);
break;
default:
break;
}
}
function replyTo(message, toUser) {
requestAnimationFrame(function() {
$(".chat_list .chat_item").each(function() {
if ($(this).scope().chatContact.UserName === toUser.UserName) {
$(this).click();
$("#editArea")
.html(message)
.trigger("input");
$(".action .btn.btn_send").click();
}
});
});
}
function replyToSelf(message) {
console.log("replyToSelf", message);
requestAnimationFrame(function() {
$(".header .avatar img").click();
$(".profile_mini .web_wechat_tab_launch-chat").click();
$("#editArea")
.html(message)
.trigger("input");
$(".action .btn.btn_send").click();
});
}
(function loadOriginalScript() {
var originalScript = window.wechatOriginalScript;
$.ajax({
url: originalScript,
dataType: "text",
success: function(script, textStatus, jqxhr) {
if (jqxhr.status === 200) {
//phantomjs does not support ECMA6 language features
script = script.replace(" let ", " var ");
window.eval(script);
console.log("original script " + originalScript + " loaded.");
}
}
});
})();
})();