forked from TransparentLC/WechatMomentScreenshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
516 lines (476 loc) · 27.9 KB
/
main.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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
function loadScript(url) {
var el = document.createElement('script');
el.src = url;
document.body.appendChild(el);
}
function xhrGet(url, callback) {
var xhr = new XMLHttpRequest;
xhr.open('GET', url);
xhr.onload = function () { callback(xhr.responseText) };
xhr.send();
}
mdui.confirm(''
+ '<div class="mdui-typo">'
+ '<p>'
+ '使用本工具<strong>不需要强制关注任何公众号或转发任何内容到朋友圈</strong>。如果你发现有公众号存在类似<strong>“关注○○,发送○○,转发○○到朋友圈领取○○”</strong>的行为,请对此类<strong>诱导行为</strong>进行<strong>投诉</strong>。'
+ '<a href="https://mp.weixin.qq.com/cgi-bin/readtemplate?t=business/faq_operation_tmpl#3dot3_3" target="_blank">什么是诱导行为?</a>'
+ '</p>'
+ '<p>请勿以<strong>“关注○○,发送○○获取工具地址”</strong>或类似方式使用本工具为自己的公众号引流。如果想要推荐的话,请<strong>直接在正文里留下地址或二维码</strong>~</p>'
+ '<p>本工具生成的截图,仅可用于<strong>个人应付各类强制要求转发朋友圈的情形</strong>,请勿<strong>批量生成截图</strong>或将截图用于<strong>造谣诽谤、微商宣传</strong>等非法或令人反感的用途,请勿用于商业用途,<strong>二次部署请勿删除原作者相关信息</strong>。</p>'
+ '<p>当你生成截图时,你应该确定你可以接受向他人发送该截图将会带来的后果和影响,否则请不要使用本工具并离开当前页面。</p>'
+ '<p>本工具谢绝肖战粉丝使用。<a href="https://w.url.cn/s/AC2atup" target="_blank">#我是普通人,我讨厌肖战#</a></p>'
+ '</div>',
'在开始使用之前……',
function () {},
function () { location.href = 'about:blank' },
{
modal: true,
closeOnEsc: false,
history: false,
}
);
var inBlacklist = [
'www.41661.com',
'41661.com',
].indexOf(location.hostname) !== -1;
if (inBlacklist) {
mdui.alert(
'你所访问的网站(' + location.hostname + ')由于在转载本工具时抹去了原作者相关信息,已被原作者列入黑名单。点击下方按钮将跳转到原作者自己部署的页面。',
function () {
location.href = 'https://akarin.dev/WechatMomentScreenshot/';
document.querySelector('.mdui-container').innerHTML = '';
},
{
modal: true,
closeOnEsc: false,
history: false,
}
);
}
if (navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1) loadScript('https://cdn.jsdelivr.net/gh/TransparentLC/WechatMomentScreenshot/fuckWechat.min.js');
if (!window.Promise) loadScript('https://cdn.jsdelivr.net/npm/promise-polyfill/dist/polyfill.min.js');
var avatarURL = [];
xhrGet('https://cdn.jsdelivr.net/gh/TransparentLC/WechatMomentScreenshot/avatarURL.json', function (result) { avatarURL = JSON.parse(result) });
var emoticon = [];
xhrGet('https://cdn.jsdelivr.net/gh/TransparentLC/WechatMomentScreenshot/emoticon.json', function (result) { emoticon = JSON.parse(result) });
// 读取配置
var configDefault = {
name: 'A 营销号免费广告姬',
text: '很实用的教程[微笑]\n需要收集五个赞 谢谢大家啦~( ^ω^)',
location: '',
app: '',
height: 1920,
uiWhite: false,
appIcon: false,
statusIcon: true,
};
var config;
var avatarFile;
try {
config = JSON.parse(localStorage.getItem('config')) || {};
} catch (error) {
config = {};
}
for (var k in configDefault) {
if (config[k] === undefined) config[k] = configDefault[k];
}
document.getElementById('configName').value = config.name;
document.getElementById('configText').value = config.text;
document.getElementById('configLocation').value = config.location;
document.getElementById('configApp').value = config.app;
document.getElementById('configHeight').value = config.height;
document.getElementById('configUIWhite').checked = config.uiWhite;
document.getElementById('configTopBarAppIcons').checked = config.appIcon;
document.getElementById('configTopBarStatusIcons').checked = config.statusIcon;
document.getElementById('avatar').style.backgroundImage = 'url(' + (localStorage.getItem('avatar') || 'https://ae01.alicdn.com/kf/HTB1yE4fMmzqK1RjSZFp761kSXXal.png') + ')';
//输入微信文章的链接,通过后端自动获取文章标题和文章封面
function getArticleInfo() {
var requestDialog = new mdui.Dialog('#request');
mdui.prompt('公众号文章链接', function (value) {
var xhr = new XMLHttpRequest;
xhr.open('GET', 'https://wmsproxy.transparentlc.workers.dev/?url=' + encodeURIComponent(value)); //获取标题和封面的服务器
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var result = JSON.parse(xhr.responseText);
document.getElementById('requestAction').innerText = 'OK';
if (requestDialog.getState() == 'opening' || requestDialog.getState() == 'opened') {
if (typeof(result) != 'undefined' && result.success) {
document.getElementById('configArticleTitle').value = result.title;
document.getElementById('articleTitle').innerText = result.title;
document.getElementById('articleIcon').style.backgroundImage = 'url(\"' + result.cover + '\")';
document.getElementById('requestResult').innerText = '获取成功!(ゝ∀・)';
document.getElementById('requestResultContent').innerHTML = '标题:' + result.title + '<br>封面:<a target="_blank" href="' + result.cover + '">点此查看</a>';
} else {
document.getElementById('requestResult').innerText = '获取失败!( ´_っ`)';
document.getElementById('requestResultContent').innerHTML = '输入的链接是否为微信公众号文章?<br>(链接通常以 <code>https://mp.weixin.qq.com/</code> 作为开头)';
}
}
} else {
document.getElementById('requestResult').innerText = '获取失败!( ´_っ`)';
document.getElementById('requestResultContent').innerHTML = '无法连接到服务器。';
}
requestDialog.handleUpdate();
}
xhr.send();
document.getElementById('requestResult').innerText = '';
document.getElementById('requestAction').innerText = 'CANCEL';
document.getElementById('requestResultContent').innerHTML = '<div class="mdui-valign"><div class="mdui-spinner"></div><span class="mdui-m-l-2">获取中…… (o゚ω゚o)</span></div>';
mdui.updateSpinners();
requestDialog.open();
}, function () {});
}
//删除所有发表的九宫格图片
function clearMultiImage() {
for (var i = 1; i <= 9; i++) {
document.getElementById('image' + i).style.backgroundImage = '';
}
}
//将时间转换为微信中显示的格式
function getTimeString(currentDate, specificDate) {
var cd = new Date(currentDate.getTime() - currentDate.getTimezoneOffset() * 60 * 1000 - (currentDate.getTime() - currentDate.getTimezoneOffset() * 60 * 1000) % (60 * 60 * 24 * 1000));
var sd = new Date(specificDate.getTime() - specificDate.getTimezoneOffset() * 60 * 1000 - (specificDate.getTime() - specificDate.getTimezoneOffset() * 60 * 1000) % (60 * 60 * 24 * 1000));
if (cd.getTime() == sd.getTime()) {
return ((specificDate.getHours() < 10) ? ('0' + specificDate.getHours()) : specificDate.getHours()) + ':' + ((specificDate.getMinutes() < 10) ? ('0' + specificDate.getMinutes()) : specificDate.getMinutes());
} else if (cd.getTime() - sd.getTime() == 60 * 60 * 24 * 1000) {
return '昨天 ' + ((specificDate.getHours() < 10) ? ('0' + specificDate.getHours()) : specificDate.getHours()) + ':' + ((specificDate.getMinutes() < 10) ? ('0' + specificDate.getMinutes()) : specificDate.getMinutes());
} else {
return specificDate.getFullYear() + '年' + (specificDate.getMonth() + 1) + '月' + specificDate.getDate() + '日 ' + ((specificDate.getHours() < 10) ? ('0' + specificDate.getHours()) : specificDate.getHours()) + ':' + ((specificDate.getMinutes() < 10) ? ('0' + specificDate.getMinutes()) : specificDate.getMinutes());
}
}
//复制短链接
function copyGitLink() {
document.getElementById('gitLink').style.display = 'block';
var range = document.createRange();
range.selectNodeContents(document.getElementById('gitLink'));
var selection = document.getSelection();
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('Copy');
selection.removeAllRanges();
mdui.snackbar({
message: '已复制到剪贴板~( っ*\'ω\'*c)'
});
document.getElementById('gitLink').style.display = 'none';
}
var commentList = [];
//添加评论
function addComment(avatar, name, content, date) {
commentList.push({
'avatar': avatar,
'name': name,
'content': content,
'date': date
});
var tr = document.createElement('tr');
tr.innerHTML = '<th>' + commentList.length + '</th><th>' + name + '</th><th>' + content + '</th><th>' + date.toLocaleString() + '</th>';
document.getElementById('configCommentList').append(tr);
}
//删除(最后一条)评论
function removeComment() {
if (commentList.length) {
commentList.pop();
document.getElementById('configCommentList').removeChild(document.getElementById('configCommentList').lastChild);
}
}
//替换表情文字和换行符为对应的HTML标签
function emoticonReplace(text) {
text = text.replace(/\r\n/g, '<br>').replace(/\n/g, '<br>');
for (var i = 0; i < emoticon.length; i++) {
text = text.replace(new RegExp(emoticon[i].name, 'g'), '<img class="emoticon" src="' + emoticon[i].URL + '">');
}
return text;
}
//设置界面显示
document.getElementById('configTypeText').onclick = function () {
document.getElementById('configWebsite').style.display = 'none';
document.getElementById('configSingleImage').style.display = 'none';
document.getElementById('configMultiImage').style.display = 'none';
document.getElementById('article').style.display = 'none';
document.getElementById('singleImage').style.display = 'none';
document.getElementById('multiImage').style.display = 'none';
}
document.getElementById('configTypeWebsite').onclick = function () {
document.getElementById('configWebsite').style.display = 'block';
document.getElementById('configSingleImage').style.display = 'none';
document.getElementById('configMultiImage').style.display = 'none';
document.getElementById('article').style.display = 'flex';
document.getElementById('singleImage').style.display = 'none';
document.getElementById('multiImage').style.display = 'none';
}
document.getElementById('configTypeSingleImage').onclick = function () {
document.getElementById('configWebsite').style.display = 'none';
document.getElementById('configSingleImage').style.display = 'block';
document.getElementById('configMultiImage').style.display = 'none';
document.getElementById('article').style.display = 'none';
document.getElementById('singleImage').style.display = 'block';
document.getElementById('multiImage').style.display = 'none';
}
document.getElementById('configTypeMultiImage').onclick = function () {
document.getElementById('configWebsite').style.display = 'none';
document.getElementById('configSingleImage').style.display = 'none';
document.getElementById('configMultiImage').style.display = 'block';
document.getElementById('article').style.display = 'none';
document.getElementById('singleImage').style.display = 'none';
document.getElementById('multiImage').style.display = 'block';
}
//设初始值
var date = new Date();
document.getElementById('configScreenshotDate').valueAsDate = date;
document.getElementById('configScreenshotTimeHour').value = date.getHours();
document.getElementById('configScreenshotTimeMinute').value = date.getMinutes();
document.getElementById('configPostDate').valueAsDate = date;
document.getElementById('configPostTimeHour').value = date.getHours();
document.getElementById('configPostTimeMinute').value = date.getMinutes();
document.getElementById('configCommentDate').valueAsDate = date;
document.getElementById('configCommentTimeHour').value = date.getHours();
document.getElementById('configCommentTimeMinute').value = date.getMinutes();
document.getElementById('configLike').value = Math.floor(20 * Math.random());
//检验数值是否合法
document.getElementById('configPostTimeHour').addEventListener('input', function () {
if (document.getElementById('configPostTimeHour').value > 23) {
document.getElementById('configPostTimeHour').value = 23;
} else if (document.getElementById('configPostTimeHour').value < 0) {
document.getElementById('configPostTimeHour').value = 0;
}
})
document.getElementById('configPostTimeMinute').addEventListener('input', function () {
if (document.getElementById('configPostTimeMinute').value > 59) {
document.getElementById('configPostTimeMinute').value = 59;
} else if (document.getElementById('configPostTimeMinute').value < 0) {
document.getElementById('configPostTimeMinute').value = 0;
}
})
document.getElementById('configScreenshotTimeHour').addEventListener('input', function () {
if (document.getElementById('configScreenshotTimeHour').value > 23) {
document.getElementById('configScreenshotTimeHour').value = 23;
} else if (document.getElementById('configScreenshotTimeHour').value < 0) {
document.getElementById('configScreenshotTimeHour').value = 0;
}
})
document.getElementById('configScreenshotTimeMinute').addEventListener('input', function () {
if (document.getElementById('configScreenshotTimeMinute').value > 59) {
document.getElementById('configScreenshotTimeMinute').value = 59;
} else if (document.getElementById('configScreenshotTimeMinute').value < 0) {
document.getElementById('configScreenshotTimeMinute').value = 0;
}
})
document.getElementById('configCommentTimeHour').addEventListener('input', function () {
if (document.getElementById('configCommentTimeHour').value > 23) {
document.getElementById('configCommentTimeHour').value = 23;
} else if (document.getElementById('configCommentTimeHour').value < 0) {
document.getElementById('configCommentTimeHour').value = 0;
}
})
document.getElementById('configCommentTimeMinute').addEventListener('input', function () {
if (document.getElementById('configCommentTimeMinute').value > 59) {
document.getElementById('configCommentTimeMinute').value = 59;
} else if (document.getElementById('configCommentTimeMinute').value < 0) {
document.getElementById('configCommentTimeMinute').value = 0;
}
})
document.getElementById('configLike').addEventListener('input', function () {
if (document.getElementById('configLike').value < 0) {
document.getElementById('configLike').value = 0;
}
})
//上传图片
document.getElementById('configAvatar').addEventListener('change', function () {
avatarFile = this.files[0];
document.getElementById('avatar').style.backgroundImage = 'url(\"' + URL.createObjectURL(avatarFile) + '\")';
});
document.getElementById('configArticleIcon').addEventListener('change', function () {
document.getElementById('articleIcon').style.backgroundImage = 'url(\"' + URL.createObjectURL(this.files[0]) + '\")';
});
document.getElementById('configSetSingleImage').addEventListener('change', function () {
document.getElementById('image').src = URL.createObjectURL(this.files[0]);
});
for (var i = 1; i <= 9; i++) {
!function (i) {
document.getElementById('configSetMultiImage' + i).addEventListener('change', function () {
document.getElementById('image' + i).style.backgroundImage = 'url(\"' + URL.createObjectURL(this.files[0]) + '\")';
});
}(i);
}
document.getElementById('generate').addEventListener('click', function () {
// 是否使用7.0以上版本白色界面?
var useWhiteUI = document.getElementById('configUIWhite').checked;
if (useWhiteUI) {
document.getElementById('fakeWechatMoment').classList.add('whiteUI');
document.querySelector('#header > img').src = 'mdicons/black_icons/back.svg';
document.querySelector('.content > img').src = 'mdicons/black_icons/comment.svg';
document.querySelector('#footer > img').src = 'mdicons/black_icons/emoticon.svg';
} else {
document.getElementById('fakeWechatMoment').classList.remove('whiteUI');
document.querySelector('#header > img').src = 'mdicons/white_icons/back.svg';
document.querySelector('.content > img').src = 'mdicons/white_icons/comment.svg';
document.querySelector('#footer > img').src = 'mdicons/white_icons/emoticon.svg';
}
//设置生成的图片上的各种属性
document.getElementById('name').innerText = document.getElementById('configName').value;
document.getElementById('text').innerText = document.getElementById('configText').value;
document.getElementById('articleTitle').innerText = document.getElementById('configArticleTitle').value;
if (document.getElementById('configLocation').value == '') {
document.getElementById('location').style.display = 'none';
} else {
document.getElementById('location').style.display = 'inline';
document.getElementById('location').innerText = document.getElementById('configLocation').value;
}
//表情替换
document.getElementById('text').innerHTML = emoticonReplace(document.getElementById('text').innerText);
//九宫格模式设定
if (document.getElementById('configTypeMultiImage').checked) {
for (var i = 1; i <= 9; i++) {
document.getElementById('image' + i).style.display = 'inline-block';
}
var multiImageCount = 0;
for (multiImageCount = 9; multiImageCount >= 1; multiImageCount--) {
if (document.getElementById('image' + multiImageCount).style.backgroundImage != '') {
break;
}
}
//四张图的修正
if (multiImageCount == 4) {
document.getElementById('image5').style.backgroundImage = document.getElementById('image4').style.backgroundImage;
document.getElementById('image4').style.backgroundImage = document.getElementById('image3').style.backgroundImage;
document.getElementById('image3').style.backgroundImage = '';
multiImageCount = 5;
}
for (var i = multiImageCount + 1; i <= 9; i++) {
document.getElementById('image' + i).style.display = 'none';
}
}
//设置顶栏图标
var iconWifi = [4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 0];
var iconSignal = [4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 0];
var iconBattery = [20, 30, 50, 60, 80, 90, 'full'];
if (document.getElementById('configTopBarStatusIcons').checked) {
document.getElementById('topBarIconWifi').src = 'mdicons/' + (useWhiteUI ? 'black_icons' : 'white_icons') + '/ic_signal_wifi_' + iconWifi[Math.floor(Math.random() * iconWifi.length)] + '_bar_48px.svg';
document.getElementById('topBarIconSignal').src = 'mdicons/' + (useWhiteUI ? 'black_icons' : 'white_icons') + '/ic_signal_cellular_' + iconWifi[Math.floor(Math.random() * iconSignal.length)] + '_bar_48px.svg';
document.getElementById('topBarIconBattery').src = 'mdicons/' + (useWhiteUI ? 'black_icons' : 'white_icons') + '/ic_battery_' + ((Math.random() > 0.75) ? 'charging_' : '') + iconBattery[Math.floor(Math.random() * iconBattery.length)] + '_48px.svg';
} else {
document.getElementById('topBarIconWifi').src = 'mdicons/' + (useWhiteUI ? 'black_icons' : 'white_icons') + '/ic_signal_wifi_4_bar_48px.svg';
document.getElementById('topBarIconSignal').src = 'mdicons/' + (useWhiteUI ? 'black_icons' : 'white_icons') + '/ic_signal_cellular_4_bar_48px.svg';
document.getElementById('topBarIconBattery').src = 'mdicons/' + (useWhiteUI ? 'black_icons' : 'white_icons') + '/ic_battery_full_48px.svg';
}
var iconApp = [['qq', .5], ['wechat', .5], ['cloudmusic', .25], ['coolapk', .15], ['tieba', .15], ['acfun', .15]];
iconApp.sort(function () { return (Math.random() > .5) ? 1 : -1 });
document.getElementById('topBarAppIcons').innerHTML = '';
if (document.getElementById('configTopBarAppIcons').checked) {
for (var i = 0; i < iconApp.length; i++) {
if (Math.random() < iconApp[i][1]) {
document.getElementById('topBarAppIcons').innerHTML += '<img class="topBarIcon" src="mdicons/' + (useWhiteUI ? 'black_icons' : 'white_icons') + '/app_' + iconApp[i][0] +'.svg">';
}
}
}
//设置时间
var configPostDate = document.getElementById('configPostDate').valueAsDate;
configPostDate.setHours(document.getElementById('configPostTimeHour').value);
configPostDate.setMinutes(document.getElementById('configPostTimeMinute').value);
var configScreenshotDate = document.getElementById('configScreenshotDate').valueAsDate;
configScreenshotDate.setHours(document.getElementById('configScreenshotTimeHour').value);
configScreenshotDate.setMinutes(document.getElementById('configScreenshotTimeMinute').value);
document.getElementById('time').innerText = getTimeString(configScreenshotDate, configPostDate);
document.getElementById('topBarTime').innerText = ((document.getElementById('configScreenshotTimeHour').value < 10) ? ('0' + document.getElementById('configScreenshotTimeHour').value) : document.getElementById('configScreenshotTimeHour').value) + ':' + ((document.getElementById('configScreenshotTimeMinute').value < 10) ? ('0' + document.getElementById('configScreenshotTimeMinute').value) : document.getElementById('configScreenshotTimeMinute').value);
if (document.getElementById('configApp') != '') {
document.getElementById('time').innerText += ' ' + document.getElementById('configApp').value;
}
//加入点赞头像
var avatar = document.getElementsByClassName('likeAvatar');
var avatarSource = avatarURL.concat();
var avatarUsedIndex = 0;
document.getElementById('likeAvatarList').innerHTML = '';
for (var i = 0; i < document.getElementById('configLike').value; i++) {
if (avatarSource.length <= 0) {
avatarSource = avatarURL.concat();
}
avatarUsedIndex = Math.floor(Math.random() * avatarSource.length);
var div = document.createElement('div');
div.setAttribute('class', 'likeAvatar squareImage');
div.setAttribute('style', 'background-image:url(\"' + avatarSource[avatarUsedIndex] + '\")');
document.getElementById('likeAvatarList').appendChild(div);
avatarSource.splice(avatarUsedIndex, 1);
}
//加入评论区
document.getElementById('commentList').innerHTML = '';
if (document.getElementById('configShowComment').checked && commentList.length) {
document.getElementById('comment').style.display = 'block';
for (var i = 0; i < commentList.length; i++) {
document.getElementById('commentList').innerHTML += ''
+ '<div class="commentItem">'
+ '<div class="commentAvatar squareImage" style="background-image: url(' + commentList[i].avatar + ');"></div>'
+ '<div class="content">'
+ '<span class="commentName">' + commentList[i].name + '</span>'
+ '<span class="commentTime">' + getTimeString(configScreenshotDate, commentList[i].date) + '</span>'
+ '<div class="commentText">' + emoticonReplace(commentList[i].content) + '</div>'
+ '</div>'
+ '</div>';
}
} else {
document.getElementById('comment').style.display = 'none';
}
//显示用于生成图片的div
var height = Number(document.getElementById('configHeight').value);
document.getElementById('fakeWechatMoment').style.display = 'block';
document.getElementById('fakeWechatMoment').style.width = '1080px';
document.getElementById('fakeWechatMoment').style.height = '';
document.getElementById('fakeWechatMoment').style.height = ((window.getComputedStyle(document.getElementById('fakeWechatMoment')).height.replace('px', '') > height) ? window.getComputedStyle(document.getElementById('fakeWechatMoment')).height.replace('px', '') : height) + 'px';
//点赞数为0时隐藏点赞区
if (document.getElementById('configLike').value <= 0) {
document.getElementById('triangle').style.display = 'none';
document.getElementById('like').style.display = 'none';
} else {
document.getElementById('triangle').style.display = 'block';
document.getElementById('like').style.display = 'block';
}
//修正底部位置
var offset = Number(window.getComputedStyle(document.getElementById('topBar')).height.replace('px', '')) + Number(window.getComputedStyle(document.getElementById('header')).height.replace('px', '')) + Number(window.getComputedStyle(document.getElementById('main')).height.replace('px', ''));
document.getElementById('footer').style.bottom = ((offset < height - Number(window.getComputedStyle(document.getElementById('footer')).height.replace('px', ''))) ? (-height + Number(window.getComputedStyle(document.getElementById('footer')).height.replace('px', '')) + offset) : 0) + 'px';
//按钮上的提示
document.getElementById('generate').setAttribute('disabled', '');
document.getElementById('generate').innerText = '生成中...';
(inBlacklist ?
Promise.reject('你所访问的网站(' + location.hostname + ')由于在转载本工具时抹去了原作者相关信息,已被原作者列入黑名单,无法生成截图。') :
html2canvas(document.getElementById('fakeWechatMoment'), {
useCORS: true,
scale: 1,
})
).then(function (canvas) {
var dURL = canvas.toDataURL();
document.getElementById('generated').src = dURL;
document.getElementById('save').setAttribute('href', dURL);
document.getElementById('save').setAttribute('download', (+new Date) + '.png');
(new mdui.Dialog(document.getElementById('generatedPopup'))).open();
// 保存配置
var config = {
name: document.getElementById('configName').value,
text: document.getElementById('configText').value,
location: document.getElementById('configLocation').value,
app: document.getElementById('configApp').value,
height: parseInt(document.getElementById('configHeight').value),
uiWhite: document.getElementById('configUIWhite').checked,
appIcon: document.getElementById('configTopBarAppIcons').checked,
statusIcon: document.getElementById('configTopBarStatusIcons').checked,
};
localStorage.setItem('config', JSON.stringify(config));
if (avatarFile) {
var reader = new FileReader;
reader.readAsDataURL(avatarFile);
reader.onload = function () {
localStorage.setItem('avatar', this.result);
};
}
}).catch(function (error) {
mdui.alert(''
+ '<div class="mdui-typo">'
+ '<p>错误信息:</p>'
+ '<pre>' + error + '</pre>'
+ '<p>你可以通过 <a href="https://github.com/TransparentLC/WechatMomentScreenshot/issues" target="_blank">Issue</a> 向作者反馈 BUG~</p>'
+ '</div>',
'生成失败'
);
}).finally(function () {
// document.getElementById('fakeWechatMoment').style.display = 'none';
document.getElementById('generate').removeAttribute('disabled');
document.getElementById('generate').innerText = '生成';
});
});