vbird_linux_prettify

美化《鸟哥的Linux私房菜》网站:用等宽字体显示所有代码;隐藏部分页面元素;

  1. // ==UserScript==
  2. // @name vbird_linux_prettify
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.7
  5. // @description 美化《鸟哥的Linux私房菜》网站:用等宽字体显示所有代码;隐藏部分页面元素;
  6. // @author Yang Li
  7. // @match http://linux.vbird.org/*
  8. // @require https://code.jquery.com/jquery-3.3.1.slim.min.js
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. $(document).ready(function(){
  13. // v0.1
  14. // v0.2
  15. // 1. 通过添加class来添加新的css规则,避免.attr()覆盖原有的font以外的规则(比如下划线)
  16. // v0.3
  17. // 1. 脚本更名:从 vbird-linux-monospaced-code 改为 vbird-linux-prettify
  18. // 2. 删除顶部和底部banner、左侧前一页按钮、右侧后一页按钮、左上方导航窗口、页面修订历史
  19. // 3. 浏览器窗口宽度改变时,正文区域随之调整
  20. // 4. 把正文区域放置在页面正中
  21. // 5. 调整最底部三个导航按钮的位置
  22. // v0.4
  23. // 1. 让代码区域根据正文区域调整宽度
  24. // 2. 浏览器窗口变窄时,图片宽度相应缩小;统一设置图片边框
  25. // 3. 例题区域根据浏览器窗口宽度调整
  26. // 4. 例题代码使用紫色等宽字体
  27. // 5. 重点强调语句(蓝色)使用橙色等宽字体
  28. // 6. 重点强调语句偶数行使用浅蓝色字体,避免视觉疲劳
  29. // 7. 增加文末习题答案可见度
  30. // v0.5
  31. // 1. 代码按照作用对象分组,便于维护
  32. // 2. 更改重点强调语句的颜色
  33. // 3. 图片宽度默认缩放到正文区域的80%,避免在手机上被缩放到较小尺寸
  34. // 4. 增大代码块宽度、显示字号,避免手机上代码字号太小
  35. // v0.6
  36. // 1. 专门为Firefox for Android增大代码字体
  37. // 2. 专门为Firefox for Android设置表格字体
  38. // v0.7
  39. // 1. 代码拆分更细致,不同用途的页面元素拆分成独立的语句
  40.  
  41. // 网页整体结构
  42.  
  43. $('.tablearea').css({'min-width':'400px','max-width':'1000px','width':'90%'});
  44. //$('.mainarea').css({'width':'100%','position':'static','float':'none'});
  45.  
  46. // The last line of main content, which contains three links: PrePage, Home, NextPage
  47. $('.mainarea > div:last-child').css('margin-top','20px');
  48.  
  49. // .toparea: header, which sets position:fixed
  50. // .bottomarea: footer, which sets position:fixed
  51. $('.toparea, .bottomarea').remove();
  52.  
  53. // .nav: the navigation sidebar on the left
  54. //$('.nav').remove();
  55.  
  56. // .leftarea: two less-than signs on the left, click it can jump to previous chapter
  57. // .rightarea: two greater-than signs on the right, click it can jump to next chapter
  58. $('.leftarea, .rightarea').remove();
  59. // 代码块
  60. $('<style> .monospaced_code {font: 14px "Anonymous Pro", monospace !important; line-height: 1.4 !important;} </style>').appendTo('head');
  61. $('table.term td *').addClass('monospaced_code');
  62. $('table.term').css({'display':'block','overflow':'auto','width':'98%'});
  63. $('pre').css({'width':'100%'});
  64. // 表格
  65. // $('table.news *').css('cssText','font: 16px serif !important;');
  66.  
  67. // 图片
  68. // $('div > img').css({'max-width':'100%','width':'80%','border':'2px dotted #c0c'});
  69. $('div > img').css({'border':'2px dotted #c0c'});
  70. // 重点强调语句
  71. $('.text_import2').css({'font':'16px monospace','color':'#e60'});
  72. $('ul.text_import2 > li:nth-child(even)').css('color','#3DC2AC');
  73.  
  74. // 例题
  75. $('table.exam').css({'display':'block','overflow':'auto','border':'2px dotted #c0c'});
  76. $('table.exam blockquote').css({'font':'14px monospace','color':'#c0c'});
  77.  
  78. // 本章习题
  79. $('.blockex').css({'color':'#eee','font':'14px monospace'});
  80. });