解除知网复制限制CNKI copy !!

Lifting copy restrictions on CNKI online reading

  1. // ==UserScript==
  2. // @name 解除知网复制限制CNKI copy !!
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2.0
  5. // @description Lifting copy restrictions on CNKI online reading
  6. // @description:zh-CN 解除知网在线阅读时复制限制
  7. // @author auko
  8. // @supportURL https://github.com/aukocharlie/my-script
  9. // @match *://*.cnki.net*/*/Detail*
  10. // @match *://*/rwt/CNKI/https/*/KXReader/Detail*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. var selectText = "";
  18. document.body.onkeydown=function(e){
  19. if(e.ctrlKey && e.keyCode == 67) {
  20. copy();
  21. return false;
  22. }
  23. };
  24. document.body.onmouseup = function(e){
  25. getSelectText();
  26. }
  27. var copytext = document.getElementById("copytext");
  28. var parent = document.getElementsByClassName("inner")[0];
  29. if(copytext!== null) parent.removeChild(copytext);
  30.  
  31. var proxyBtn = document.createElement("A");
  32.  
  33. parent.insertBefore(proxyBtn,parent.children[0]);
  34.  
  35. proxyBtn.setAttribute("id","proxy");
  36. proxyBtn.innerHTML="复制";
  37. document.getElementById("proxy").onclick = function(e){
  38. if(document.getElementById("aukoToProxy")){
  39. document.getElementById("aukoToProxy").value = selectText;
  40. document.getElementById("aukoToProxy").select();
  41. }else{
  42. var temp = document.createElement('input');
  43. temp.value = selectText;
  44. temp.setAttribute("id","aukoToProxy");
  45. document.body.appendChild(temp);
  46. temp.select();
  47. temp.style.opacity='0';
  48. }
  49. copy();
  50. }
  51.  
  52. function getSelectText() {
  53. if(document.selection) {
  54. if(document.selection.createRange().text && document.selection.createRange().text !== ''){
  55. selectText = document.selection.createRange().text;
  56. }
  57. } else {
  58. if(document.getSelection()&& document.getSelection().toString() !== ''){
  59. selectText = document.getSelection().toString();
  60. }
  61. }
  62. }
  63.  
  64. function copy(){
  65. try{
  66. if(document.execCommand("Copy","false",null)){
  67. console.log("复制成功!");
  68. }else{
  69. console.warn("复制失败!");
  70. }
  71. }catch(err){
  72. console.warn("复制错误!")
  73. }
  74. return false;
  75. }
  76. })();