forked from necopapa/readable-wikipedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWikipedia_prettify.js
607 lines (492 loc) · 11.8 KB
/
Wikipedia_prettify.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
// ==UserScript==
// @name Wikipedia_prettfy
// @description prettfy wikipedia move toc to side,etc make it easier to read
// @namespace https://github.com/willowj/readable-wikipedia
// @include http*://*.wikipedia.org/**
// @include http*://*.wikinews.org/**
// @include http*://*.wikisource.org/**
// @version 1.2
// @grant Adam willow
// modified from https://greasyfork.org/zh-CN/scripts/35198-readable-wikipedia/code v1
// ==/UserScript==
function GM_addStyle_from_string(str) {
var node = document.createElement('style');
node.innerHTML = str;
document.body.appendChild(node);
}
//var cssSrc = GM_getResourceText ("readableWikipediaCss");
var cssSrc = `
/* Base Wikipedia Enhancement */
#firstHeading {
font-weight: bolder !important;
padding: 0.6em !important;
font-size: xx-large !important;
}
body{
background: none !important;
}
a:visited {
color: #948af5 !important;
}
a {
color: #063b92;
}
.toc>ul a {
color: black;
}
.reference {
/* display: none !important;*/
}
.internal {
/*display: none !important;*/
}
#mw-head-base {
background-image: none !important;
}
.infobox th {
background-color: #e6e0c8 !important;
/*font-weight: normal !imporant;*/
}
/*.infobox th a {
color: white !important;
font-weight: normal !imporant;
}*/
table.infobox {
border-spacing: 3px;
text-align: left;
font-size: small;
line-height: 1.5em;
border-collapse: collapse;
}
.wikitable{
margin: auto !important;
}
#simpleSearch{
border :0px !important;
}
/*vectorTabs*/
div.vectorTabs span{
display: block !important;
background-image: unset !important;
}
div.vectorTabs{
background-image: unset !important;
}
div#mw-head div.vectorMenu h3{
background-image: unset !important;
}
div.vectorTabs ul li{
background-image: unset !important;
}
div.vectorTabs ul{
background-image: unset !important;
}
/*vectorTabs*/
#siteNotice {
text-align: right;
font-size: 6px;
margin-left: 50%;
position: absolute;
}
h2 {
margin-top: 2em !important;
}
dl>dd{
border-bottom-style: groove;
}
#mw-page-base {
height: auto !important;
}
#siteSub {
display: none !important;
}
.metadata {
display: none !important;
}
.catlinks {
/*display: none !important;*/
}
.Template-Fact {
display: none !important;
}
div#content a.external {
background: none !important;
}
.topicon {
display: none !important;
right: 9999px !important;
}
.icone_de_titre {
display: none !important;
}
#coordinates {
display: none !important;
}
#left-navigation {
margin-left: 20%;
margin-top: 0px;
font-size: 8px !important;
}
#right-navigation {
margin-top: 2em !important;
}
#p-views {
display: none !important;
}
#mw-panel {
font-size: inherit;
position: unset;
top: 0;
width: 10em;
left: 0;
}
#mw-body {
margin-left: 0px !important;
}
.mw-body-content h2 {
/* font-size: 1.5em; */
margin-top: 1em;
border-left-style: inset;
border-left-width: 0.6em;
border-left-color: lightskyblue;
padding-left: 0.3em;
}
.mw-body-content p,ul {
line-height: inherit;
margin: 0.5em 0;
padding-left: 4% !important;
}
.mw-parser-output li {
padding-bottom: 0.6em !important;
}
p {
font-size: 1em !important;
margin-top: 1em !important;
}
.mw-parser-output>p {
letter-spacing: 1px;
text-align: justify;
}
.mw-parser-output>dl{
padding-left: 3em;
}
.mw-parser-output>ol{
padding-left: 5em;
}
.mw-parser-output>h3~ol{
padding-left: 1em;
}
h2~h3 {
padding-left: 0.5em;
}
h3~h4 {
padding-left: 1em;
}
h4~h5 {
padding-left: 2em;
}
#protected-icon {
display: none !important;
}
.dablink {
display: none !important;
}
#mw-articlefeedback {
display: none !important;
}
.editsection {
display: none !important;
}
#footer {
text-align: center !important;
border-top: 1px solid grey !important;
}
#footer-places {
display: none !important;
}
#footer img {
display: none !important;
}
.tleft {
margin: 1.5em 1.4em 1.3em 0 !important;
}
/* I'm really not sure about this change,
* Eventually I'd like the TOC accessible
* via a side menu, for now this is experimental
* and might change
*/
div#toc {
position: fixed;
margin-left: 0px;
font-size: 13px;
top: 0%;
overflow: auto;
height: 100%;
display: inline-block;
z-index: 1;
background: beige ;
border: 0px;
font-size :0.9em;
}
.toc ul ul {
margin: 0 0 0 1em;
}
div#toc>ul li:focus{
border-right-style: solid;
border-right-color: wheat;
font-weight: bolder;
}
.toc>ul{
margin-bottom: 2em;
margin-left:5%;
}
.tocnumber, .toctext {
display: table-cell;
text-decoration: blink;
}
/* Reading Enhacements */
* {
line-height: 1.7em !important;
}
/* File Enhancements */
/*#file img {
width: 100% !important;
height: auto !important;
}*/
.fullMedia, .sharedUploadNotice, #mw-imagepage-section-linkstoimage, #filelinks, #mw-imagepage-section-filehistory, #filehistory, #mw-imagepage-section-globalusage, #globalusage, #mw-imagepage-content, #template-picture-of-the-day, #metadata, .mw-imagepage-section-metadata, .mw-filepage-resolutioninfo {
display: none !important;
}
/* Scripted in styles */
#logo {
margin: .5em auto auto 1em;
}
.visible-link {
color: #2B77BD !important;
}
#enhancement_credit {
font-size: 12px !important;
}
.mw-editsection {
display: none !important;
}
.mobile {
display: none !important;
}
/* Responsive breakpoints */
@media screen and (min-width: 1200px) {
div#content{
margin-left: 15% !important;
width: 70% !important;
padding-left: 5em !important;
padding-right: 7em !important;
}
.toc{
width: 13%;
}
#p-personal {
display: inherit !important;
padding-right: 7em !important;
}
#right-navigation{
padding-right: 8% !important;
font-size: 8px !important;
}
#siteNotice{
padding-right: 10em !important;
}
.infobox {
margin-left: 2em !important;
float: right !important;
min-width: auto !important;
clear: unset !important;
}
}
@media screen and (max-width: 1200px) {
div#content {
width: 72% !important;
margin-left: 20%;
}
div#toc{
width: 15%;
}
.thumb, .tright, .left {
display: block !important;
/* float: none !important;*/
}
#mw-articlefeedbackv5 {
display: none !important;
}
.infobox {
margin-left: 2em !important;
float: right !important;
min-width: auto !important;
clear: unset !important;
}
}
@media screen and (max-width: 650px) {
div#content {
margin-left: 2%;
width: 90% !important;
padding-top: 1em !important
background: none !important;
padding: 4.25em 1.5em 1.5em 1.5em !important;
border: none !important;
}
table.infobox{
width:90% !important;
}
.toc{
width: 90% !important;
position : relative !important;
height : auto !important;
margin-left: 5% !important;
top : 5em !important
}
#mw-panel{
display :none !important;
}
.desktop {
display: none !important;
}
.mobile {
display: block !important;
}
.infobox {
display: block !important;
float: none !important;
margin: 1em auto !important;
}
}
/* MY CODE */
div#content {
padding-top: 1em !important;
margin-top: 3em;
border: none;
}
.toc::-webkit-scrollbar{
width: 0px;
height: 8px;
}
/* 设置滚动条的滑轨 */
.toc::-webkit-scrollbar-track {
/*background-color: #ddd;*/
}
/* 滑块 */
/*.toc::-webkit-scrollbar-thumb {
background-color: #54595d;
border-radius: 4px;
}*/
/* 滑轨两头的监听按钮 */
.toc::-webkit-scrollbar-button {
background-color: #888;
display: none;
`;
GM_addStyle_from_string(cssSrc);
//document.getElementById("References").parentNode.nextSibling.nextSibling.style.display = "none";
var toc = document.querySelector('div#toc');
if (toc == null) {
var toc = document.createElement('div');
toc.setAttribute('id', 'toc');
toc.setAttribute('class', 'toc');
}
document.body.insertBefore(toc, document.body.firstElementChild);
var pg = document.querySelector('#mw-panel');
document.querySelector('#toc').appendChild(pg);
/*toc toggle*/
if (!document.querySelector("#toc .toctoggle")) {
var tog = document.createElement('span');
document.querySelector("#toc .toctitle").appendChild(tog);
if (document.URL.indexOf('//en.wiki') >= 0) {
var hide = 'hide';
} else {
var hide = '隐藏';
}
tog.outerHTML = '<span class="toctoggle"> [<a role="button" tabindex="0" class="togglelink">' + hide + '</a>] </span>';
}
/*toc show toogle*/
var togglelink = document.querySelector("#toc .toctitle .togglelink");
var ul = document.querySelector("#toc>ul");
togglelink.addEventListener("click", function() {
if (ul.style.display === 'none') {
ul.style.display = 'block';
} else {
ul.style.display = 'none';
}
var tog_ = {
"hide": "show",
"show": "hide",
"隐藏": "显示",
"显示": '隐藏'
};
togglelink.text = tog_[togglelink.text];
});
if (document.body.offsetWidth <= 650) {
togglelink.click();
}
/*var theurl = document.URL;
var res = theurl.replace(/zh.wikipedia.org\/wiki\//gi, "zh.wikipedia.org/zh-cn/");
if (res != theurl){
window.location.href = (res);
}*/
/*info box right*/
/*var info_box = document.createElement("div");
info_box.id = 'info_box';
document.body.insertBefore(info_box, document.querySelector('#content'));
document.querySelectorAll('.infobox').forEach(function (item) {
info_box.appendChild(item);
});
*/
/*a link to zn_cn */
function link_to_zh_cn() {
if (document.URL.indexOf("zh.wikipedia.org") >= 0) {
var nodes = document.querySelectorAll("a[href*='/wiki/']");
for (var i = 0; i < nodes.length; i++) {
var url = decodeURIComponent(nodes[i].href.replace(/\/wiki\//gi, "/zh-hans/"));
nodes[i].href = url;
}
console.log("link to zn_cn ");
}
}
link_to_zh_cn();
/*add space betwen cn and eng
var g1 = /(\w)([\u4e00-\u9fa5])/g;
var g2 = /([\u4e00-\u9fa5])(\w)/g;
document.querySelectorAll('p').forEach(function (item) {
if (item.innerText) {
item.innerText=item.innerText.replace(g1,"$1 $2").replace(g2,"$1 $2");
}
});*/
/*menu on scroll*/
window.onscroll = function() {
var t = document.documentElement.scrollTop || document.querySelector('#content').scrollTop; //取当前高度
//取各个锚点的位置
var menu = document.querySelectorAll('div#toc>ul a');
var flag = -1;
for (var i = 0; i < menu.length; i++) {
var ssid = menu[i].href.split('#');
ssid = ssid[ssid.length - 1];
if (document.getElementById(ssid).offsetTop + 200 >= t) {
/*menu[i].closest('li').focus();*/
flag = i;
break;
}
}
for (var ik = 0; ik < menu.length; ik++) {
if (flag == ik) { //找到当前浏览器固定达到的位置所对应的标题
menu[ik].style.color = "black"; //旗下的a标签里面的内容为红色
menu[ik].style.fontWeight = "bolder"; //旗下的a标签里面的内容为红色
menu[ik].focus();
menu[ik].closest('li').style.borderRightStyle = "solid";
menu[ik].closest('li').style.borderRightColor = "wheat";
} else { //其余标题
//menu[ik].style.color="blue";//旗下的a标签里面的内容为蓝色
menu[ik].style.color = "unset";
menu[ik].style.fontWeight = "unset"; //旗下的a标签里面的内容为红色
menu[ik].closest('li').style.borderRightStyle = "unset";
menu[ik].closest('li').style.borderRightColor = "unset";
}
}
/* if(flag==-1){//如果没有任何一个标题碰到浏览器顶部,那么就认为是现在悬停在第一个标题
menu[0].style.color="red";//旗下的a标签里面的内容为红色
}*/
};