forked from auko-lq/my-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNKI-copy.js
75 lines (68 loc) · 2.33 KB
/
CNKI-copy.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
// ==UserScript==
// @name 解除知网复制限制CNKI copy !!
// @namespace http://tampermonkey.net/
// @version 1.1.4
// @description Lifting copy restrictions on CNKI online reading
// @description:zh-CN 解除知网在线阅读时复制限制
// @author auko
// @supportURL https://github.com/aukocharlie/my-script
// @include http://kns.cnki.net*/*/Detail*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var selectText = "";
document.body.onkeydown=function(e){
if(e.ctrlKey && e.keyCode == 67) {
copy();
}
return false;
};
document.body.onmouseup = function(e){
getSelectText();
}
var copytext = document.getElementById("copytext");
var parent = document.getElementsByClassName("inner")[0];
if(copytext!== null) parent.removeChild(copytext);
var proxyBtn = document.createElement("A");
parent.insertBefore(proxyBtn,parent.children[0]);
proxyBtn.setAttribute("id","proxy");
proxyBtn.innerHTML="复制";
document.getElementById("proxy").onclick = function(e){
if(document.getElementById("aukoToProxy")){
document.getElementById("aukoToProxy").value = selectText;
document.getElementById("aukoToProxy").select();
}else{
var temp = document.createElement('input');
temp.value = selectText;
temp.setAttribute("id","aukoToProxy");
document.body.appendChild(temp);
temp.select();
temp.style.opacity='0';
}
copy();
}
function getSelectText() {
if(document.selection) {
if(document.selection.createRange().text && document.selection.createRange().text !== ''){
selectText = document.selection.createRange().text;
}
} else {
if(document.getSelection()&& document.getSelection().toString() !== ''){
selectText = document.getSelection().toString();
}
}
}
function copy(){
try{
if(document.execCommand("Copy","false",null)){
console.log("复制成功!");
}else{
console.warn("复制失败!");
}
}catch(err){
console.warn("复制错误!")
}
return false;
}
})();