-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfront.js
783 lines (684 loc) · 18.4 KB
/
front.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
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
// ==UserScript==
// @name 博客园
// @namespace http://www.terwergreen.com/
// @version 0.0.1
// @description 博客园界面美化
// @author Terwer
// @match *://www.cnblogs.com/
// @match *://www.cnblogs.com/sitehome*
// @match *://www.cnblogs.com/pick*
// @match *://www.cnblogs.com/candidate*
// @match *://www.cnblogs.com/news*
// @match *://www.cnblogs.com/following*
// @match *://www.cnblogs.com/aggsite*
// @match *://www.cnblogs.com/cate*
// @match *://www.cnblogs.com/comment*
// @grant GM_addStyle
// @require https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js
// ==/UserScript==
console.log("New style of cnblogs desgined by Terwer!");
// bootstrap4
addLinkCss('https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css');
console.log("add bootstrap4");
function addLinkCss(url){
var link = window.document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = url;
document.getElementsByTagName("HEAD")[0].appendChild(link);
}
var cnblogsCss = `
body{
line-height:22px;
margin: 0;
padding: 0;
font-size: 14px;
font-family: "Hiragino Sans GB","Microsoft Yahei",SimSun,Arial,"Helvetica Neue",Helvetica;
color: #333;
word-wrap: break-word;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background: #fff !important;
}
button, input, optgroup, select, textarea {
margin: 0;
padding: 0;
border: 1px solid #ededed;
border-radius: 0;
font-family: "Hiragino Sans GB","Microsoft Yahei",SimSun,Arial,"Helvetica Neue",Helvetica;
}
a:link, a:visited, a:active {
color: #555 !important;
background-color: transparent !important;
}
a:hover{
color: #00B38A !important;
}
ul, ol {
margin: 0;
padding: 0;
list-style: none;
}
`;
cnblogsCss +=`
#cnblogs_a1{
display:none;
}
#cnblogs_b1{
display:none;
}
#cnblogs_b2{
display:none;
}
#cnblogs_b3{
display:none;
}
#cnblogs_b4{
display:none;
}
#hd_info{
background: #F2F5F4 !important;
}
`;
// nav_menu
cnblogsCss += `
#nav_menu{
margin:0;
min-width: 1200px;
height: 40px;
background: #32373e;
}
#nav_menu .inner {
position: relative;
max-width: 1200px;
margin: 0 auto;
}
#nav_menu div.lg_tbar_l {
float: left;
}
#nav_menu ul.lg_tbar_m {
float: left;
overflow: hidden;
margin-left: 34px;
}
#nav_menu div.lg_tbar_r {
float: right;
}
#nav_menu div.lg_tbar_l .logo {
color: #00B38A !important;
height: 21px;
float: left;
padding-left: 0;
font-weight: bold;
font-size: 24px;
text-decoration: none;
}
#nav_menu div.lg_tbar_l a, #lg_tbar div.lg_tbar_r a, #lg_tbar div.lg_tbar_l span, #lg_tbar div.lg_tbar_r span {
color: #c4c3c3 !important;
float: left;
line-height: 40px;
padding: 0 12px;
}
#nav_menu ul.lg_tbar_m li {
width: 70px;
line-height: 40px;
float: left;
}
#nav_menu ul.lg_tbar_m li a.current {
color: #fff !important;
background: #24282C !important;
}
#nav_menu ul.lg_tbar_m li a {
font-size: 14px;
color: #afb5c0 !important;
width: 100%;
height: 100%;
display: block;
text-align: center;
padding:0;
}
#nav_menu a:link, #nav_menu a:visited, #nav_menu a:active {
color: #eee !important;
text-decoration: none;
}
#nav_menu ul.lg_tbar_m li a:hover{
color: #fff !important;
}
#nav_menu div.lg_tbar_l a.lg_app, #nav_menu div.lg_tbar_r a.lg_app {
color: #08d7a2;
padding: 0 12px 0 27px;
margin-top: 13px;
line-height: 15px;
}
#nav_menu div.lg_tbar_l a, #nav_menu div.lg_tbar_r a, #nav_menu div.lg_tbar_l span, #nav_menu div.lg_tbar_r span {
color: #c4c3c3;
float: left;
line-height: 40px;
padding: 0 12px;
}
`;
cnblogsCss += `
#side_nav{
top:174px;
background-color: #fff !important;
}
#side_right{
top:174px;
background-color: #fff !important;
}
.search-wrapper {
background: #F2F5F4;
padding: 30px 0 28px;
min-width: 1200px;
}
.search_box {
border: 0 solid #00b38a;
width: 938px;
height: 46px;
margin: 0 auto;
position: relative;
}
.search_input {
width: 762px;
height: 20px;
line-height: 20px;
float: left;
font-size: 16px;
padding: 12px 16px;
margin: 0;
border: 1px solid #E8E8E8;
border-right: 0;
}
.search_button {
float: left;
width: 142px;
height: 46px;
font-size: 18px;
color: #FFF;
border: 0;
background: #00b38a;
cursor: pointer;
}
`;
cnblogsCss += `
.rss_link{
top:178px;
}
`
cnblogsCss += `
.post_nav_block_wrapper{
border:none;
}
.post_nav_block a{
border:none;
}
.post_nav_block a.current_nav:link, .post_nav_block a.current_nav:visited, .post_nav_block a.current_nav:active {
background-color: #fff;
border:none;
border-bottom: 2px solid #0dca9f;
}
.post_nav_block a:link, .post_nav_block a:visited, .post_nav_block a:active{
border:none;
}
.post_item{
color: #555;
border: 1px solid #ededed;
padding: 18px;
}
.post_item_body{
margin-left: 0;
}
.post_item_body a.titlelnk{
margin: 0;
font-size: 16px;
color: #00b38a !important;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
word-wrap: normal;
font-weight: normal;
text-decoration: none;
}
#post_list .post_item_summary{
font-size: 14px;
}
.post_item_foot{
height: 20px;
padding: 15px 10px;
background-color: #fafafa;
}
.diggit{
display: inline-block;
max-width: 108px;
height: 28px;
font-size: 12px;
line-height: 20px;
color: #555 !important;
border: 1px solid #dcdcdc;
border-radius: 3px;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
word-wrap: normal;
background-image:none;
background-color: #fafafa;
}
.diggnum{
color: #555 !important;
}
.pfs{
width:48px;
height:48px;
margin-right:15px;
border:none;
margin-top:0;
}
.digg{
float:right;
}
.gray:hover{
font-size:14px;
}
`;
// 左侧菜单
cnblogsCss += `
#side_nav{
top:596px;
}
#sidebar{
position: absolute;
left: 10px;
top: 174px;
}
.r_l_1{
height: 0;
}
.r_l_2{
margin: 0;
height: 0;
}
.r_l_3{
margin: 0;
height: 0;
border-bottom: 1px solid #ddd;
}
#side_nav .w_l{
border-left: 1px solid #ddd;
border-right: 1px solid #ddd;
}
`;
cnblogsCss+=`
ul, dl, dd {
padding: 0;
margin: 0;
list-style: none;
color: #666;
}
.mainside_l {
width: 160px;
background: #fff;
border: 1px solid #00b38a;
margin: 0;
}
/*整个列表的宽高,背景,边框*/
.list_title {
height: 30px;
width: 160px;
background: #00b38a;
color: #fff;
font-size: 18px;
font-weight: bold;
line-height: 30px;
text-align: center;
margin: 0; /*如果不设置,标题与列表之间有空白*/
}
/*列表标题的宽高,背景,字体*/
.list {
padding-top: 6px; /*列表与标题之间的空隙*/
position: relative;
}
.list > li {
font-size: 14px;
line-height: 32px;
padding-left: 26px;
padding-right: 12px;
}
/*直接子元素*/
.list a {
color: #666;
}
/*列表文字颜色*/
.list > li:hover {
color: #00b38a;
background: #b8f4e7;
}
/*当鼠标滑过时,列表项颜色、背景变化*/
.list a:hover {
color: #ff5000;
}
/*当鼠标滑过时,列表字体颜色变化*/
.list_fuhao {
float: right;
}
/* > 这个符号靠右显示*/
.li_toggle:hover ul {
display: block;
}
.li_toggle a{
text-decoration: none;
}
/*鼠标滑过时,显示菜单*/
.list_items {
position: absolute;
left: 160px;
top: 0;
border: 1px solid #00b38a;
background: #fff;
display: none; /*隐藏菜单*/
}
/*二级菜单设置*/
.list_items_l {
float: left;
border-right: 1px solid #f4f4f4;
}
/*二级菜单左侧区域设置*/
.list_items_l a {
text-decoration: none;
}
.list_dl {
padding: 10px 14px 0 26px;
}
/*二级菜单左侧定义列表*/
.list_dl h3 {
font-size: 18px;
font-weight: normal;
padding-top: 12px;
}
/*二级菜单左侧标题*/
.list_dl h3 a {
color: #3c3c3c;
}
.list_dl dt span {
float: right;
font-size: 12px;
}
.list_dl dd {
font-size: 12px;
line-height: 26px;
padding-bottom: 10px;
}
/*二级菜单列表项设置*/
.list_dl dd a {
padding-right: 13px;
white-space: nowrap;
}
/*二级菜单列表超链接设置*/
.list_dl dd a:hover {
color: #666;
}
.list_items_r {
float: right;
width: 250px;
height: 518px;
text-align: left;
}
/*二级菜单右侧区域设置*/
.list_items_r h3 {
font-size: 16px;
margin: 10px 0 0;
height: 40px;
line-height: 40px;
text-align: center;
}
/*二级菜单右侧标题*/
.list_items_pic {
margin: 0 10px;
width: 232px;
height: 456px;
}
/*二级菜单右侧列表设置*/
.pic {
float: left;
width: 116px;
height: 152px;
padding: 0 10px;
}
/*二级菜单右侧图片div设置*/
.pic a {
text-decoration: none;
}
.pic img {
width: 97px;
height: 97px;
border: 1px dotted #ededed;
}
.pic p {
width: 97px;
overflow: hidden;
text-overflow: clip;
white-space: nowrap;
font-size: 12px;
text-align: center;
}
/*二级菜单右侧图片div设置*/
`;
cnblogsCss += `
#paging_block{
margin: 0 6px;
}
#paging_block a:link, a:visited, a: {
color: #555 !important;
background-color: transparent !important;
text-decoration: none;
}
#paging_block a:hover,.active {
color:#e9ecef !important;
background-color: #00B38A !important;
}
#paging_block .active {
color:#e9ecef !important;
background-color: #00B38A !important;
}
.search_input{
height:47px;
}
p{
margin:0;
}
`;
//与元数据块中的@grant值相对应,功能是生成一个style样式
GM_addStyle(cnblogsCss);
// 移除广告
removeAd();
// 生成菜单
makeNavMenu();
// 生成搜索
makeSearch();
// 生成左侧菜单
makeLeftMenu();
// 生成分页
makePager();
// function
function removeAd() {
$("#header").remove();
$("#cnblogs_a1").remove();
$("#cnblogs_b1").remove();
$("#cnblogs_b2").remove();
$("#cnblogs_b3").remove();
$("#cnblogs_b4").remove();
$(".side_search").remove();
$("#search_block").remove();
$("#ad_right_text").remove();
}
// make nav menu
function makeNavMenu() {
var inner = ``;
var innerHeader = `<div class="inner">
<div class="lg_tbar_l">
<a href="https://www.cnblogs.com/" class="logo">博客园</a>
</div>`;
var innerBody = `<ul class="lg_tbar_m">
<li>
<a href="https://www.cnblogs.com/" class="current" data-lg-tj-id="5i00" data-lg-tj-no="idnull" data-lg-tj-cid="idnull">首页</a>
</li>
`;
var as = $("#nav_menu a");
// console.log(as);
as.each(function (i, n) {
var hrf = $(n).attr("href");
var txt = $(n).text();
innerBody += `<li><a rel="nofollow" href="` + hrf + `" target="_blank" data-lg-tj-id="ic00" data-lg-tj-no="idnull" data-lg-tj-cid="idnull" data-lg-tj-track-code="index_yanzhi">` + txt + `</a></li>`;
});
innerBody += `</ul>`;
var innerFooter = `<div class="lg_tbar_r">
<a rel="nofollow" href="https://app.cnblogs.com/" target="_blank" class="lg_app" data-lg-tj-id="5500" data-lg-tj-no="idnull" data-lg-tj-cid="idnull" target="_blank">博客园APP</a>
<a rel="nofollow" href="https://i.cnblogs.com/" target="_blank" class="lg_os" data-lg-tj-id="5600" data-lg-tj-no="idnull" data-lg-tj-cid="idnull" data-lg-tj-track-code="index_qiyeban">进入后台</a>
</div>
</div>`;
inner += innerHeader;
inner += innerBody;
inner += innerFooter;
$("#nav_menu").empty()
$("#nav_menu").append(inner);
}
// make search
function makeSearch() {
var search = `
<div id="search">
<!-- 搜索 -->
<div class="search-wrapper">
<div id="search_box" class="search_box" data-lg-tj-track-code="index_search" data-lg-tj-track-type="1">
<form id="searchForm" class="searchForm clearfix" name="searchForm" action="https://zzk.cnblogs.com/s?t=b" method="get">
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
<input type="text" id="search_input" name="w" class="search_input ui-autocomplete-input" tabindex="1" maxlength="64" autocomplete="off" value="" placeholder="请输入文章关键字">
<input type="submit" id="search_button" class="search_button" value="搜索" data-lg-tj-id="4V00" data-lg-tj-no="idnull" data-lg-tj-cid="idnull">
</form>
</div>
</div>
</div>
`;
$("#nav_menu").after(search);
}
// make left menu
function makeLeftMenu() {
var leftMenu = `
<div id="sidebar">
<div class="mainside_l">
<h3 class="list_title">网站分类</h3>
`;
leftMenu += `
<ul class="list">
`;
// 每一项开始
var firstCatIdArray = cateIdList.split(",");
var firstCnblogsMenu = $("#cate_title_block #cate_item li");
// console.log("firstCnblogsMenu=>", firstCnblogsMenu);
firstCnblogsMenu.each(function(i, n){
// console.log("fm=>", n)
var fa = $(n).find("a").eq(0);
var fid = firstCatIdArray[i];
var fhref = $(fa).attr("href");
var ftext = $(fa).text();
// .NET技术108698缓存java技术
if(fid == 108698){
fhref = '/cate/java/';
ftext = 'Java后端';
}
leftMenu += `
<li class="li_toggle" id="li_toggle_`+ fid +`">
<a href="`+ fhref +`">`+ ftext +`</a>
`;
leftMenu += `
</li>
`;
});
// 每一项结束
leftMenu += `
</ul>
`;
leftMenu +=`
</div>
</div>
`;
// $("#cate_title_block").remove();
$("#pager_bottom").after(leftMenu);
// 等菜单加载完成后加载子菜单
var loadCnblogsSubCategories = function () {
// var subblock = $("#cate_sub_block");
$.ajax({
type: "post",
contentType: 'application/json; charset=utf-8', // 很重要
url: "/aggsite/SubCategories",
data: '{"cateIds":"' + cateIdList + '"}',
dataType: "text",
success: function(res) {
// console.log(res);
var wrapper= document.createElement('div');
wrapper.innerHTML=res;
// console.log(wrapper);
// 子菜单
firstCatIdArray.forEach(function(e) {
var fid = e;
// console.log("show sub " + fid);
var sub = $(wrapper).find("#cate_content_block_"+fid);
var secondCnblogsMenu = $(sub).find('.cate_content_block ul li');
// 有子菜单才追加
if(secondCnblogsMenu.length>0 && fid!=108698){
var subItem = ``;
subItem +=`
<span class="list_fuhao"> > </span>
<ul class="list_items">
<li class="list_items_l">
<dl class="list_dl">
`;
$(secondCnblogsMenu).each(function(k,m){
// console.log("m=>", $(m).html());
subItem+=`<dd>`+$(m).html()+`</dd>`;
});
subItem+=`
</dl>
</li>
</ul>`;
$("#li_toggle_"+fid).append(subItem);
// console.log("subItem=>", subItem);
}
});
// 全部完成,删除就菜单
$("#cate_title_block").remove();
}
});
};
// 加载子菜单
loadCnblogsSubCategories();
}
// 分页
function makePager(){
var pager = $("#paging_block .pager");
console.log("pager=>", pager);
var newas = "";
pager.children().each(function(i,n){
console.log("href",$(n).attr("href"));
console.log("class",$(n).attr("class"));
console.log("txt",$(n).html());
var cls = $(n).attr("class");
var txt = $(n).html();
var hrf = $(n).attr("href");
if(cls=='ellipsis'){
hrf="javascript:void(0);";
}else if(typeof(cls) != "undefined" && cls.indexOf('current')>=0){
cls = "active";
}else{
cls ="";
}
txt=txt.replace("Prev","上一页");
txt=txt.replace("Next","下一页");
var newa = "<li class='page-item'><a class='page-link "+cls+"' href='"+hrf+"'>"+txt+"</a></li>";
newas += newa;
});
var pagerHtml = "<nav><ul class='pagination'>";
pagerHtml += newas;
pagerHtml += "</ul></nav>";
console.log("pagerHtml=>",pagerHtml);
$("#paging_block").html(pagerHtml);
}