1.js
8.07 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
const homejs=`window.rnapp=true;function awaitPostMessage() {
var isReactNativePostMessageReady = !!window.originalPostMessage;
const queue = [];
var currentPostMessageFn = function store(message) {
if (queue.length > 100) queue.shift();
queue.push(message);
};
if (!isReactNativePostMessageReady) {
const originalPostMessage = window.postMessage;
Object.defineProperty(window, 'postMessage', {
configurable: true,
enumerable: true,
get: function() {
return currentPostMessageFn;
},
set: function(fn) {
currentPostMessageFn = fn;
isReactNativePostMessageReady = true;
setTimeout(sendQueue, 0);
}
});
window.postMessage.toString = function () {
return String(originalPostMessage);
};
}
function sendQueue() {
while (queue.length > 0) window.postMessage(queue.shift());
}
}
function getQueryString(url, name) {
var parameterString = null;
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
parameterString = url.substr(url.indexOf("?"), url.length);//获取截取?以后的字符串
var r = parameterString.substr(1).match(reg);
if (r != null){
return unescape(r[2]);
}
return null;
}
(function() {
var originalPostMessage = window.postMessage;
var patchedPostMessage = function(message, targetOrigin, transfer) {
originalPostMessage(message, targetOrigin, transfer);
};
patchedPostMessage.toString = function() {
return String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage');
};
window.postMessage = patchedPostMessage;
})();
(function(){
$(".xn-page-container").on("click","a",function (e) {
awaitPostMessage(); // Call this only once in your Web Code.
var url = e.currentTarget.href;
var data = {};
if (url.indexOf("/mb2c/groupBuy/groupBuy") >=0 ){
e.preventDefault();
//跳转到商品列表页面
data.page = "groupBuyList";
} else if (url.indexOf("/mb2c/searchList") >=0 ){
e.preventDefault();
//跳转到商品列表页面
data.page = "searchList";
//参数
var categoryId = getQueryString(url,"categoryId");
if (categoryId){
data.id = categoryId;
}
} else if(url.indexOf("/mb2c/personal/information/cart") >=0 ){
e.preventDefault();
//购物车页面
data.page = "shoppingCart";
}else if(url.indexOf("mb2c/commodity/categoryList") >=0 ){
}else if(url.indexOf("/mb2c/searchSelect") >=0 ){
e.preventDefault();
data.page="search"
}else if(url.indexOf("/mb2c/groupCommodity") >=0){
e.preventDefault();
//跳转到商品页面-拼团
data.page = "commodityDetail";
//参数
var commodityId = getQueryString(url,"commodityId");
var promotionId = getQueryString(url,"promotionId");
if (commodityId){
data.commodityId = commodityId;
}
if (promotionId){
data.promotionId = promotionId;
}
} else if(url.indexOf("/mb2c/commodity") >=0 ){
//商品详情
data.page = "commodityDetail";
//先获取参数格式URL的商品ID
var commodityId = getQueryString(url,"commodityId");
if (commodityId){
data.commodityId = commodityId;
}else{
//为获取到,则从静态页面中获取
var begin = url.lastIndexOf("\/");
var end = url.lastIndexOf(".");
if(url.substring(begin +1,end )!=="categoryList"){
e.preventDefault();
data.id = url.substring(begin +1,end );
}
}
}
if(!!data.page){
window.postMessage(JSON.stringify(data));
}
})
})();
(function(){
$("form").submit(function(e){
e.preventDefault();
data={}
data.page = "searchList";
data.keyword=$("input[name='keyword']").val()
awaitPostMessage();
window.postMessage(JSON.stringify(data));
data.keyword=$("input[name='keyword']").val("").blur()
})
})()
`
const pointjs=`window.rnapp=true;
function awaitPostMessage() {
var isReactNativePostMessageReady = !!window.originalPostMessage;
const queue = [];
var currentPostMessageFn = function store(message) {
if (queue.length > 100) queue.shift();
queue.push(message);
};
if (!isReactNativePostMessageReady) {
// const originalPostMessage = window.postMessage;
Object.defineProperty(window, 'postMessage', {
configurable: true,
enumerable: true,
get: function() {
return currentPostMessageFn;
},
set: function(fn) {
currentPostMessageFn = fn;
isReactNativePostMessageReady = true;
setTimeout(sendQueue, 0);
}
});
}
function sendQueue() {
while (queue.length > 0) window.postMessage(queue.shift());
}
}
(function() {
var originalPostMessage = window.postMessage;
var patchedPostMessage = function(message, targetOrigin, transfer) {
originalPostMessage(message, targetOrigin, transfer);
};
patchedPostMessage.toString = function() {
return String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage');
};
window.postMessage = patchedPostMessage;
})();
function getQueryString(url, name) {
var parameterString = null;
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
parameterString = url.substr(url.indexOf("?"), url.length);//获取截取?以后的字符串
var r = parameterString.substr(1).match(reg);
if (r != null){
return unescape(r[2]);
}
return null;
}
(function(){
$("a").click(function (e) {
e.preventDefault();
awaitPostMessage(); // Call this only once in your Web Code.
var url = e.currentTarget.href;
var data = {};
if (url.indexOf("/mpoint/sortlist") >=0 ){
//跳转到商品列表页面
data.page = "pointSearchList";
//参数
var categoryId = getQueryString(url,"categoryId");
if (categoryId){
data.id = categoryId;
}
} else if(url.indexOf("/mb2c/personal/information/cart") >=0 ){
//购物车页面
data.page = "shoppingCart";
} else if(url.indexOf("/mpoint/commodity") >=0 ){
//商品详情
data.page = "pointCommodityDetail";
//先获取参数格式URL的商品ID
var commodityId = getQueryString(url,"commodityId");
if (commodityId){
data.commodityId = commodityId;
}else{
//为获取到,则从静态页面中获取
var begin = url.lastIndexOf("\/");
var end = url.lastIndexOf(".");
data.id = url.substring(begin +1,end);
}
}
if(!!data.page){
window.postMessage(JSON.stringify(data));
}
})
})();
`