Greasy Fork is available in English.

知网 参考文献 bibtex

try to take over the world!

// ==UserScript==
// @name         知网 参考文献 bibtex
// @namespace    https://github.com/HawkTom
// @require      https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
// @version      0.2
// @description  try to take over the world!
// @author       Hao
// @match        https://kns.cnki.net/kns/ViewPage/*displayMode=NoteExpress
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var btn = "<input type=\"button\" value=\"BibTex到剪贴板\" class=\"save clipboard\" id=\"bib_save\">";
    jQuery(document).ready(function($) {
        $(".btnDiv").append(btn)
        console.log("hello world")

        $("#bib_save").click(function(){
            var x = document.getElementsByClassName('CurContentID')
            var y = x[0].innerText.split('\n')
            console.log(x, y, y.length)
            var bibtext = ""
            var bibtex = new Array()
            for (var i=0; i<y.length-1; i++){
                var k = y[i].split("}: ")
                var item = k[0].substring(1,k[0].length).toLowerCase().split(" ").join("")
                var detail = k[1]
                if (item == "referencetype"){
                    if (detail == "Journal Article"){
                        bibtext = "@article{cite_label ,\n"
                    }
                    else if(detail == "Conference Proceedings"){
                        bibtext = "@inproceedings{cite_label ,\n"
                    }
                }
                else if(item == "issue"){
                    bibtext = bibtext + "   {number}={" + detail + "},\n"
                }
                else {
                    bibtext = bibtext + "   {" + item + "}={" + detail + "},\n"
                }
                bibtex[item] = detail
                // console.log(i, item, detail)
            }
            bibtext += "}"
            // console.log(bibtext)
            const input = document.createElement('textarea')
            input.value = bibtext
            document.body.appendChild(input)
            input.select()
            document.execCommand('Copy')
            document.body.removeChild(input)

        })
    })

    // Your code here...
})();