forked from sansan0/TrendRadar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
973 lines (864 loc) · 41.7 KB
/
index.html
File metadata and controls
973 lines (864 loc) · 41.7 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
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>热点新闻分析</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js" integrity="sha512-BNaRQnYJYiPSqHHDb58B0yaPfCu+Wgds8Gp/gU33kqBtgNS4tSPHuGibyoeqMV/TJlSKda6FXzoEyYGjTe+vXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<style>
* { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
margin: 0;
padding: 16px;
background: #fafafa;
color: #333;
line-height: 1.5;
}
.container {
max-width: 600px;
margin: 0 auto;
background: white;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 2px 16px rgba(0,0,0,0.06);
}
.header {
background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
color: white;
padding: 32px 24px;
text-align: center;
position: relative;
}
.save-buttons {
position: absolute;
top: 16px;
right: 16px;
display: flex;
gap: 8px;
}
.save-btn {
background: rgba(255, 255, 255, 0.2);
border: 1px solid rgba(255, 255, 255, 0.3);
color: white;
padding: 8px 16px;
border-radius: 6px;
cursor: pointer;
font-size: 13px;
font-weight: 500;
transition: all 0.2s ease;
backdrop-filter: blur(10px);
white-space: nowrap;
}
.save-btn:hover {
background: rgba(255, 255, 255, 0.3);
border-color: rgba(255, 255, 255, 0.5);
transform: translateY(-1px);
}
.save-btn:active {
transform: translateY(0);
}
.save-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.header-title {
font-size: 22px;
font-weight: 700;
margin: 0 0 20px 0;
}
.header-info {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
font-size: 14px;
opacity: 0.95;
}
.info-item {
text-align: center;
}
.info-label {
display: block;
font-size: 12px;
opacity: 0.8;
margin-bottom: 4px;
}
.info-value {
font-weight: 600;
font-size: 16px;
}
.content {
padding: 24px;
}
.word-group {
margin-bottom: 40px;
}
.word-group:first-child {
margin-top: 0;
}
.word-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 20px;
padding-bottom: 8px;
border-bottom: 1px solid #f0f0f0;
}
.word-info {
display: flex;
align-items: center;
gap: 12px;
}
.word-name {
font-size: 17px;
font-weight: 600;
color: #1a1a1a;
}
.word-count {
color: #666;
font-size: 13px;
font-weight: 500;
}
.word-count.hot { color: #dc2626; font-weight: 600; }
.word-count.warm { color: #ea580c; font-weight: 600; }
.word-index {
color: #999;
font-size: 12px;
}
.news-item {
margin-bottom: 20px;
padding: 16px 0;
border-bottom: 1px solid #f5f5f5;
position: relative;
display: flex;
gap: 12px;
align-items: center;
}
.news-item:last-child {
border-bottom: none;
}
.news-item.new::after {
content: "NEW";
position: absolute;
top: 12px;
right: 0;
background: #fbbf24;
color: #92400e;
font-size: 9px;
font-weight: 700;
padding: 3px 6px;
border-radius: 4px;
letter-spacing: 0.5px;
}
.news-number {
color: #999;
font-size: 13px;
font-weight: 600;
min-width: 20px;
text-align: center;
flex-shrink: 0;
background: #f8f9fa;
border-radius: 50%;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
align-self: flex-start;
margin-top: 8px;
}
.news-content {
flex: 1;
min-width: 0;
padding-right: 40px;
}
.news-item.new .news-content {
padding-right: 50px;
}
.news-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
flex-wrap: wrap;
}
.source-name {
color: #666;
font-size: 12px;
font-weight: 500;
}
.rank-num {
color: #fff;
background: #6b7280;
font-size: 10px;
font-weight: 700;
padding: 2px 6px;
border-radius: 10px;
min-width: 18px;
text-align: center;
}
.rank-num.top { background: #dc2626; }
.rank-num.high { background: #ea580c; }
.time-info {
color: #999;
font-size: 11px;
}
.count-info {
color: #059669;
font-size: 11px;
font-weight: 500;
}
.news-title {
font-size: 15px;
line-height: 1.4;
color: #1a1a1a;
margin: 0;
}
.news-link {
color: #2563eb;
text-decoration: none;
}
.news-link:hover {
text-decoration: underline;
}
.news-link:visited {
color: #7c3aed;
}
.new-section {
margin-top: 40px;
padding-top: 24px;
border-top: 2px solid #f0f0f0;
}
.new-section-title {
color: #1a1a1a;
font-size: 16px;
font-weight: 600;
margin: 0 0 20px 0;
}
.new-source-group {
margin-bottom: 24px;
}
.new-source-title {
color: #666;
font-size: 13px;
font-weight: 500;
margin: 0 0 12px 0;
padding-bottom: 6px;
border-bottom: 1px solid #f5f5f5;
}
.new-item {
display: flex;
align-items: center;
gap: 12px;
padding: 8px 0;
border-bottom: 1px solid #f9f9f9;
}
.new-item:last-child {
border-bottom: none;
}
.new-item-number {
color: #999;
font-size: 12px;
font-weight: 600;
min-width: 18px;
text-align: center;
flex-shrink: 0;
background: #f8f9fa;
border-radius: 50%;
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.new-item-rank {
color: #fff;
background: #6b7280;
font-size: 10px;
font-weight: 700;
padding: 3px 6px;
border-radius: 8px;
min-width: 20px;
text-align: center;
flex-shrink: 0;
}
.new-item-rank.top { background: #dc2626; }
.new-item-rank.high { background: #ea580c; }
.new-item-content {
flex: 1;
min-width: 0;
}
.new-item-title {
font-size: 14px;
line-height: 1.4;
color: #1a1a1a;
margin: 0;
}
.error-section {
background: #fef2f2;
border: 1px solid #fecaca;
border-radius: 8px;
padding: 16px;
margin-bottom: 24px;
}
.error-title {
color: #dc2626;
font-size: 14px;
font-weight: 600;
margin: 0 0 8px 0;
}
.error-list {
list-style: none;
padding: 0;
margin: 0;
}
.error-item {
color: #991b1b;
font-size: 13px;
padding: 2px 0;
font-family: 'SF Mono', Consolas, monospace;
}
.footer {
margin-top: 32px;
padding: 20px 24px;
background: #f8f9fa;
border-top: 1px solid #e5e7eb;
text-align: center;
}
.footer-content {
font-size: 13px;
color: #6b7280;
line-height: 1.6;
}
.footer-link {
color: #4f46e5;
text-decoration: none;
font-weight: 500;
transition: color 0.2s ease;
}
.footer-link:hover {
color: #7c3aed;
text-decoration: underline;
}
.project-name {
font-weight: 600;
color: #374151;
}
@media (max-width: 480px) {
body { padding: 12px; }
.header { padding: 24px 20px; }
.content { padding: 20px; }
.footer { padding: 16px 20px; }
.header-info { grid-template-columns: 1fr; gap: 12px; }
.news-header { gap: 6px; }
.news-content { padding-right: 45px; }
.news-item { gap: 8px; }
.new-item { gap: 8px; }
.news-number { width: 20px; height: 20px; font-size: 12px; }
.save-buttons {
position: static;
margin-bottom: 16px;
display: flex;
gap: 8px;
justify-content: center;
flex-direction: column;
width: 100%;
}
.save-btn {
width: 100%;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<div class="save-buttons">
<button class="save-btn" onclick="saveAsImage()">保存为图片</button>
<button class="save-btn" onclick="saveAsMultipleImages()">分段保存</button>
</div>
<div class="header-title">热点新闻分析</div>
<div class="header-info">
<div class="info-item">
<span class="info-label">报告类型</span>
<span class="info-value">当日汇总</span>
</div>
<div class="info-item">
<span class="info-label">新闻总数</span>
<span class="info-value">255 条</span>
</div>
<div class="info-item">
<span class="info-label">热点新闻</span>
<span class="info-value">16 条</span>
</div>
<div class="info-item">
<span class="info-label">生成时间</span>
<span class="info-value">12-02 11:19</span>
</div>
</div>
</div>
<div class="content">
<div class="word-group">
<div class="word-header">
<div class="word-info">
<div class="word-name">github ai 人工智能 star</div>
<div class="word-count hot">10 条</div>
</div>
<div class="word-index">1/3</div>
</div>
<div class="news-item ">
<div class="news-number">1</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">微博</span><span class="rank-num top">3</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://s.weibo.com/weibo?q=%23%E7%BD%91%E8%AD%A6%E4%BE%A6%E7%A0%B4AI%E6%8D%A2%E8%84%B8%E4%BE%B5%E5%85%A5%E8%AE%A1%E7%AE%97%E6%9C%BA%E6%A1%88%23&t=31&band_rank=3&Refer=top" target="_blank" class="news-link">网警侦破AI换脸侵入计算机案</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">2</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">今日头条</span><span class="rank-num ">6</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://www.toutiao.com/trending/7578802867742461503/" target="_blank" class="news-link">网警破获通过AI换脸非法侵入系统案</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">3</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">百度热搜</span><span class="rank-num ">6</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://www.baidu.com/s?wd=%E7%BD%91%E8%AD%A6%E7%A0%B4%E8%8E%B7%E2%80%9CAI%E6%8D%A2%E8%84%B8%E2%80%9D%E4%BE%B5%E5%85%A5%E8%AE%A1%E7%AE%97%E6%9C%BA%E6%A1%88" target="_blank" class="news-link">网警破获“AI换脸”侵入计算机案</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">4</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">bilibili 热搜</span><span class="rank-num ">6</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://search.bilibili.com/all?keyword=%E7%BD%91%E8%AD%A6%E7%A0%B4%E8%8E%B7AI%E6%8D%A2%E8%84%B8%E9%9D%9E%E6%B3%95%E4%BE%B5%E5%85%A5%E7%B3%BB%E7%BB%9F%E6%A1%88" target="_blank" class="news-link">网警破获AI换脸非法侵入系统案</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">5</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">财联社热门</span><span class="rank-num ">6</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://www.cls.cn/detail/2216587" target="_blank" class="news-link">剑指AI芯片市场!大摩上调谷歌TPU产量预期:2027年或达500万块</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">6</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">抖音</span><span class="rank-num ">6</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://www.douyin.com/hot/2323802" target="_blank" class="news-link">网警破获AI换脸非法侵入案</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">7</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">财联社热门</span><span class="rank-num ">7</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://www.cls.cn/detail/2216608" target="_blank" class="news-link">“让AI拥有操作系统级权限!” 字节跳动携手中兴通讯试水AI手机</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">8</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">华尔街见闻</span><span class="rank-num ">9</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://wallstreetcn.com/articles/3760479" target="_blank" class="news-link">英伟达砸20亿入股EDA巨头新思科技,黄仁勋盛赞“巨大扩展机遇”、否认类似OpenAI交易闭环</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">9</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">财联社热门</span><span class="rank-num ">11</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://www.cls.cn/detail/2216521" target="_blank" class="news-link">苹果更换AI主管 白银年内涨幅突破100% | 环球市场</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">10</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">微博</span><span class="rank-num ">14</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://s.weibo.com/weibo?q=%E9%83%91%E6%81%BA%E4%B8%8A%E6%88%8F%E5%90%88%E5%BD%B1%20AI%E7%94%9F%E6%88%90&t=31&band_rank=14&Refer=top" target="_blank" class="news-link">郑恺上戏合影 AI生成</a>
</div>
</div>
</div>
</div>
<div class="word-group">
<div class="word-header">
<div class="word-info">
<div class="word-name">DeepSeek deepseek grok</div>
<div class="word-count warm">5 条</div>
</div>
<div class="word-index">2/3</div>
</div>
<div class="news-item ">
<div class="news-number">1</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">财联社热门</span><span class="rank-num top">1</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://www.cls.cn/detail/2216499" target="_blank" class="news-link">【早报】热门中概股逆势飘红,银价续创历史新高;DeepSeek发布两款新模型</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">2</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">华尔街见闻</span><span class="rank-num high">4</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://wallstreetcn.com/articles/3760468" target="_blank" class="news-link">开源最强!“拳打GPT 5”,“脚踢Gemini-3.0”,DeepSeek V3.2为何提升这么多?</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">3</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">bilibili 热搜</span><span class="rank-num high">4</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://search.bilibili.com/all?keyword=%E5%AE%9E%E6%B5%8BDeepSeekV3.2%E6%AD%A3%E5%BC%8F%E7%89%88" target="_blank" class="news-link">实测DeepSeekV3.2正式版</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">4</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">华尔街见闻</span><span class="rank-num high">5</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://wallstreetcn.com/articles/3760461" target="_blank" class="news-link">DeepSeek发布V3.2系列模型,强化Agent能力,推理能力追平GPT-5</a>
</div>
</div>
</div>
<div class="news-item ">
<div class="news-number">5</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">bilibili 热搜</span><span class="rank-num ">9</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://search.bilibili.com/all?keyword=DeepSeek%E6%96%B0%E6%A8%A1%E5%9E%8B%E8%BF%BD%E5%B9%B3Gemini" target="_blank" class="news-link">DeepSeek新模型追平Gemini</a>
</div>
</div>
</div>
</div>
<div class="word-group">
<div class="word-header">
<div class="word-info">
<div class="word-name">谷歌 google gemini deepmind</div>
<div class="word-count ">1 条</div>
</div>
<div class="word-index">3/3</div>
</div>
<div class="news-item ">
<div class="news-number">1</div>
<div class="news-content">
<div class="news-header">
<span class="source-name">华尔街见闻</span><span class="rank-num ">7</span><span class="time-info">11时19分</span>
</div>
<div class="news-title"><a href="https://wallstreetcn.com/articles/3760440" target="_blank" class="news-link">大摩大幅上调谷歌TPU产量预测:2027年达500万块,每50万块“外销”或增收130亿美元</a>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="footer-content">
由 <span class="project-name">TrendRadar</span> 生成 ·
<a href="https://github.com/sansan0/TrendRadar" target="_blank" class="footer-link">
GitHub 开源项目
</a>
<br>
<span style="color: #ea580c; font-weight: 500;">
发现新版本 3.4.1,当前版本 3.1.0
</span>
</div>
</div>
</div>
<script>
async function saveAsImage() {
const button = event.target;
const originalText = button.textContent;
try {
button.textContent = '生成中...';
button.disabled = true;
window.scrollTo(0, 0);
// 等待页面稳定
await new Promise(resolve => setTimeout(resolve, 200));
// 截图前隐藏按钮
const buttons = document.querySelector('.save-buttons');
buttons.style.visibility = 'hidden';
// 再次等待确保按钮完全隐藏
await new Promise(resolve => setTimeout(resolve, 100));
const container = document.querySelector('.container');
const canvas = await html2canvas(container, {
backgroundColor: '#ffffff',
scale: 1.5,
useCORS: true,
allowTaint: false,
imageTimeout: 10000,
removeContainer: false,
foreignObjectRendering: false,
logging: false,
width: container.offsetWidth,
height: container.offsetHeight,
x: 0,
y: 0,
scrollX: 0,
scrollY: 0,
windowWidth: window.innerWidth,
windowHeight: window.innerHeight
});
buttons.style.visibility = 'visible';
const link = document.createElement('a');
const now = new Date();
const filename = `TrendRadar_热点新闻分析_${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}_${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}.png`;
link.download = filename;
link.href = canvas.toDataURL('image/png', 1.0);
// 触发下载
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
button.textContent = '保存成功!';
setTimeout(() => {
button.textContent = originalText;
button.disabled = false;
}, 2000);
} catch (error) {
const buttons = document.querySelector('.save-buttons');
buttons.style.visibility = 'visible';
button.textContent = '保存失败';
setTimeout(() => {
button.textContent = originalText;
button.disabled = false;
}, 2000);
}
}
async function saveAsMultipleImages() {
const button = event.target;
const originalText = button.textContent;
const container = document.querySelector('.container');
const scale = 1.5;
const maxHeight = 5000 / scale;
try {
button.textContent = '分析中...';
button.disabled = true;
// 获取所有可能的分割元素
const newsItems = Array.from(container.querySelectorAll('.news-item'));
const wordGroups = Array.from(container.querySelectorAll('.word-group'));
const newSection = container.querySelector('.new-section');
const errorSection = container.querySelector('.error-section');
const header = container.querySelector('.header');
const footer = container.querySelector('.footer');
// 计算元素位置和高度
const containerRect = container.getBoundingClientRect();
const elements = [];
// 添加header作为必须包含的元素
elements.push({
type: 'header',
element: header,
top: 0,
bottom: header.offsetHeight,
height: header.offsetHeight
});
// 添加错误信息(如果存在)
if (errorSection) {
const rect = errorSection.getBoundingClientRect();
elements.push({
type: 'error',
element: errorSection,
top: rect.top - containerRect.top,
bottom: rect.bottom - containerRect.top,
height: rect.height
});
}
// 按word-group分组处理news-item
wordGroups.forEach(group => {
const groupRect = group.getBoundingClientRect();
const groupNewsItems = group.querySelectorAll('.news-item');
// 添加word-group的header部分
const wordHeader = group.querySelector('.word-header');
if (wordHeader) {
const headerRect = wordHeader.getBoundingClientRect();
elements.push({
type: 'word-header',
element: wordHeader,
parent: group,
top: groupRect.top - containerRect.top,
bottom: headerRect.bottom - containerRect.top,
height: headerRect.height
});
}
// 添加每个news-item
groupNewsItems.forEach(item => {
const rect = item.getBoundingClientRect();
elements.push({
type: 'news-item',
element: item,
parent: group,
top: rect.top - containerRect.top,
bottom: rect.bottom - containerRect.top,
height: rect.height
});
});
});
// 添加新增新闻部分
if (newSection) {
const rect = newSection.getBoundingClientRect();
elements.push({
type: 'new-section',
element: newSection,
top: rect.top - containerRect.top,
bottom: rect.bottom - containerRect.top,
height: rect.height
});
}
// 添加footer
const footerRect = footer.getBoundingClientRect();
elements.push({
type: 'footer',
element: footer,
top: footerRect.top - containerRect.top,
bottom: footerRect.bottom - containerRect.top,
height: footer.offsetHeight
});
// 计算分割点
const segments = [];
let currentSegment = { start: 0, end: 0, height: 0, includeHeader: true };
let headerHeight = header.offsetHeight;
currentSegment.height = headerHeight;
for (let i = 1; i < elements.length; i++) {
const element = elements[i];
const potentialHeight = element.bottom - currentSegment.start;
// 检查是否需要创建新分段
if (potentialHeight > maxHeight && currentSegment.height > headerHeight) {
// 在前一个元素结束处分割
currentSegment.end = elements[i - 1].bottom;
segments.push(currentSegment);
// 开始新分段
currentSegment = {
start: currentSegment.end,
end: 0,
height: element.bottom - currentSegment.end,
includeHeader: false
};
} else {
currentSegment.height = potentialHeight;
currentSegment.end = element.bottom;
}
}
// 添加最后一个分段
if (currentSegment.height > 0) {
currentSegment.end = container.offsetHeight;
segments.push(currentSegment);
}
button.textContent = `生成中 (0/${segments.length})...`;
// 隐藏保存按钮
const buttons = document.querySelector('.save-buttons');
buttons.style.visibility = 'hidden';
// 为每个分段生成图片
const images = [];
for (let i = 0; i < segments.length; i++) {
const segment = segments[i];
button.textContent = `生成中 (${i + 1}/${segments.length})...`;
// 创建临时容器用于截图
const tempContainer = document.createElement('div');
tempContainer.style.cssText = `
position: absolute;
left: -9999px;
top: 0;
width: ${container.offsetWidth}px;
background: white;
`;
tempContainer.className = 'container';
// 克隆容器内容
const clonedContainer = container.cloneNode(true);
// 移除克隆内容中的保存按钮
const clonedButtons = clonedContainer.querySelector('.save-buttons');
if (clonedButtons) {
clonedButtons.style.display = 'none';
}
tempContainer.appendChild(clonedContainer);
document.body.appendChild(tempContainer);
// 等待DOM更新
await new Promise(resolve => setTimeout(resolve, 100));
// 使用html2canvas截取特定区域
const canvas = await html2canvas(clonedContainer, {
backgroundColor: '#ffffff',
scale: scale,
useCORS: true,
allowTaint: false,
imageTimeout: 10000,
logging: false,
width: container.offsetWidth,
height: segment.end - segment.start,
x: 0,
y: segment.start,
windowWidth: window.innerWidth,
windowHeight: window.innerHeight
});
images.push(canvas.toDataURL('image/png', 1.0));
// 清理临时容器
document.body.removeChild(tempContainer);
}
// 恢复按钮显示
buttons.style.visibility = 'visible';
// 下载所有图片
const now = new Date();
const baseFilename = `TrendRadar_热点新闻分析_${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}_${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}`;
for (let i = 0; i < images.length; i++) {
const link = document.createElement('a');
link.download = `${baseFilename}_part${i + 1}.png`;
link.href = images[i];
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
// 延迟一下避免浏览器阻止多个下载
await new Promise(resolve => setTimeout(resolve, 100));
}
button.textContent = `已保存 ${segments.length} 张图片!`;
setTimeout(() => {
button.textContent = originalText;
button.disabled = false;
}, 2000);
} catch (error) {
console.error('分段保存失败:', error);
const buttons = document.querySelector('.save-buttons');
buttons.style.visibility = 'visible';
button.textContent = '保存失败';
setTimeout(() => {
button.textContent = originalText;
button.disabled = false;
}, 2000);
}
}
document.addEventListener('DOMContentLoaded', function() {
window.scrollTo(0, 0);
});
</script>
</body>
</html>