Greasy Fork

Greasy Fork is available in English.

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

Lifting copy restrictions on CNKI online reading

当前为 2019-12-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         解除知网复制限制CNKI copy !!
// @namespace    http://tampermonkey.net/
// @version      1.1.0
// @description  Lifting copy restrictions on CNKI online reading
// @description:zh-CN  解除知网在线阅读时复制限制
// @author       auko
// @match        http://kns.cnki.net//*/Detail*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.onload=function(){
        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;
            }else{
                var temp = document.createElement('input');
                temp.value = selectText;
                temp.setAttribute("id","aukoToProxy");
                document.body.appendChild(temp);
                temp.select();
                temp.style.displau='none';
            }
            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;
        }
    }
})();