知网CNKI小助手

CNKI tools.

  1. // ==UserScript==
  2. // @name 知网CNKI小助手
  3. // @version 0.3
  4. // @description CNKI tools.
  5. // @author leftjie
  6. // @match *://kns.cnki.net/KXReader/Detail?*
  7. // @match *://new.oversea.cnki.net/KXReader/Detail?*
  8. // @match *://new.big5.oversea.cnki.net/KXReader/Detail?*
  9. // @match *://new.gb.oversea.cnki.net/KXReader/Detail?*
  10. // @match *://*/KXReader/Detail?*
  11. // @grant none
  12. // @namespace https://greasyfork.org/users/244539
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. window.onload = function(){
  18.  
  19. function add_size(){
  20. var c_size = document.getElementsByClassName('main')[0];
  21. var cur_size = window.getComputedStyle(c_size).fontSize.replace("px","")-0;
  22. var main = document.getElementsByClassName('main')[0];
  23. main.style.fontSize=(cur_size+1)+"px";
  24. var ps = main.getElementsByClassName('p1');
  25. for(var i=0;i<ps.length;i++){
  26. ps[i].style.fontSize=(cur_size+1)+"px";
  27. }
  28. }
  29. function redu_size(){
  30. var c_size = document.getElementsByClassName('main')[0];
  31. var cur_size = window.getComputedStyle(c_size).fontSize.replace("px","")-0;
  32. var main = document.getElementsByClassName('main')[0];
  33. main.style.fontSize=(cur_size-1)+"px";
  34. var ps = main.getElementsByClassName('p1');
  35. for(var i=0;i<ps.length;i++){
  36. ps[i].style.fontSize=(cur_size-1)+"px";
  37. }
  38. }
  39. function change_mode(color){
  40. localStorage.bgc=color;
  41. var c_bgc = document.getElementsByTagName('body')[0];
  42. var c_main = document.getElementsByClassName('main')[0];
  43. var c_dl = document.getElementsByTagName('dl');
  44. var c_p = document.getElementsByTagName('p');
  45. var c_nav = document.getElementsByClassName('ecp_top-nav')[0];
  46. var c_con = document.getElementsByClassName('content')[0];
  47. var c_tips = document.getElementsByClassName('tips')[0];
  48. var c_refer = document.getElementsByClassName('refer')[0];
  49. var c_h4 = document.getElementsByClassName('refer')[0].getElementsByTagName('h4')[0];
  50. var c_briefs = document.getElementsByClassName('brief');
  51. c_bgc.style.backgroundColor = localStorage.bgc;
  52. c_nav.style.backgroundColor = localStorage.bgc;
  53. c_con.style.backgroundColor = localStorage.bgc;
  54. c_tips.style.backgroundColor = localStorage.bgc;
  55. c_main.style.background = localStorage.bgc;
  56. c_refer.style.background = localStorage.bgc;
  57. c_h4.style.background = localStorage.bgc;
  58. for(var i=0;i<c_briefs.length;i++){
  59. c_briefs[i].style.background = localStorage.bgc;
  60. }
  61. for(var j=0;j<c_dl.length;j++){
  62. c_dl[j].style.backgroundColor = localStorage.bgc;
  63. }
  64. for(var m=0;m<c_p.length;m++){
  65. c_p[m].style.backgroundColor = localStorage.bgc;
  66. }
  67.  
  68. }
  69. function change_mode_auto(){
  70. change_mode(localStorage.bgc);
  71. var select_default = document.getElementById("protect_eyes_select");
  72. for(var i=0; i<select_default.options.length; i++){
  73. if(select_default.options[i].value == localStorage.bgc){
  74. select_default.options[i].selected = true;
  75. break;
  76. }
  77. }
  78. }
  79.  
  80.  
  81.  
  82. var font_size_button_plus = document.createElement('span');
  83. font_size_button_plus.title = "增大字体"
  84. font_size_button_plus.id = "font_size_button_plus";
  85. font_size_button_plus.innerText = "字✚";
  86. font_size_button_plus.style.fontSize="14px";
  87. font_size_button_plus.style.display="block";
  88. font_size_button_plus.style.lineHeight="18px";
  89. font_size_button_plus.style.border="1px solid #e2e2e2";
  90. font_size_button_plus.style.borderRadius="2px";
  91. font_size_button_plus.style.backgroundColor="#f5f5f5";
  92. font_size_button_plus.style.color="#504f4f";
  93. font_size_button_plus.style.float="left";
  94. font_size_button_plus.style.padding="3px";
  95. font_size_button_plus.style.position = "absolute";
  96. font_size_button_plus.style.right = "0";
  97. font_size_button_plus.style.bottom = "-60px";
  98. font_size_button_plus.style.width = "28px";
  99.  
  100. var font_size_button_redu = document.createElement('span');
  101. font_size_button_redu.title = "减小字体"
  102. font_size_button_redu.innerText = "字 ━";
  103. font_size_button_redu.id = "font_size_button_redu";
  104. font_size_button_redu.style.fontSize="14px";
  105. font_size_button_redu.style.display="block";
  106. font_size_button_redu.style.lineHeight="18px";
  107. font_size_button_redu.style.border="1px solid #e2e2e2";
  108. font_size_button_redu.style.borderRadius="2px";
  109. font_size_button_redu.style.backgroundColor="#f5f5f5";
  110. font_size_button_redu.style.color="#504f4f";
  111. font_size_button_redu.style.float="left";
  112. font_size_button_redu.style.padding="3px";
  113. font_size_button_redu.style.position = "absolute";
  114. font_size_button_redu.style.right = "0";
  115. font_size_button_redu.style.bottom = "-30px";
  116. font_size_button_redu.style.width = "28px";
  117.  
  118.  
  119. var protect_eyes = document.createElement('select');
  120. protect_eyes.insertAdjacentHTML("beforeend",'<option value="none" selected>护眼模式</option><option value="#FFFFFF">银河白</option><option value="#FAF9DE">杏仁黄</option><option value="#FFF2E2">秋叶褐</option><option value="#FDE6E0">胭脂红</option><option value="#E3EDCD">青草绿</option><option value="#DCE2F1">海天蓝</option><option value="#E9EBFE">葛巾紫</option><option value="#EAEAEF">极光灰</option>');
  121. protect_eyes.style.width="36px";
  122. protect_eyes.id="protect_eyes_select";
  123. protect_eyes.style.fontSize="12px";
  124. document.getElementsByClassName('backtop')[0].appendChild(protect_eyes);
  125. document.getElementsByClassName('backtop')[0].appendChild(font_size_button_plus);
  126. document.getElementsByClassName('backtop')[0].appendChild(font_size_button_redu);
  127.  
  128. document.getElementById("font_size_button_redu").addEventListener("click", redu_size);
  129. document.getElementById("font_size_button_plus").addEventListener("click", add_size);
  130. document.getElementById("protect_eyes_select").addEventListener("change", function(){change_mode(this.value)});
  131.  
  132.  
  133. change_mode_auto()
  134. };
  135. })();